Пример #1
0
 def test_wrong_sizes(self):
     nodes = [4, 4, 16, 32, 32, 64, 64, 256, 64, 256, 256]
     try:
         gc.MultiResGraphClustering(self.G, nodes, k=4)
         self.fail()
     except:
         pass
Пример #2
0
 def test_cont_nodes(self):
     self.G_params['type_z'] = ds.RAND
     G = ds.create_graph(self.G_params, seed=SEED)
     cluster = gc.MultiResGraphClustering(G, self.nodes_enc, k=4)
     out = np.unique(cluster.labels[0])
     for U in cluster.Us:
         out = U.dot(out)
     self.assertTrue(np.array_equal(out, cluster.labels[0]))
def compute_clusters(G, alg, k):
    sizes = []
    Us = []
    hier_As = []
    for i in range(N_EXPS):
        cluster = gc.MultiResGraphClustering(G, EXPS[i]['nodes'], k, alg)
        sizes.append(cluster.sizes)
        Us.append(cluster.Us)
        hier_As.append(cluster.As)
    return sizes, Us, hier_As
Пример #4
0
 def setUp(self):
     np.random.seed(SEED)
     G_params = {}
     G_params['type'] = ds.SBM
     G_params['N'] = 256
     G_params['k'] = 4
     G_params['p'] = 0.15
     G_params['q'] = 0.01 / 4
     G_params['type_z'] = ds.RAND
     G = ds.create_graph(G_params, seed=SEED)
     nodes_dec = [4, 16, 32, 64, 256]
     self.N = nodes_dec[-1]
     self.k = nodes_dec[0]
     self.cluster = gc.MultiResGraphClustering(G, nodes_dec, k=4)
     self.model = Sequential()
     for i, U in enumerate(self.cluster.Us):
         self.add_layer(MeanUps(U, self.cluster.As[i], gamma=1))
Пример #5
0
def compute_clusters(G, root_clust):
    sizes = []
    Us = []
    As = []
    for exp in EXPERIMENTS:
        if not isinstance(exp, dict):
            sizes.append(None)
            Us.append(None)
            As.append(None)
            continue

        exp['t'][-1] = G.N
        cluster = gc.MultiResGraphClustering(G, exp['t'], root_clust)
        sizes.append(cluster.sizes)
        Us.append(cluster.Us)
        As.append(cluster.As)
    return sizes, Us, As
Пример #6
0
def compute_clusters(k):
    sizes = []
    Us = []
    hier_As = []
    for i in range(N_SCENARIOS):
        if EXPS[i][0] is None:
            nodes = [t[-1]] * len(t)
        else:
            nodes = t
        cluster = gc.MultiResGraphClustering(G,
                                             nodes,
                                             k,
                                             alg,
                                             method=c_method,
                                             up_method=EXPS[i][0])
        sizes.append(cluster.sizes)
        Us.append(cluster.Us)
        hier_As.append(cluster.As)
    return sizes, Us, hier_As
Пример #7
0
 def setUp(self):
     G_params = {}
     G_params['type'] = ds.SBM
     G_params['N'] = 256
     G_params['k'] = 4
     G_params['p'] = 0.15
     G_params['q'] = 0.01 / 4
     G_params['type_z'] = ds.RAND
     G = ds.create_graph(G_params, seed=SEED)
     nodes = [4, 16, 32, 256]
     self.K = 3
     cluster = gc.MultiResGraphClustering(G, nodes, k=4)
     self.ups = []
     self.As = []
     self.Us = []
     for i in range(len(cluster.Us)):
         self.ups.append(GFUps(cluster.Us[i], cluster.As[i], self.K))
         self.As.append(Tensor(cluster.As[i]))
         self.Us.append(Tensor(cluster.Us[i]))
Пример #8
0
 def test_all_sizes_repeated(self):
     nodes = [256, 256, 256]
     cluster = gc.MultiResGraphClustering(self.G, nodes, k=4)
     self.assertEqual(len(nodes), len(cluster.sizes))
     for U in cluster.Us:
         self.assertEqual(U, None)
Пример #9
0
 def test_repeated_sizes(self):
     nodes = [4, 4, 16, 32, 32, 64, 256, 256, 256]
     cluster = gc.MultiResGraphClustering(self.G, nodes, k=4)
     self.assertEqual(len(nodes), len(cluster.sizes))
     self.assertEqual(len(nodes) - 1, len(cluster.Us))