bitsim
Model, simulate, estimate and control robots in C++
Loading...
Searching...
No Matches
multi_armed_bandits.h
Go to the documentation of this file.
1#ifndef MULTI_ARMED_BANDITS_H
2#define MULTI_ARMED_BANDITS_H
3
8
9#include <any>
10#include <atomic>
11#include <random>
12#include <string>
13#include <unordered_map>
14#include <vector>
15
16namespace bitrl
17{
19{
20
26{
27
32
37
42
47};
48
54class MultiArmedBandits final : public EnvBase<TimeStep<bool>, MultiArmedBanditsSpace>
55{
56
57 public:
61 static const std::string name;
62
67
73
78
83
88
93
98
106 virtual void
107 make(const std::string &version, const std::unordered_map<std::string, std::any> &options,
108 const std::unordered_map<std::string, std::any> &reset_options) override final;
109
113 virtual void close() override final;
114
118 virtual time_step_type reset() override final;
119
124 virtual time_step_type step(const action_type &action) override final;
125
129 uint_t n_actions() const noexcept { return bandits_.size(); }
130
134 real_t success_reward() const noexcept { return success_reward_; }
135
139 real_t fail_reward() const noexcept { return fail_reward_; }
140
145 static uint_t n_copies() { return n_copies_.load(); }
146
147 private:
151 uint_t seed_;
152
157 std::mt19937 generator_;
158
163 static std::atomic<uint_t> n_copies_;
164
168 real_t success_reward_;
169
174 real_t fail_reward_;
175
179 std::vector<bitsim::maths::stats::BernoulliDist> bandits_;
180};
181
182} // namespace envs::bandits
183} // namespace bitrl
184
185#endif
MultiArmedBanditsSpace::state_space state_space_type
Definition env_base.h:45
MultiArmedBanditsSpace::state_type state_type
Definition env_base.h:48
const std::unordered_map< std::string, std::any > & reset_options() const noexcept
Definition env_base.h:105
EnvBase(const std::string &idx=bitsim::consts::INVALID_STR, const std::string &name=bitsim::consts::INVALID_STR)
MultiArmedBanditsSpace::action_space action_space_type
Definition env_base.h:51
TimeStep< bool > time_step_type
Definition env_base.h:42
MultiArmedBanditsSpace::action_type action_type
Definition env_base.h:54
std::string version() const noexcept
Definition env_base.h:143
static uint_t n_copies()
Definition multi_armed_bandits.h:145
EnvBase< TimeStep< bool >, MultiArmedBanditsSpace > base_type
The base type.
Definition multi_armed_bandits.h:66
base_type::time_step_type time_step_type
The time step type we return every time a step in the environment is performed.
Definition multi_armed_bandits.h:72
virtual time_step_type reset() override final
Reset the environment.
uint_t n_actions() const noexcept
Return the number of actions.
Definition multi_armed_bandits.h:129
real_t fail_reward() const noexcept
Returns the fail reward.
Definition multi_armed_bandits.h:139
base_type::state_space_type state_space_type
The type describing the state space for the environment.
Definition multi_armed_bandits.h:77
real_t success_reward() const noexcept
Returns the sucees reward.
Definition multi_armed_bandits.h:134
base_type::action_type action_type
The type of the action to be undertaken in the environment.
Definition multi_armed_bandits.h:87
virtual void close() override final
close the environment
virtual time_step_type step(const action_type &action) override final
step in the environment by performing the given action
base_type::action_space_type action_space_type
The type of the action space for the environment.
Definition multi_armed_bandits.h:82
base_type::state_type state_type
The type of the action to be undertaken in the environment.
Definition multi_armed_bandits.h:92
static const std::string name
name
Definition multi_armed_bandits.h:61
MultiArmedBandits()
MultiArmedBandits Constructor.
virtual void make(const std::string &version, const std::unordered_map< std::string, std::any > &options, const std::unordered_map< std::string, std::any > &reset_options) override final
make. Builds the environment.
Definition multi_armed_bandits.h:19
Various utilities used when working with RL problems.
Definition bitrl_log.h:25
std::size_t uint_t
uint_t
Definition bitsim_types.h:40
double real_t
real_t
Definition bitsim_types.h:20
struct MultiArmedBanditsSpace specifies the MultiArmedBandits state-action space
Definition multi_armed_bandits.h:26
Null state_type
The type of the state.
Definition multi_armed_bandits.h:36
Null action_space
The type of the action space for the environment.
Definition multi_armed_bandits.h:41
uint_t action_type
The type of the action to be undertaken in the environment.
Definition multi_armed_bandits.h:46
Null state_space
The type describing the state space for the environment.
Definition multi_armed_bandits.h:31
Null placeholder.
Definition bitsim_types.h:179