Brush C++ API
A flexible interpretable machine learning framework
Loading...
Searching...
No Matches
Brush::MAB::Bandit< T > Struct Template Reference

The Bandit struct represents a multi-armed bandit. More...

#include <bandit.h>

Collaboration diagram for Brush::MAB::Bandit< T >:

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.
 
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
 

Detailed Description

template<typename T>
struct Brush::MAB::Bandit< T >

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.

Definition at line 33 of file bandit.h.

Member Typedef Documentation

◆ Iter

template<typename T>
using Brush::MAB::Bandit< T >::Iter = tree<Node>::pre_order_iterator

Definition at line 35 of file bandit.h.

Constructor & Destructor Documentation

◆ Bandit() [1/3]

template<typename T>
Brush::MAB::Bandit< T >::Bandit ( )

Definition at line 8 of file bandit.cpp.

Here is the call graph for this function:

◆ ~Bandit()

template<typename T>
Brush::MAB::Bandit< T >::~Bandit ( )
inline

Definition at line 50 of file bandit.h.

◆ Bandit() [2/3]

template<typename T>
Brush::MAB::Bandit< T >::Bandit ( string type,
vector< T > arms )

Constructor for the Bandit struct.

Parameters
typeThe type of the bandit.
armsThe arms of the bandit.

Definition at line 16 of file bandit.cpp.

Here is the call graph for this function:

◆ Bandit() [3/3]

template<typename T>
Brush::MAB::Bandit< T >::Bandit ( string type,
map< T, float > arms_probs )

Constructor for the Bandit struct.

Parameters
typeThe type of the bandit.
arms_probsThe arms and their associated probabilities.

Definition at line 29 of file bandit.cpp.

Here is the call graph for this function:

Member Function Documentation

◆ choose()

template<typename T>
T Brush::MAB::Bandit< T >::choose ( const VectorXf & context)

Selects an arm using the tree and fitness as context.

Template Parameters
TThe type of the arms the bandit has.
Parameters
treeThe tree structure containing nodes of type T.
fThe fitness function used to evaluate and select nodes.
Returns
T The selected arm from the tree.

Definition at line 93 of file bandit.cpp.

◆ get_arms()

template<typename T>
vector< T > Brush::MAB::Bandit< T >::get_arms ( )

Gets the arms of the bandit.

Definition at line 68 of file bandit.cpp.

◆ get_context()

template<typename T>
template<ProgramType PT>
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.

◆ get_probs()

template<typename T>
map< T, float > Brush::MAB::Bandit< T >::get_probs ( )

Gets the probabilities associated with each arm.

Definition at line 78 of file bandit.cpp.

◆ get_type()

template<typename T>
string Brush::MAB::Bandit< T >::get_type ( )

Gets the type of the bandit.

Definition at line 58 of file bandit.cpp.

◆ sample_probs()

template<typename T>
map< T, float > Brush::MAB::Bandit< T >::sample_probs ( bool update = false)

Samples the probabilities associated with each arm using the policy.

Parameters
updateFlag indicating whether to update the bandit's state, or just return the current probabilities.
Returns
The sampled probabilities associated with each arm.

Definition at line 88 of file bandit.cpp.

Here is the call graph for this function:

◆ set_arms()

template<typename T>
void Brush::MAB::Bandit< T >::set_arms ( vector< T > arms)

Sets the arms of the bandit.

Definition at line 73 of file bandit.cpp.

Here is the caller graph for this function:

◆ set_bandit()

template<typename T>
void Brush::MAB::Bandit< T >::set_bandit ( )

Sets the bandit operator (policy).

Definition at line 41 of file bandit.cpp.

Here is the caller graph for this function:

◆ set_probs()

template<typename T>
void Brush::MAB::Bandit< T >::set_probs ( map< T, float > arms_probs)

Sets the probabilities associated with each arm.

Parameters
arms_probsThe arms and their associated probabilities.

Definition at line 83 of file bandit.cpp.

Here is the caller graph for this function:

◆ set_type()

template<typename T>
void Brush::MAB::Bandit< T >::set_type ( string type)

Sets the type of the bandit.

Definition at line 63 of file bandit.cpp.

Here is the caller graph for this function:

◆ update()

template<typename T>
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.

Parameters
armThe chosen arm.
rewardThe received reward.

Definition at line 98 of file bandit.cpp.

Here is the caller graph for this function:

Member Data Documentation

◆ arms

template<typename T>
vector<T> Brush::MAB::Bandit< T >::arms

The arms of the bandit.

Definition at line 45 of file bandit.h.

◆ pbandit

template<typename T>
std::shared_ptr<BanditOperator<T> > Brush::MAB::Bandit< T >::pbandit

A shared pointer to the bandit operator (policy).

Definition at line 41 of file bandit.h.

◆ probabilities

template<typename T>
std::map<T, float> Brush::MAB::Bandit< T >::probabilities

The probabilities associated with each arm.

Definition at line 47 of file bandit.h.

◆ type

template<typename T>
std::string Brush::MAB::Bandit< T >::type

The type of the bandit.

Definition at line 44 of file bandit.h.


The documentation for this struct was generated from the following files: