k-Armed Bandit 1.0.0
A collection of k-armed bandits and assoicated agents for reinforcement learning
Loading...
Searching...
No Matches
test_random.py
Go to the documentation of this file.
1from bandit import RandomWalk
2import numpy
3import unittest
4
5
6class TestRandomWalkBandit(unittest.TestCase):
7 """
8 Tests the implementation of a bandit with random walk on the distributions.
9
10 As this class inherits from Normal, the only difference is testing that the
11 distribution means change after each call to select.
12 """
13
15 """
16 Test that means change over time.
17
18 The class should randomly walk the mean of the distribution of each arm
19 after a call to select. So call it a number of times and watch for some
20 sort of change. Because it is random, the exact change can't be known,
21 so just ensure that the numbers do in fact change.
22 """
23 K = 100
24 bandit = RandomWalk(K)
25 (mean, _) = bandit.trueValues()
26 previous_mean = numpy.copy(mean)
27 values_have_changed = False
28 # Call select a number of times. As long as it changes at least once,
29 # then the method is working.
30 for i in range(100):
31 _ = bandit.select(0)
32 (mean, _) = bandit.trueValues()
33 values_have_changed |= not numpy.array_equal(previous_mean, mean)
34 previous_mean = numpy.copy(mean)
35 self.assertTrue(values_have_changed)
A random walk bandit.
Definition random_walk.py:5
Tests the implementation of a bandit with random walk on the distributions.
Definition test_random.py:6
test_mean_change(self)
Test that means change over time.