-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathad.py
41 lines (34 loc) · 1.23 KB
/
ad.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
import pyro
import random
class Ad():
def __init__(self):
self.target_age = 'young'
self.target_sex = 'male'
self.occupation = 'student'
self.item_sold = random.randint(1,5)
self.appeal = pyro.sample('appeal', pyro.distributions.Uniform(0.1,0.5)).item()
self.generate()
def generate(self):
a = pyro.sample('a', pyro.distributions.Uniform(0,1)).item()
if a <= 1/3:
self.target_age = 1
elif a > 1/3 and a <= 2/3:
self.target_age = 2
else:
self.target_age = 3
s = pyro.sample('s', pyro.distributions.Uniform(0,1)).item()
if s <= 0.5:
self.target_sex = 1
else:
self.target_sex = 2
i = pyro.sample('i', pyro.distributions.Uniform(0,1)).item()
if i <= 0.2:
self.occupation = 1
elif i > 0.2 and i < 0.8:
self.occupation = 2
else:
self.occupation = 3
def __str__(self):
return f"Ad: ({self.target_age}, {self.target_sex}, {self.occupation}, {self.item_sold})"
def arr(self):
return [self.target_age, self.target_sex, self.occupation, self.item_sold]