Brush C++ API
A flexible interpretable machine learning framework
Toggle main menu visibility
Loading...
Searching...
No Matches
bandit_operator.cpp
Go to the documentation of this file.
1
#include "
bandit_operator.h
"
2
3
namespace
Brush
{
4
namespace
MAB
{
5
6
BanditOperator::BanditOperator
(vector<string> arms)
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
17
BanditOperator::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
25
std::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
37
string
BanditOperator::choose
()
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
49
void
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
bandit_operator.h
Brush::MAB::BanditOperator::probabilities
std::map< string, float > probabilities
Definition
bandit_operator.h:66
Brush::MAB::BanditOperator::update
virtual void update(string arm, float reward)
Updates the reward for a specific arm.
Definition
bandit_operator.cpp:49
Brush::MAB::BanditOperator::choose
virtual string choose()
Chooses an arm based on the given tree and fitness. Should call sample_probs internally.
Definition
bandit_operator.cpp:37
Brush::MAB::BanditOperator::BanditOperator
BanditOperator(vector< string > arms)
Constructs a BanditOperator object with a vector of arms.
Definition
bandit_operator.cpp:6
Brush::MAB::BanditOperator::sample_probs
virtual std::map< string, float > sample_probs(bool update)
Samples the probabilities of the arms.
Definition
bandit_operator.cpp:25
HANDLE_ERROR_THROW
#define HANDLE_ERROR_THROW(err)
Definition
error.h:27
Brush::MAB
Definition
bandit.cpp:4
Brush
< nsga2 selection operator for getting the front
Definition
bandit.cpp:3
src
bandit
bandit_operator.cpp
Generated by
1.17.0