7#include "bitrl/base/bitrl_config.h"
27template <
typename StateTp>
30 return table.row(state);
33template <
typename StateTp>
38 auto itr = table.find(state);
40 if (itr == table.end())
42 assert(
false &&
"Invalid state given");
49template <
typename StateTp>
53 auto itr = table.find(state);
55 if (itr == table.end())
57 assert(
false &&
"Invalid state given");
113template <
typename VectorType>
118 std::uniform_real_distribution<> real_dist_(0.0, 1.0);
126 std::uniform_int_distribution<uint_t> distrib_(
275template <
typename KeyTp>
277 const std::vector<index_type> &indices,
action_type n_actions,
real_t init_value)
282 for (
uint_t i = 0; i < indices.size(); ++i)
290template <
typename KeyTp>
297 static_assert(index == 1 || index == 2,
"Invalid index for template parameter");
300 return get_table_values_(
q_table_1, state)[action];
303 return get_table_values_(
q_table_2, state)[action];
306template <
typename KeyTp>
313 static_assert(index == 1 || index == 2,
"Invalid index for template parameter");
317 auto &vals1 = get_table_values_(
q_table_1, state);
318 vals1[action] = value;
321 auto &vals2 = get_table_values_(
q_table_2, state);
322 vals2[action] = value;
331 template <
typename TableTp,
typename StateTp>
332 static uint_t max_action(
const TableTp &q1_table,
const TableTp &q2_table,
const StateTp &state,
338 template <
typename TableTp,
typename StateTp>
342template <
typename TableTp,
typename StateTp>
344 const TableTp &q2_table,
345 const StateTp &state,
uint_t )
349 get_table_values_(q1_table, state) + get_table_values_(q2_table, state);
350 Eigen::Index idx = 0;
352 return static_cast<uint_t>(idx);
355template <
typename TableTp,
typename StateTp>
357 const StateTp &state,
uint_t )
361 Eigen::Index idx = 0;
363 return static_cast<uint_t>(idx);
uint_t arg_max(const VectorType &vec)
Returns the index of the element that has the maximum value in the array. Implementation taken from h...
Definition vector_math.h:383
Definition dummy_agent.h:9
EpsilonDecayOptionType
Definition epsilon_decay_options.h:12
uint_t max_action(const DynMat< real_t > &qtable, uint_t state, uint_t n_actions)
max_action
std::size_t uint_t
uint_t
Definition bitsim_types.h:40
Eigen::MatrixX< T > DynMat
Dynamically sized matrix to use around the library.
Definition bitsim_types.h:51
double real_t
real_t
Definition bitsim_types.h:20
Eigen::RowVectorX< T > DynVec
Dynamically sized row vector.
Definition bitsim_types.h:101
The with_decay_epsilon_option_mixin struct.
Definition rl_mixins.h:79
uint_t seed
Definition rl_mixins.h:86
real_t min_eps
Definition rl_mixins.h:82
EpsilonDecayOptionType decay_op
Definition rl_mixins.h:87
real_t epsilon_decay
Definition rl_mixins.h:84
uint_t n_actions
Definition rl_mixins.h:85
uint_t choose_action_index(const VectorType &values) const
Definition rl_mixins.h:114
std::mt19937 generator
The generator of the random numbers. seed_generator() seeds it with seed; a new generator in every ca...
Definition rl_mixins.h:93
void seed_generator()
seed_generator. Seeds the generator with seed
Definition rl_mixins.h:98
real_t max_eps
Definition rl_mixins.h:83
real_t eps
Definition rl_mixins.h:81
real_t eps_init
Definition rl_mixins.h:80
real_t decay_eps(uint_t episode_index)
decay_eps
Definition rl_mixins.h:326
static uint_t max_action(const TableTp &q1_table, const TableTp &q2_table, const StateTp &state, uint_t n_actions)
Returns the max action by averaging the state values from the two tables.
Definition rl_mixins.h:343
real_t value_type
Definition rl_mixins.h:164
void set(const state_type &state, const action_type action, const value_type value)
DynMat< value_type > q_table_1
q_table_1
Definition rl_mixins.h:169
DynMat< value_type > q_table_2
q_table_2
Definition rl_mixins.h:174
uint_t state_type
Definition rl_mixins.h:162
uint_t index_type
Definition rl_mixins.h:161
value_type get(const state_type &state, const action_type action) const
void initialize(const std::vector< index_type > &indices, action_type n_actions, real_t init_value)
initialize
uint_t action_type
Definition rl_mixins.h:163
void initialize(state_type n_states, action_type n_actions, real_t init_value)
initialize. Sizes both tables to n_states x n_actions and sets every entry to init_value
Definition rl_mixins.h:189
KeyTp index_type
Definition rl_mixins.h:239
void initialize(const std::vector< index_type > &indices, action_type n_actions, real_t init_value)
initialize
Definition rl_mixins.h:276
std::map< KeyTp, DynVec< real_t > > q_table_2
q_table_2
Definition rl_mixins.h:252
std::map< KeyTp, DynVec< real_t > > q_table_1
q_table_1
Definition rl_mixins.h:247
KeyTp state_type
Definition rl_mixins.h:240
void set(const state_type &state, const action_type action, const value_type value)
Definition rl_mixins.h:308
uint_t action_type
Definition rl_mixins.h:241
real_t value_type
Definition rl_mixins.h:242
value_type get(const state_type &state, const action_type action) const
Definition rl_mixins.h:154
The WithQTableMixin struct.
Definition rl_mixins.h:135
uint_t action_type
Definition rl_mixins.h:137
uint_t state_type
Definition rl_mixins.h:136
void initialize(state_type n_states, action_type n_actions, real_t init_value)
initialize
DynMat< value_type > q_table
q_table
Definition rl_mixins.h:143
real_t value_type
Definition rl_mixins.h:138