Example #1
0
def hungarian_APC(N):
    '''
    Hungarian matching (APC: Lawler - implemented by G. CARPANETO, S. MARTELLO, P. TOTH)
    '''
    #print '... entering fortran binary'
    mapping, cost, errorcode  = hung_APC.apc(-N)
    if errorcode != 0:
        print 'APC error code %d: need to increase MAXSIZE in APC.f to handle this problem' % (errorcode)
    total=np.sum(np.diag(N[:,mapping-1]))
    if total != -cost:
        print 'cost %d and total %d unequal!' % (-cost,total)
    #total = -cost    
    #print 'mapping length', len(mapping), 'cost', cost, 'total', total
    #print 'percent agreements: ', 100*total/np.sum(N)
    
    return 100*total/np.sum(N), kappa(N[:,mapping-1]), mapping-1
Example #2
0
    Nnegintlist = [[int(-c) for c in b] for b in N]
    print 'time to build list of list of integers =', time()-t
    t=time()
    h = hungarian.HungarianSolver(Nnegintlist)
    h.solve()
    t=time()-t
    print '>>> time elapsed =', t
    p = h.get_assignment()
    total = 0
    for row in range(min(N.shape)):
        total += N[row,p[row]]
    print 'percent agreements: ', 100*total/np.sum(N)
    print 'kappa', 100*kappa(N[:,p])
    print p
    '''

    print '\n>>> Hungarian matching (APC: Lawler - implemented by G. CARPANETO, S. MARTELLO, P. TOTH) ...'
    import hung_APC 
    t=time()
    mapping, cost, errorcode  = hung_APC.apc(-N)
    if errorcode != 0:
        print 'APC error code %d: need to increase MAXSIZE in APC.f to handle this problem' % (errorcode)
    t=time()-t
    print '>>> time elapsed =', t
    total=np.sum(np.diag(N[:,mapping-1]))
    #total = -cost
    print 'cost', cost, 'perm length',len(mapping)     
    print 'percent agreements: ', 100*total/np.sum(N)
    print 'kappa', 100*kappa(N[:,mapping-1])