-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate_synthetic_data.py
executable file
·182 lines (112 loc) · 4.15 KB
/
generate_synthetic_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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
import numpy as np
import random
num_active = 12000
num_active_feat = 25
num_lost = 8000
num_lost_feat = 26
num_edge_feat = 1
train_num_pairs = 5000
val_num_pairs = 2000
unlabeled_num_pairs = 20000
active_players = []
for i in range(num_active):
active_players.append("ActivePlayer_" + str(i))
active_player_features = np.random.rand(num_active, num_active_feat)
lost_players = []
for j in range(num_lost):
lost_players.append("LostPlayer_" + str(j))
lost_player_features = np.random.rand(num_lost, num_lost_feat)
player_pairs = set()
train_lines_to_write = []
train_active_ids = set()
val_active_ids = set()
for k in range(train_num_pairs):
k_a = np.random.randint(num_active)
k_l = np.random.randint(num_lost)
active_id = active_players[k_a]
lost_id = lost_players[k_l]
pair_id = active_id + "," + lost_id
if pair_id in player_pairs:
continue
train_active_ids.add(active_id)
player_pairs.add(pair_id)
active_feat = active_player_features[k_a]
lost_feat = lost_player_features[k_l]
edge_feat = np.random.rand(1, num_edge_feat)
id_cols = [active_id, lost_id]
check_cols = ["0","0","0","0"]
labels = []
if random.random() < 0.05:
label = "1"
else:
label = "0"
labels.append(label)
a_feat_cols =[str(x) for x in active_feat]
ab_feat_cols = [str(x) for x in edge_feat[0]]
b_feat_cols = [str(x) for x in lost_feat]
line_cols = id_cols + check_cols + labels + a_feat_cols + ab_feat_cols + b_feat_cols
line_to_write = "\t".join(line_cols)
train_lines_to_write.append(line_to_write + "\n")
with open("data/train", "w") as f:
f.writelines(train_lines_to_write)
val_lines_to_write = []
for k in range(val_num_pairs):
k_a = np.random.randint(num_active)
k_l = np.random.randint(num_lost)
active_id = active_players[k_a]
lost_id = lost_players[k_l]
pair_id = active_id + "," + lost_id
if pair_id in player_pairs:
continue
if active_id in train_active_ids:
continue
val_active_ids.add(active_id)
player_pairs.add(pair_id)
active_feat = active_player_features[k_a]
lost_feat = lost_player_features[k_l]
edge_feat = np.random.rand(1, num_edge_feat)
id_cols = [active_id, lost_id]
check_cols = ["0","0","0","0"]
labels = []
if random.random() < 0.05:
label = "1"
else:
label = "0"
labels.append(label)
a_feat_cols =[str(x) for x in active_feat]
ab_feat_cols = [str(x) for x in edge_feat[0]]
b_feat_cols = [str(x) for x in lost_feat]
line_cols = id_cols + check_cols + labels + a_feat_cols + ab_feat_cols + b_feat_cols
line_to_write = "\t".join(line_cols)
val_lines_to_write.append(line_to_write + "\n")
with open("data/val", "w") as f:
f.writelines(val_lines_to_write)
unlabeled_lines_to_write = []
for k in range(unlabeled_num_pairs):
k_a = np.random.randint(num_active)
k_l = np.random.randint(num_lost)
active_id = active_players[k_a]
lost_id = lost_players[k_l]
pair_id = active_id + "," + lost_id
if pair_id in player_pairs:
continue
if active_id in train_active_ids or active_id in val_active_ids:
continue
val_active_ids.add(active_id)
player_pairs.add(pair_id)
active_feat = active_player_features[k_a]
lost_feat = lost_player_features[k_l]
edge_feat = np.random.rand(1, num_edge_feat)
id_cols = [active_id, lost_id]
check_cols = ["0","0","0","0"]
labels = []
label = "0"
labels.append(label)
a_feat_cols =[str(x) for x in active_feat]
ab_feat_cols = [str(x) for x in edge_feat[0]]
b_feat_cols = [str(x) for x in lost_feat]
line_cols = id_cols + check_cols + labels + a_feat_cols + ab_feat_cols + b_feat_cols
line_to_write = "\t".join(line_cols)
unlabeled_lines_to_write.append(line_to_write + "\n")
with open("data/unlabeled", "w") as f:
f.writelines(unlabeled_lines_to_write)