Brush C++ API
A flexible interpretable machine learning framework
Loading...
Searching...
No Matches
bandit_operator.cpp
Go to the documentation of this file.
1#include "bandit_operator.h"
2
3namespace Brush {
4namespace MAB {
5
6template<typename T>
8{
9 // Initialize the map with the keys and uniform distributed values
10 float uniform_prob = 1.0 / arms.size();
11
12 this->probabilities = std::map<T, float>();
13 for (const T& arm : arms) {
14 this->probabilities[arm] = uniform_prob;
15 }
16}
17
18template<typename T>
19BanditOperator<T>::BanditOperator(map<T, float> arms_probs)
20{
21 this->probabilities = std::map<T, float>();
22 for (const auto& arm_prob : arms_probs) {
23 this->probabilities[arm_prob.first] = arm_prob.second;
24 }
25}
26
27template<typename T>
29{
30 // TODO: Implement the logic for sampling probabilities
31 // based on the bandit operator's strategy
32
33 // Throw an error if the select() operation is undefined
34 HANDLE_ERROR_THROW("Undefined bandit sample_probs() operation");
35
36 // Return an empty vector
37 return this->probabilities;
39
40template<typename T>
41T BanditOperator<T>::choose(const VectorXf& context)
42{
43 // TODO: Implement the logic for sampling probabilities
44 // based on the bandit operator's strategy
45
46 HANDLE_ERROR_THROW("Undefined bandit choose() operation");
47
48 // Placeholder
49 return this->probabilities.begin()->first;
50}
51
52
53template<typename T>
54void BanditOperator<T>::update(T arm, float reward, VectorXf& context)
55{
56 // TODO: Implement the logic for updating the bandit operator's internal state
57 // based on the received rewards
58
59 // Throw an error if the update operation is undefined
60 HANDLE_ERROR_THROW("Undefined bandit update() operation");
61}
62
63} // MAB
64} // Brush
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.
BanditOperator(vector< T > arms)
Constructs a BanditOperator object with a vector of arms.
std::map< T, float > probabilities
virtual void update(T arm, float reward, VectorXf &context)
Updates the reward for a specific arm.
#define HANDLE_ERROR_THROW(err)
Definition error.h:27
< nsga2 selection operator for getting the front
Definition bandit.cpp:4