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
7{
8 // Initialize the map with the keys and uniform distributed values
9 float uniform_prob = 1.0 / arms.size();
10
11 this->probabilities = std::map<string, float>();
12 for (const string& arm : arms) {
13 this->probabilities[arm] = uniform_prob;
14 }
15}
16
17BanditOperator::BanditOperator(map<string, float> arms_probs)
18{
19 this->probabilities = std::map<string, float>();
20 for (const auto& arm_prob : arms_probs) {
21 this->probabilities[arm_prob.first] = arm_prob.second;
22 }
23}
24
25std::map<string, float> BanditOperator::sample_probs(bool update)
26{
27 // TODO: Implement the logic for sampling probabilities
28 // based on the bandit operator's strategy
29
30 // Throw an error if the select() operation is undefined
31 HANDLE_ERROR_THROW("Undefined bandit sample_probs() operation");
32
33 // Return an empty vector
34 return this->probabilities;
35}
36
38{
39 // TODO: Implement the logic for sampling probabilities
40 // based on the bandit operator's strategy
41
42 HANDLE_ERROR_THROW("Undefined bandit choose() operation");
43
44 // Placeholder
45 return this->probabilities.begin()->first;
46}
47
48
49void BanditOperator::update(string arm, float reward)
50{
51 // TODO: Implement the logic for updating the bandit operator's internal state
52 // based on the received rewards
53
54 // Throw an error if the update operation is undefined
55 HANDLE_ERROR_THROW("Undefined bandit update() operation");
56}
57
58} // MAB
59} // Brush
std::map< string, float > probabilities
virtual void update(string arm, float reward)
Updates the reward for a specific arm.
virtual string choose()
Chooses an arm based on the given tree and fitness. Should call sample_probs internally.
BanditOperator(vector< string > arms)
Constructs a BanditOperator object with a vector of arms.
virtual std::map< string, float > sample_probs(bool update)
Samples the probabilities of the arms.
#define HANDLE_ERROR_THROW(err)
Definition error.h:27
< nsga2 selection operator for getting the front
Definition bandit.cpp:4