Пример #1
0
    def test_mat(self):
        n = 8
        perms = sn(n)
        g = random.choice(perms)
        mat = g.mat()

        for j in range(1, n + 1):
            i = g[j]
            self.assertEqual(mat[i-1, j-1], 1)
Пример #2
0
def raw_ft(f, _lambda):
    n = sum(_lambda)
    _sn = sn(n)
    rho = SnIrrep(_lambda, fmt='dense')
    fhat = 0

    for p in _sn:
        fhat += rho(p) * f(p)

    return fhat
Пример #3
0
    def test_yor_inv(self):
        partition = (4, 3, 1)
        s8 = sn(8)

        rho = SnIrrep(partition, 'dense')
        g = random.choice(s8)
        gmat = rho(g)
        mat_inv = np.linalg.inv(gmat)
        ginv_mat = rho(g.inv())

        self.assertTrue(np.allclose(mat_inv, ginv_mat))
Пример #4
0
def main():
    n = 6
    _sn = sn(n)
    _lambda = (n - 2, 1, 1)

    distr = sn_distr(n)
    sn_func = make_sn_func(distr, _sn)
    irreps, _ = qap_decompose(_lambda)

    all_tups = ordered_tups(n)
    fhat_perm = ft(sn_func, perm_rep, _sn)
    fhat_perm_tup = ft(sn_func, lambda p: perm_tup(p, all_tups), _sn)
    block_diag = gen_fhat_blocks(sn_func, irreps, _sn)
    c_mat = c_lambda(_lambda)
    print(np.allclose(
        np.linalg.inv(c_mat) @ block_diag @ c_mat, fhat_perm_tup))
Пример #5
0
    def test_yor_dense(self):
        partition = (4, 2, 1, 1)
        s8 = sn(8)

        g = random.choice(s8)
        h = random.choice(s8)
        gh = g * h

        rho = SnIrrep(partition, 'dense')
        gd = rho(g)
        hd = rho(h)
        ghd = rho(gh)
        self.assertTrue(np.allclose(gd.dot(hd), ghd))

        rho_sp = SnIrrep(partition, 'sparse')
        gsp = rho_sp(g)
        hsp = rho_sp(h)
        ghsp = rho_sp(gh)

        self.assertTrue(np.allclose(gd, gsp.toarray()))
        self.assertTrue(np.allclose(hd, hsp.toarray()))
        self.assertTrue(np.allclose(ghd, ghsp.toarray()))
        self.assertTrue(np.allclose(gsp.dot(hsp).toarray(), ghsp.toarray()))
Пример #6
0
    perm_tup = c_lambdas_inv[(n-2, 1, 1)] @ block_diags[(n - 2, 1, 1)].value @c_lambdas[(n-2, 1, 1)]
    res = ((perm @ amat @ perm.T)@ bmat).sum()
    print('Perm tup sums:', perm_tup.sum(axis=1), perm_tup.sum(axis=0), perm_tup.sum(), perm_tup.shape)
    print(f'Lower bound:  {res} | result: {result}')
    pdb.set_trace()

if __name__ == '__main__':
    #fname = '../data/rou12.mat'
    #mat = scipy.io.loadmat(fname)
    np.random.seed(0)
    n = 6
    mat = {}
    mat['A'] = np.random.randint(0, 10, (n,n))
    mat['B'] = np.random.randint(0, 100, (n,n))
    best = (mat['A'] * mat['B']).sum()
    best_p = Perm.eye(n)
    avg = 0

    for p in sn(mat['A'].shape[0]):
        obj = ((p.mat() @ mat['A'] @ p.mat().T) @ mat['B']).sum()
        avg += obj
        if obj > best:
            best = obj
            best_p = p
    avg = avg / math.factorial(n)
    print('Opt value: {} | Avg value: {:.2f} | Opt perm: {}'.format(best, avg, best_p))

    start = time.time()
    main(mat)
    print('Elapsed: {:.2f}s'.format(time.time() - start))