Connect++ 0.5.0
A fast, readable connection prover for first-order logic.
Loading...
Searching...
No Matches
ERWA.hpp
1/*
2
3Copyright © 2023-24 Sean Holden. All rights reserved.
4
5*/
6/*
7
8This file is part of Connect++.
9
10Connect++ is free software: you can redistribute it and/or modify it
11under the terms of the GNU General Public License as published by the
12Free Software Foundation, either version 3 of the License, or (at your
13option) any later version.
14
15Connect++ is distributed in the hope that it will be useful, but WITHOUT
16ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
18more details.
19
20You should have received a copy of the GNU General Public License along
21with Connect++. If not, see <https://www.gnu.org/licenses/>.
22
23*/
24
25#ifndef ERWA_HPP
26#define ERWA_HPP
27
28#include <iostream>
29#include <vector>
30#include <math.h>
31
32#include "Parameters.hpp"
33
34#include <boost/random/mersenne_twister.hpp>
35#include <boost/random/bernoulli_distribution.hpp>
36#include <boost/random/uniform_int_distribution.hpp>
37
38using std::vector;
39using std::cerr;
40using std::endl;
41using std::ostream;
42
53class ERWA {
54private:
61 static boost::random::mt19937 random_generator;
62 boost::random::bernoulli_distribution<> p;
63 boost::random::uniform_int_distribution<> p2;
64 vector<double> r_hat;
65 double epsilon;
66 double alpha;
67 size_t K;
68 size_t n;
69 bool epsilon_greedy;
70 bool alpha_is_1_over_n;
79 size_t choice;
84 size_t find_max() const;
85public:
86 ERWA() = delete;
87 ERWA(size_t, bool=true, bool=true);
88
89 inline size_t get_choice() const {
90 return choice;
91 }
95 inline void set_epsilon(double _e) {
96 epsilon = _e;
97 boost::random::bernoulli_distribution<> new_p(_e);
98 p = new_p;
99 }
103 inline void set_alpha(double _a) {
104 alpha = _a;
105 }
109 size_t choose();
113 void reward(double);
114
115 friend ostream& operator<<(ostream&, const ERWA&);
116};
117
118#endif
Implementation of the ERWA algorithm for multiarmed bandits.
Definition ERWA.hpp:53
static boost::random::mt19937 random_generator
Random source.
Definition ERWA.hpp:61
size_t choice
Store the last choice made.
Definition ERWA.hpp:79
size_t choose()
Choose using the current state.
Definition ERWA.cpp:63
bool choose_next
Belt-and braces: warn if choose/reward happens in the wrong order.
Definition ERWA.hpp:75
size_t find_max() const
Find the index of the currently maximum r_hat.
Definition ERWA.cpp:50
void reward(double)
Provide reward for the most recent choice.
Definition ERWA.cpp:78
void set_alpha(double _a)
Reset alpha to something different.
Definition ERWA.hpp:103
void set_epsilon(double _e)
Reset epsilon to something different.
Definition ERWA.hpp:95