k-Armed Bandit 1.0.0
A collection of k-armed bandits and assoicated agents for reinforcement learning
Loading...
Searching...
No Matches
base_bandit.py
Go to the documentation of this file.
1import abc
2
3
4class BaseBandit(abc.ABC):
5 """
6 A base class for the various bandit implementations.
7
8 This class defines several abstract methods and properties that must be
9 implemented by any k-armed bandit implementation. This ensures consistent
10 APIs across all of them.
11 """
12
13 def __init__(self, k: int) -> None:
14 """
15 Initialize the object with a set number of arms.
16
17 @param k The number of arms this bandit should have. This must be an
18 integer greater than zero.
19 @exception ValueError if k is not an integer greater than zero.
20 """
21 if not isinstance(k, int) or k <= 0:
22 raise ValueError('k must be an integer greater than 0.')
23 self._k = k
24
25 @property
26 def k(self) -> int:
27 """
28 Return the number of arms this bandit has.
29 @return An int greater than or equal to one.
30 """
31 return self._k
32
33 @abc.abstractmethod
34 def select(self, index):
35 """
36 The method to select one of the arms of the bandit.
37
38 When implemented, this method should return the reward obtained when
39 selecting the given arm index.
40 @param index Some sort of index representation to select which arms to
41 get rewards from. Typically, this will be a single integer or some
42 sort of list, array, etc. of integers.
43 """
44 raise NotImplementedError("Subclass does not implement select method.")
45
46 @abc.abstractmethod
47 def trueValues(self):
48 """
49 Return the true reward values of the bandit.
50
51 When implemented, this should provide the user with the complete truth
52 of the bandit's state at the moment called. It is up to the
53 implementation what exact information this is.
54 """
55 raise NotImplementedError(
56 'Subclass does not implement trueValues method.')
A base class for the various bandit implementations.
Definition base_bandit.py:4
int k(self)
Return the number of arms this bandit has.
select(self, index)
The method to select one of the arms of the bandit.
None __init__(self, int k)
Initialize the object with a set number of arms.
trueValues(self)
Return the true reward values of the bandit.