Brush C++ API
A flexible interpretable machine learning framework
|
The Bandit struct represents a multi-armed bandit. More...
#include <bandit.h>
Public Types | |
using | Iter = tree<Node>::pre_order_iterator |
Public Member Functions | |
Bandit () | |
~Bandit () | |
Bandit (string type, vector< T > arms) | |
Constructor for the Bandit struct. | |
Bandit (string type, map< T, float > arms_probs) | |
Constructor for the Bandit struct. | |
void | set_bandit () |
Sets the bandit operator (policy). | |
void | set_arms (vector< T > arms) |
Sets the arms of the bandit. | |
vector< T > | get_arms () |
Gets the arms of the bandit. | |
string | get_type () |
Gets the type of the bandit. | |
void | set_type (string type) |
Sets the type of the bandit. | |
map< T, float > | get_probs () |
Gets the probabilities associated with each arm. | |
void | set_probs (map< T, float > arms_probs) |
Sets the probabilities associated with each arm. | |
map< T, float > | sample_probs (bool update=false) |
Samples the probabilities associated with each arm using the policy. | |
T | choose (const VectorXf &context) |
Selects an arm using the tree and fitness as context. | |
void | update (T arm, float reward, VectorXf &context) |
Updates the bandit's state based on the chosen arm and the received reward. | |
template<ProgramType PT> | |
VectorXf | get_context (const Program< PT > &program, Iter spot, const SearchSpace &ss, const Dataset &d) |
Public Attributes | |
std::shared_ptr< BanditOperator< T > > | pbandit |
A shared pointer to the bandit operator (policy). | |
std::string | type |
vector< T > | arms |
std::map< T, float > | probabilities |
The Bandit struct represents a multi-armed bandit.
The Bandit struct encapsulates the bandit operator (policy) and provides\ methods to set and get the arms, type, and probabilities of the bandit. It also provides a method to update the bandit's state based on the chosen arm and the received reward.
using Brush::MAB::Bandit< T >::Iter = tree<Node>::pre_order_iterator |
Brush::MAB::Bandit< T >::Bandit | ( | ) |
|
inline |
Brush::MAB::Bandit< T >::Bandit | ( | string | type, |
vector< T > | arms ) |
Constructor for the Bandit struct.
type | The type of the bandit. |
arms | The arms of the bandit. |
Definition at line 16 of file bandit.cpp.
Brush::MAB::Bandit< T >::Bandit | ( | string | type, |
map< T, float > | arms_probs ) |
Constructor for the Bandit struct.
type | The type of the bandit. |
arms_probs | The arms and their associated probabilities. |
Definition at line 29 of file bandit.cpp.
T Brush::MAB::Bandit< T >::choose | ( | const VectorXf & | context | ) |
Selects an arm using the tree and fitness as context.
T | The type of the arms the bandit has. |
tree | The tree structure containing nodes of type T. |
f | The fitness function used to evaluate and select nodes. |
Definition at line 93 of file bandit.cpp.
vector< T > Brush::MAB::Bandit< T >::get_arms | ( | ) |
Gets the arms of the bandit.
Definition at line 68 of file bandit.cpp.
VectorXf Brush::MAB::Bandit< T >::get_context | ( | const Program< PT > & | program, |
Iter | spot, | ||
const SearchSpace & | ss, | ||
const Dataset & | d ) |
Definition at line 103 of file bandit.cpp.
map< T, float > Brush::MAB::Bandit< T >::get_probs | ( | ) |
Gets the probabilities associated with each arm.
Definition at line 78 of file bandit.cpp.
string Brush::MAB::Bandit< T >::get_type | ( | ) |
Gets the type of the bandit.
Definition at line 58 of file bandit.cpp.
map< T, float > Brush::MAB::Bandit< T >::sample_probs | ( | bool | update = false | ) |
Samples the probabilities associated with each arm using the policy.
update | Flag indicating whether to update the bandit's state, or just return the current probabilities. |
Definition at line 88 of file bandit.cpp.
void Brush::MAB::Bandit< T >::set_arms | ( | vector< T > | arms | ) |
Sets the arms of the bandit.
Definition at line 73 of file bandit.cpp.
void Brush::MAB::Bandit< T >::set_bandit | ( | ) |
Sets the bandit operator (policy).
Definition at line 41 of file bandit.cpp.
void Brush::MAB::Bandit< T >::set_probs | ( | map< T, float > | arms_probs | ) |
Sets the probabilities associated with each arm.
arms_probs | The arms and their associated probabilities. |
Definition at line 83 of file bandit.cpp.
void Brush::MAB::Bandit< T >::set_type | ( | string | type | ) |
Sets the type of the bandit.
Definition at line 63 of file bandit.cpp.
void Brush::MAB::Bandit< T >::update | ( | T | arm, |
float | reward, | ||
VectorXf & | context ) |
Updates the bandit's state based on the chosen arm and the received reward.
arm | The chosen arm. |
reward | The received reward. |
Definition at line 98 of file bandit.cpp.
vector<T> Brush::MAB::Bandit< T >::arms |
std::shared_ptr<BanditOperator<T> > Brush::MAB::Bandit< T >::pbandit |
std::map<T, float> Brush::MAB::Bandit< T >::probabilities |
std::string Brush::MAB::Bandit< T >::type |