-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharms.py
35 lines (27 loc) · 959 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
"""
Author: DURUII
Date: 2023/12/16
Ref:
1. https://github.com/johnmyleswhite/BanditsBook/blob/master/python/arms/normal.py
2. simulation settings in the paper
"""
import random
class NormalArm:
def __init__(self, mu: float, sigma: float):
""" Mean and standard deviation for the normal distribution."""
self.mu = mu
self.sigma = sigma
def draw(self):
""" Returns the achieved reward of the arm at this round. """
return random.gauss(self.mu, self.sigma)
class StrategicArm(NormalArm):
c_min, c_max = 0.1, 1
def __init__(self):
# in the paper, r is expected reward
r = random.uniform(0.1, 1)
# to make that sample value is within 0~1 with 97%
sigma = random.uniform(0, min(r / 3, (1 - r) / 3))
super().__init__(r, sigma)
# c for cost, b for bid, c_i = b_i according to the theorem 2
self.c = random.uniform(0.1, 1)
self.b = self.c