MCPcopy Create free account
hub / github.com/lazyprogrammer/machine_learning_examples / Bandit

Class Bandit

ab_testing/bayesian_bandit.py:20–36  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

18
19
20class 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
39def plot(bandits, trial):

Callers 2

run_experimentFunction · 0.90
experimentFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected