Brush C++ API
A flexible interpretable machine learning framework
Loading...
Searching...
No Matches
bandit.h
Go to the documentation of this file.
1/* Brush
2copyright 2024 William La Cava
3license: GNU/GPL v3
4*/
5
6#ifndef BANDIT_H
7#define BANDIT_H
8
9#include "../init.h"
10#include "../types.h"
11#include "../program/program.h"
13#include "../util/utils.h"
14#include "bandit_operator.h"
15#include "dummy.h"
16#include "thompson.h"
17
18namespace Brush {
19namespace MAB {
20
21using namespace Brush;
22
31struct Bandit
32{
33 using Iter = tree<Node>::pre_order_iterator;
34
35public:
39 std::shared_ptr<BanditOperator> pbandit;
40 // TODO: This should be a shared pointer to allow multiple instances of Bandit to share the same operator.
41
42 std::string type;
43 vector<string> arms;
44
45 std::map<string, float> probabilities;
46
47 Bandit();
49
55 Bandit(string type, vector<string> arms);
56
62 Bandit(string type, map<string, float> arms_probs);
63
67 void set_bandit();
68
72 void set_arms(vector<string> arms);
73
77 vector<string> get_arms();
78
82 string get_type();
83
87 void set_type(string type);
88
92 map<string, float> get_probs();
93
98 void set_probs(map<string, float> arms_probs);
99
105 map<string, float> sample_probs(bool update=false);
106
112 string choose();
113
119 void update(string arm, float reward);
120};
121
122//TODO: serialization should save the type of bandit and its parameters
123
124} // MAB
125} // Brush
126#endif
< nsga2 selection operator for getting the front
Definition bandit.cpp:4
tree< Node >::pre_order_iterator Iter
Definition bandit.h:33
void update(string arm, float reward)
Updates the bandit's state based on the chosen arm and the received reward.
Definition bandit.cpp:94
string get_type()
Gets the type of the bandit.
Definition bandit.cpp:51
vector< string > arms
Definition bandit.h:43
vector< string > get_arms()
Gets the arms of the bandit.
Definition bandit.cpp:59
void set_type(string type)
Sets the type of the bandit.
Definition bandit.cpp:55
void set_arms(vector< string > arms)
Sets the arms of the bandit.
Definition bandit.cpp:63
std::map< string, float > probabilities
Definition bandit.h:45
std::string type
Definition bandit.h:42
void set_probs(map< string, float > arms_probs)
Sets the probabilities associated with each arm.
Definition bandit.cpp:71
string choose()
Selects an arm.
Definition bandit.cpp:90
map< string, float > sample_probs(bool update=false)
Samples the probabilities associated with each arm using the policy.
Definition bandit.cpp:75
void set_bandit()
Sets the bandit operator (policy).
Definition bandit.cpp:37
std::shared_ptr< BanditOperator > pbandit
A shared pointer to the bandit operator (policy).
Definition bandit.h:39
map< string, float > get_probs()
Gets the probabilities associated with each arm.
Definition bandit.cpp:67