Пример #1
0
def testAgainstMunkres(N=100, d=100, round=False):
    # compare Hungarian (munkres) algoritm to LAPJV
    import munkres
    success = 0
    for i in xrange(N):
        A = np.random.randn(d,d) / np.random.randn(d,d)
        if round:
            A = A.round()
        if i % 2 == 0: # test some branh of the code
            A = A - np.mean(A)
        [rowsol, cost, v, u, costMat] = cy_lapjv(A)
        E = munkres.munkres(A)
        rowsol_munkres = np.nonzero(E)[1]
        cost_munkres = (A[E]).sum()
        acc = np.abs(cost - cost_munkres)
        if acc < 1e-8 and np.all(rowsol_munkres==rowsol):
            success += 1
        else:
            print i
            print 'failed with accurracy', acc
            print 'munkres:', cost_munkres
            print 'LAPJV:', cost
            print rowsol_munkres - rowsol
            print rowsol
            print A
    print success, 'out of' , N
Пример #2
0
def testAgainstMunkres(N=100, d=100, round=False):
    # compare Hungarian (munkres) algoritm to LAPJV
    import munkres
    success = 0
    for i in xrange(N):
        A = np.random.randn(d, d) / np.random.randn(d, d)
        if round:
            A = A.round()
        if i % 2 == 0:  # test some branh of the code
            A = A - np.mean(A)
        [rowsol, cost, v, u, costMat] = cy_lapjv(A)
        E = munkres.munkres(A)
        rowsol_munkres = np.nonzero(E)[1]
        cost_munkres = (A[E]).sum()
        acc = np.abs(cost - cost_munkres)
        if acc < 1e-8 and np.all(rowsol_munkres == rowsol):
            success += 1
        else:
            print i
            print 'failed with accurracy', acc
            print 'munkres:', cost_munkres
            print 'LAPJV:', cost
            print rowsol_munkres - rowsol
            print rowsol
            print A
            asd
    print success, 'out of', N
Пример #3
0
def fast_lapjv(costMat, resolution=None):
    return cy_lapjv(costMat, resolution)
Пример #4
0
def fast_lapjv(costMat, resolution=None):
    return cy_lapjv(costMat, resolution)