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

A virtual class representing a bandit operator. More...

#include <bandit_operator.h>

Inheritance diagram for Brush::MAB::BanditOperator< T >:
Collaboration diagram for Brush::MAB::BanditOperator< T >:

Public Member Functions

 BanditOperator (vector< T > arms)
 Constructs a BanditOperator object with a vector of arms.
 
 BanditOperator (map< T, float > arms_probs)
 Constructs a BanditOperator object with a map of arms and their probabilities.
 
 ~BanditOperator ()
 
virtual std::map< T, float > sample_probs (bool update)
 Samples the probabilities of the arms.
 
virtual T choose (const VectorXf &context)
 Chooses an arm based on the given tree and fitness. Should call sample_probs internally.
 
virtual void update (T arm, float reward, VectorXf &context)
 Updates the reward for a specific arm.
 

Protected Attributes

std::map< T, float > probabilities
 

Private Types

using Iter = tree<Node>::pre_order_iterator
 

Detailed Description

template<typename T>
class Brush::MAB::BanditOperator< T >

A virtual class representing a bandit operator.

This class provides functionality for sampling probabilities and updating rewards for different arms. The bandit should somehow behave stocasticaly when called twice in a row without being rewarded, because some mutations may require multiple sampling from the search space. Also, the bandit should have a functionality to return smapling probabilities, instead of just the chosen arm.

Template Parameters
TThe type of the arms.

Definition at line 22 of file bandit_operator.h.

Member Typedef Documentation

◆ Iter

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

Definition at line 24 of file bandit_operator.h.

Constructor & Destructor Documentation

◆ BanditOperator() [1/2]

template<typename T>
Brush::MAB::BanditOperator< T >::BanditOperator ( vector< T > arms)

Constructs a BanditOperator object with a vector of arms.

Parameters
armsThe vector of arms.

Definition at line 7 of file bandit_operator.cpp.

Here is the caller graph for this function:

◆ BanditOperator() [2/2]

template<typename T>
Brush::MAB::BanditOperator< T >::BanditOperator ( map< T, float > arms_probs)

Constructs a BanditOperator object with a map of arms and their probabilities.

Parameters
arms_probsThe map of arms and their probabilities.

Definition at line 19 of file bandit_operator.cpp.

◆ ~BanditOperator()

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

Definition at line 40 of file bandit_operator.h.

Member Function Documentation

◆ choose()

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

Chooses an arm based on the given tree and fitness. Should call sample_probs internally.

Parameters
treeThe tree structure used to choose the arm.
fThe fitness value used to influence the choice.
Returns
The arm with highest probability.

Reimplemented in Brush::MAB::DummyBandit< T >, Brush::MAB::LinearThompsonSamplingBandit< T >, and Brush::MAB::ThompsonSamplingBandit< T >.

Definition at line 41 of file bandit_operator.cpp.

◆ sample_probs()

template<typename T>
std::map< T, float > Brush::MAB::BanditOperator< T >::sample_probs ( bool update)
virtual

Samples the probabilities of the arms.

Parameters
updateA boolean indicating whether to update the probabilities.
Returns
A map of arms and their probabilities.

Reimplemented in Brush::MAB::DummyBandit< T >, Brush::MAB::LinearThompsonSamplingBandit< T >, and Brush::MAB::ThompsonSamplingBandit< T >.

Definition at line 28 of file bandit_operator.cpp.

Here is the call graph for this function:

◆ update()

template<typename T>
void Brush::MAB::BanditOperator< T >::update ( T arm,
float reward,
VectorXf & context )
virtual

Updates the reward for a specific arm.

Parameters
armThe arm for which to update the reward.
rewardThe reward value.

Reimplemented in Brush::MAB::DummyBandit< T >, Brush::MAB::LinearThompsonSamplingBandit< T >, and Brush::MAB::ThompsonSamplingBandit< T >.

Definition at line 54 of file bandit_operator.cpp.

Here is the caller graph for this function:

Member Data Documentation

◆ probabilities

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

Definition at line 67 of file bandit_operator.h.


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