-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharms.py
41 lines (30 loc) · 884 Bytes
/
arms.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
import random
class BernoulliArm():
def __init__(self, p):
self.p = p
self.mean_return = self.p
def draw(self):
if random.random() > self.p:
return 0.0
else:
return 1.0
class GaussianArm():
def __init__(self, mu, sigma=1):
self.mu = mu
self.sigma = sigma
self.mean_return = self.mu
def draw(self):
return random.gauss(self.mu, self.sigma)
class AdversarialArm():
def __init__(self, reward_sequence):
self.reward_sequence = reward_sequence
self.T0 = len(reward_sequence)
self.step = 0
self.mean_return = sum(self.reward_sequence) / self.T0
def draw(self):
if self.step < self.T0:
tmp = self.reward_sequence[self.step]
self.step += 1
else:
tmp = random.random
return tmp