-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate_multi.py
More file actions
35 lines (32 loc) · 857 Bytes
/
generate_multi.py
File metadata and controls
35 lines (32 loc) · 857 Bytes
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
import numpy as np
def solve(weights, TreeDepth, TreeWidth):
'''
structure: Tree, 3 - 3 - 3 - 3 - 3
'''
w = weights - 0.5
solution = np.zeros(TreeDepth * TreeWidth)
for i in range(TreeWidth):
opt_sum = 0.0
opt_idx = 0
cur_sum = 0.0
for j in range(TreeDepth):
cur_sum += w[i * TreeDepth + j]
if cur_sum > opt_sum:
opt_sum, opt_idx = cur_sum, j + 1
for j in range(opt_idx):
solution[i * TreeDepth + j] = 1
return solution
if __name__ == '__main__':
number = 10000
TreeDepth = 3
TreeBranth = 5
Dim = TreeDepth * TreeBranth
data_x = []
data_y = []
for i in range(number):
weights = np.random.rand(Dim)
labels = solve(weights, TreeDepth, TreeBranth)
data_x.append(weights)
data_y.append(labels)
np.save('./data/Multi/syn_train_w.npy', np.array(data_x))
np.save('./data/Multi/syn_train_x.npy', np.array(data_y))