k-Armed Bandit 1.0.0
A collection of k-armed bandits and assoicated agents for reinforcement learning
Loading...
Searching...
No Matches
random_walk.py
Go to the documentation of this file.
1import numpy
2from bandit import Normal
3
4
6 """
7 A random walk bandit.
8
9 This class features k arms with rewards from the arms drawn from normal
10 distributions. The means, when initialized, are drawn from a uniform range
11 of [-1, 1). However, after each call to select, the means for every arm
12 is changed. Each arm's mean is adjusted by a randomly selected value drawn
13 from a normal distribution with mean 0 and standard deviation 0.01. These
14 values are drawn independently for each arm.
15 """
16
17 def __init__(self, k: int) -> None:
18 super().__init__(k)
19
20 def select(self, index):
21 rewards = super().select(index)
22 # Now modify the means.
23 walk_values = numpy.random.normal(loc=0.0, scale=0.01, size=self.k)
24 self._mean += walk_values
25 return rewards
int k(self)
Return the number of arms this bandit has.
This bandit draws a reward from a set normal distribution each time an arm is chosen.
Definition normal.py:5
A random walk bandit.
Definition random_walk.py:5
None __init__(self, int k)
Construct the class.
select(self, index)
Select one or several arms to obtain a reward from.