Brush C++ API
A flexible interpretable machine learning framework
Toggle main menu visibility
Loading...
Searching...
No Matches
bandit.h
Go to the documentation of this file.
1
/* Brush
2
copyright 2024 William La Cava
3
license: 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
"
12
#include "
../vary/search_space.h
"
13
#include "
../util/utils.h
"
14
#include "
bandit_operator.h
"
15
#include "
dummy.h
"
16
#include "
thompson.h
"
17
18
namespace
Brush
{
19
namespace
MAB
{
20
21
using namespace
Brush;
22
31
struct
Bandit
32
{
33
using
Iter
= tree<Node>::pre_order_iterator;
34
35
public
:
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
();
48
~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
private
:
122
bool
bandit_set
=
false
;
123
void
ensure_bandit_set
()
const
;
124
};
125
126
//TODO: serialization should save the type of bandit and its parameters
127
128
}
// MAB
129
}
// Brush
130
#endif
bandit_operator.h
dummy.h
init.h
Brush::MAB
Definition
bandit.cpp:4
Brush
< nsga2 selection operator for getting the front
Definition
bandit.cpp:3
program.h
search_space.h
Brush::MAB::Bandit::Bandit
Bandit()
Definition
bandit.cpp:6
Brush::MAB::Bandit::Iter
tree< Node >::pre_order_iterator Iter
Definition
bandit.h:33
Brush::MAB::Bandit::ensure_bandit_set
void ensure_bandit_set() const
Definition
bandit.cpp:50
Brush::MAB::Bandit::update
void update(string arm, float reward)
Updates the bandit's state based on the chosen arm and the received reward.
Definition
bandit.cpp:101
Brush::MAB::Bandit::get_type
string get_type()
Gets the type of the bandit.
Definition
bandit.cpp:56
Brush::MAB::Bandit::bandit_set
bool bandit_set
Definition
bandit.h:122
Brush::MAB::Bandit::arms
vector< string > arms
Definition
bandit.h:43
Brush::MAB::Bandit::get_arms
vector< string > get_arms()
Gets the arms of the bandit.
Definition
bandit.cpp:64
Brush::MAB::Bandit::set_type
void set_type(string type)
Sets the type of the bandit.
Definition
bandit.cpp:60
Brush::MAB::Bandit::set_arms
void set_arms(vector< string > arms)
Sets the arms of the bandit.
Definition
bandit.cpp:68
Brush::MAB::Bandit::probabilities
std::map< string, float > probabilities
Definition
bandit.h:45
Brush::MAB::Bandit::type
std::string type
Definition
bandit.h:42
Brush::MAB::Bandit::set_probs
void set_probs(map< string, float > arms_probs)
Sets the probabilities associated with each arm.
Definition
bandit.cpp:76
Brush::MAB::Bandit::choose
string choose()
Selects an arm.
Definition
bandit.cpp:96
Brush::MAB::Bandit::~Bandit
~Bandit()
Definition
bandit.h:48
Brush::MAB::Bandit::sample_probs
map< string, float > sample_probs(bool update=false)
Samples the probabilities associated with each arm using the policy.
Definition
bandit.cpp:80
Brush::MAB::Bandit::set_bandit
void set_bandit()
Sets the bandit operator (policy).
Definition
bandit.cpp:36
Brush::MAB::Bandit::pbandit
std::shared_ptr< BanditOperator > pbandit
A shared pointer to the bandit operator (policy).
Definition
bandit.h:39
Brush::MAB::Bandit::get_probs
map< string, float > get_probs()
Gets the probabilities associated with each arm.
Definition
bandit.cpp:72
thompson.h
types.h
utils.h
src
bandit
bandit.h
Generated by
1.17.0