-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathdata_generator.py
More file actions
58 lines (50 loc) · 1.36 KB
/
data_generator.py
File metadata and controls
58 lines (50 loc) · 1.36 KB
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
import sys
import time
import pickle as pkl
import numpy as np
import scipy.stats as st
from cfr_py.calculator import MYCFR
from multiprocessing.dummy import Pool
def generate_sample(MAX_CTR):
calculator = MYCFR.Calculator()
ctr = 0
samples = []
while ctr < MAX_CTR:
cards = np.arange(52)
np.random.shuffle(cards)
cards = cards[:7]
step = np.random.randint(4)
if step == 0:
cards[2:] = -1
elif step == 1:
cards[5:] = -1
elif step == 2:
cards[6:] = -1
win = calculator.prior_win_rate(
int(cards[0]),
int(cards[1]),
int(cards[2]),
int(cards[3]),
int(cards[4]),
int(cards[5]),
int(cards[6]),
step,
MCtimes=1000
)
prob = np.array(st.norm.pdf(range(6), loc=win*5))
prob = prob / prob.sum()
sample = [cards.astype(np.int64), prob.astype(np.float32)]
samples.append(sample)
ctr += 1
if ctr % 100 == 0:
print(ctr)
return samples
def main():
i = [MAX_CTR] * NUM_CPU
with Pool(NUM_CPU) as p:
all_samples = p.map(generate_sample, i)
pkl.dump(all_samples, open("./data_{}.pkl".format(sys.argv[1]), "wb"))
if __name__ == "__main__":
MAX_CTR = 300000
NUM_CPU = 1
main()