-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathgenerator.py
35 lines (25 loc) · 882 Bytes
/
generator.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import networkx as nx
import numpy as np
import pickle as pkl
num_class = 5
num_feature = 8
size = [20 for i in range(num_class)]
prob = [[0.173, 0.078, 0.085, 0.007, 0.024],
[0.078, 0.165, 0.101, 0.070, 0.044],
[0.085, 0.101, 0.178, 0.159, 0.020],
[0.007, 0.070, 0.159, 0.118, 0.090],
[0.024, 0.044, 0.020, 0.090, 0.178]]
G = nx.stochastic_block_model(size, prob)
cov = np.triu(np.random.rand(num_feature, num_feature))
cov += cov.T - np.diag(cov.diagonal())
feature = np.zeros((20*num_class, num_feature))
label = []
for i in range(num_class):
label.extend([i for j in range(20)])
mean = np.random.randn(num_feature)
feature[i*20:(i+1)*20,:] = np.random.multivariate_normal(mean, cov, 20)
label = np.array(label)
with open('../data/sbm.p', 'wb') as f:
pkl.dump((G, feature, label), f)
f.close()
print(G.graph["partition"])