-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgenerate_data.py
47 lines (45 loc) · 1.44 KB
/
generate_data.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
36
37
38
39
40
41
42
43
44
45
46
47
import numpy as np
mu = 0.9
user_number = 10
G = np.zeros((user_number, user_number), dtype=np.float)
for i in range(user_number):
for j in range(user_number):
if i == j:
G[i][j] = 0
else:
p = np.random.random()
if p <= mu:
G[i][j] = 1
else:
G[i][j] = 0
for i in range(user_number):
print('[', end='')
for j in range(user_number):
print(G[i][j], end=', ')
print('], ')
# G = np.array([
# [0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0, ],
# [1.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 0.0, ],
# [1.0, 1.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, ],
# [1.0, 1.0, 1.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0, ],
# [0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, ],
# [1.0, 0.0, 1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 1.0, ],
# [0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 1.0, 1.0, ],
# [0.0, 1.0, 1.0, 0.0, 1.0, 1.0, 1.0, 0.0, 1.0, 0.0, ],
# [0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0, ],
# [1.0, 0.0, 1.0, 0.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, ],
# ])
I = np.ones((user_number, 1))
K = np.dot(G, I)
L = np.dot(G.transpose(), I)
g = np.sum(G)
d = g / user_number
H = np.dot(K, L.transpose()) / g
for i in range(user_number):
print('[', end='')
for j in range(user_number):
# if i == j:
# print('0.0', end=', ')
# else:
print(np.round(H[i][j], 2), end=', ')
print('],')