Brush C++ API
A flexible interpretable machine learning framework
Loading...
Searching...
No Matches
linear_thompson.h
Go to the documentation of this file.
1#include "bandit_operator.h"
2
3// #include <boost/random.hpp>
4// #include <boost/random/gamma_distribution.hpp>
5
6#include <boost/math/distributions/gamma.hpp>
7
8// // https://www.boost.org/doc/libs/1_85_0/doc/html/boost/random/beta_distribution.html
9// #include <boost/random/beta_distribution.hpp>
10
11#include "../util/utils.h" // to use random generator
12
13#ifndef LINEAR_THOMPSON_H
14#define LINEAR_THOMPSON_H
15
16namespace Brush {
17namespace MAB {
18
19template <typename T>
21{
22public:
23 LinearThompsonSamplingBandit(vector<T> arms);
24 LinearThompsonSamplingBandit(map<T, float> arms_probs);
26
27 std::map<T, float> sample_probs(bool update);
28 T choose(const VectorXf& context);
29 void update(T arm, float reward, VectorXf& context);
30private:
31 int n_arms;
32
33 vector<MatrixXf> B;
34 vector<MatrixXf> B_inv;
35 vector<MatrixXf> B_inv_sqrt;
36
37 MatrixXf m2_r;
38 MatrixXf mean;
39
40 // we need to make sure indexes does not change
41 std::map<int, T> arm_index_to_key;
42};
43
44} // MAB
45} // Brush
46
47#endif // LINEAR_THOMPSON_H
BanditOperator(vector< T > arms)
Constructs a BanditOperator object with a vector of arms.
void update(T arm, float reward, VectorXf &context)
Updates the reward for a specific arm.
std::map< T, float > sample_probs(bool update)
Samples the probabilities of the arms.
T choose(const VectorXf &context)
Chooses an arm based on the given tree and fitness. Should call sample_probs internally.
< nsga2 selection operator for getting the front
Definition bandit.cpp:4