-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate_eligibility.py
85 lines (63 loc) · 2.71 KB
/
generate_eligibility.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
import numpy as np
import random
import pickle
def generate_eligibility(filename, job_amount, prob_list, client_amount = 500000, skew = False):
client_list = [set() for _ in range(client_amount)]
for j in range(job_amount):
for i in range(client_amount):
if random.random() > prob_list[j]:
if skew:
job_type = np.random.choice([*range(1, job_amount+1 )], p=[0.5, 0.2, 0.3])
else:
job_type = random.randint(1, job_amount)
client_list[i].add(job_type)
client_list = [list(i) for i in client_list]
with open(filename, 'wb') as outp: # Overwrites any existing file.
pickle.dump(client_list, outp, pickle.HIGHEST_PROTOCOL)
return client_list
def generate_within_eligibility(filename, job_amount, prob_list, client_amount = 500000, skew = False):
client_list = [[] for _ in range(client_amount)]
for i in range(client_amount):
job_type = [1]
if random.random() < 0.6:
job_type.append(2)
if random.random() < 0.5:
job_type.append(3)
client_list[i] = job_type
with open(filename, 'wb') as outp: # Overwrites any existing file.
pickle.dump(client_list, outp, pickle.HIGHEST_PROTOCOL)
return client_list
def generate_cross_eligibility(filename, job_amount, prob_list, client_amount = 500000, skew = False):
client_list = [[] for _ in range(client_amount)]
for i in range(client_amount):
count = 2 if random.random() < 0.5 else 1
job_type =list( np.random.choice([*range(1, job_amount )], count, p=[0.2,0.8]))
if 2 in job_type and 1 not in job_type and random.random() < 0.5:
job_type.append(job_amount)
client_list[i] = job_type
with open(filename, 'wb') as outp: # Overwrites any existing file.
pickle.dump(client_list, outp, pickle.HIGHEST_PROTOCOL)
return client_list
if __name__ == '__main__':
# generate_eligibility('baseline_eligibility_3job', 3, [0, 0.5, 0.8])
generate_cross_eligibility('baseline_eligibility_3cross', 3, [0, 0.5, 0.8],client_amount = 50000, skew = True)
# generate_within_eligibility('baseline_eligibility_3_within', 3, [0, 0, 0],client_amount = 50000, skew = True)
a=b=c=d=f=g=h=0
eligibility_file = 'baseline_eligibility_3cross'
with open(eligibility_file, 'rb') as config_dictionary_file:
eligibility = pickle.load(config_dictionary_file)
for e in eligibility:
if 1 in e:
a += 1
if 2 in e:
b+=1
if 3 in e:
c += 1
if 1 in e and 2 in e:
d += 1
if 1 in e and 3 in e:
f += 1
if 3 in e and 2 in e:
g += 1
if 1 in e and 2 in e and 3 in e:
h += 1