k-Armed Bandit
1.0.0
A collection of k-armed bandits and assoicated agents for reinforcement learning
Loading...
Searching...
No Matches
bandit
random_walk.py
Go to the documentation of this file.
1
import
numpy
2
from
bandit
import
Normal
3
4
5
class
RandomWalk
(
Normal
):
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
bandit.base_bandit.BaseBandit.k
int k(self)
Return the number of arms this bandit has.
Definition
base_bandit.py:26
bandit.normal.Normal
This bandit draws a reward from a set normal distribution each time an arm is chosen.
Definition
normal.py:5
bandit.normal.Normal._mean
_mean
Definition
normal.py:28
bandit.random_walk.RandomWalk
A random walk bandit.
Definition
random_walk.py:5
bandit.random_walk.RandomWalk.__init__
None __init__(self, int k)
Construct the class.
Definition
random_walk.py:17
bandit.random_walk.RandomWalk.select
select(self, index)
Select one or several arms to obtain a reward from.
Definition
random_walk.py:20
Generated by
1.9.8