| 18 | |
| 19 | |
| 20 | class Bandit: |
| 21 | def __init__(self, p): |
| 22 | self.p = p |
| 23 | self.a = 1 |
| 24 | self.b = 1 |
| 25 | self.N = 0 # for information only |
| 26 | |
| 27 | def pull(self): |
| 28 | return np.random.random() < self.p |
| 29 | |
| 30 | def sample(self): |
| 31 | return np.random.beta(self.a, self.b) |
| 32 | |
| 33 | def update(self, x): |
| 34 | self.a += x |
| 35 | self.b += 1 - x |
| 36 | self.N += 1 |
| 37 | |
| 38 | |
| 39 | def plot(bandits, trial): |
no outgoing calls
no test coverage detected