bitsim
Model, simulate, estimate and control robots in C++
Loading...
Searching...
No Matches
bitrl::rl::algos::td::DoubleQLearning< EnvTp, ActionSelector > Class Template Referencefinal

The class DoubleQLearning. Tabular double Q-learning, see van Hasselt, Double Q-learning, NIPS 2010. More...

#include <double_q_learning.h>

Inheritance diagram for bitrl::rl::algos::td::DoubleQLearning< EnvTp, ActionSelector >:
Collaboration diagram for bitrl::rl::algos::td::DoubleQLearning< EnvTp, ActionSelector >:

Public Types

typedef TDAlgoBase< EnvTp >::env_type env_type
typedef TDAlgoBase< EnvTp >::action_type action_type
typedef TDAlgoBase< EnvTp >::state_type state_type
typedef ActionSelector action_selector_type
typedef with_double_q_table_mixin< DynMat< real_t > > table_mixin_type
Public Types inherited from bitrl::rl::algos::td::TDAlgoBase< EnvTp >
typedef EnvTp env_type
 env_t
typedef env_type::action_type action_type
 action_t
typedef env_type::state_type state_type
 state_t
Public Types inherited from bitrl::rl::algos::RLSolverBase< EnvTp >
typedef EnvTp env_type

Public Member Functions

 DoubleQLearning (const DoubleQLearningConfig config, const ActionSelector &selector)
 Constructor.
virtual void actions_before_training_begins (env_type &)
 Sets both tables to zero.
virtual void actions_after_training_ends (env_type &)
 Saves the tables if the configuration gives a path.
virtual void actions_before_episode_begins (env_type &, uint_t)
virtual void actions_after_episode_ends (env_type &, uint_t episode_idx, const EpisodeInfo &)
 Lets the action selector adjust itself, for example decay its epsilon.
virtual EpisodeInfo on_training_episode (env_type &, uint_t episode_idx)
 Plays one episode and updates the tables after every step.
void save (std::string filename) const
 Writes the two tables to a CSV file, one row per state and table.
const DynMat< real_t > & q_table_1 () const noexcept
const DynMat< real_t > & q_table_2 () const noexcept
Public Member Functions inherited from bitrl::rl::algos::td::TDAlgoBase< EnvTp >
virtual ~TDAlgoBase ()=default
 Destructor.
Public Member Functions inherited from bitrl::rl::algos::RLSolverBase< EnvTp >
virtual ~RLSolverBase ()=default
 Destructor.
virtual void actions_before_training_begins (env_type &)=0
 actions_before_training_begins. Execute any actions the algorithm needs before starting the iterations
virtual void actions_after_training_ends (env_type &)=0
 actions_after_training_ends. Actions to execute after the training iterations have finisehd
virtual void actions_before_episode_begins (env_type &, uint_t)
 actions_before_training_episode
virtual void actions_after_episode_ends (env_type &, uint_t, const EpisodeInfo &)
 actions_after_training_episode
virtual EpisodeInfo on_training_episode (env_type &, uint_t)=0
 on_episode Do one on_episode of the algorithm

Additional Inherited Members

Protected Types inherited from bitrl::rl::with_double_q_table_mixin< DynMat< real_t > >
typedef uint_t index_type
typedef uint_t state_type
typedef uint_t action_type
typedef real_t value_type
Protected Member Functions inherited from bitrl::rl::algos::td::TDAlgoBase< EnvTp >
 TDAlgoBase ()=default
 DPAlgoBase.
Protected Member Functions inherited from bitrl::rl::algos::RLSolverBase< EnvTp >
 RLSolverBase ()=default
 Constructor.
Protected Member Functions inherited from bitrl::rl::with_double_q_table_mixin< DynMat< real_t > >
void initialize (const std::vector< index_type > &indices, action_type n_actions, real_t init_value)
 initialize
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
template<int index>
value_type get (const state_type &state, const action_type action) const
template<int index>
void set (const state_type &state, const action_type action, const value_type value)
template<>
with_double_q_table_mixin< DynMat< real_t > >::value_type get (const state_type &state, const action_type action) const
template<>
with_double_q_table_mixin< DynMat< real_t > >::value_type get (const state_type &state, const action_type action) const
template<>
void set (const state_type &state, const action_type action, const value_type value)
template<>
void set (const state_type &state, const action_type action, const value_type value)
Static Protected Member Functions inherited from bitrl::rl::with_double_q_table_max_action_mixin
template<typename TableTp, typename StateTp>
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.
template<typename TableTp, typename StateTp>
static uint_t max_action (const TableTp &q1_table, const StateTp &state, uint_t n_actions)
 Returns the max action by averaging the state values from the two tables.
Protected Attributes inherited from bitrl::rl::with_double_q_table_mixin< DynMat< real_t > >
DynMat< value_type > q_table_1
 q_table_1
DynMat< value_type > q_table_2
 q_table_2

Detailed Description

template<envs::discrete_world_concept EnvTp, typename ActionSelector>
class bitrl::rl::algos::td::DoubleQLearning< EnvTp, ActionSelector >

The class DoubleQLearning. Tabular double Q-learning, see van Hasselt, Double Q-learning, NIPS 2010.

Q-learning takes the value of the next state as the largest value in the same table it updates, which overestimates it. Double Q-learning keeps two tables. Every step a coin picks one of them to update; the action that is best in that table is valued with the other one. Actions are chosen with the sum of the two tables.

ActionSelector is called as selector(q_table_1, q_table_2, state) and returns an action, for example EpsilonDoubleQTableGreedyPolicy. It must also have adjust_on_episode(episode_idx).

Member Typedef Documentation

◆ action_selector_type

template<envs::discrete_world_concept EnvTp, typename ActionSelector>
typedef ActionSelector bitrl::rl::algos::td::DoubleQLearning< EnvTp, ActionSelector >::action_selector_type

◆ action_type

template<envs::discrete_world_concept EnvTp, typename ActionSelector>
typedef TDAlgoBase<EnvTp>::action_type bitrl::rl::algos::td::DoubleQLearning< EnvTp, ActionSelector >::action_type

◆ env_type

template<envs::discrete_world_concept EnvTp, typename ActionSelector>
typedef TDAlgoBase<EnvTp>::env_type bitrl::rl::algos::td::DoubleQLearning< EnvTp, ActionSelector >::env_type

◆ state_type

template<envs::discrete_world_concept EnvTp, typename ActionSelector>
typedef TDAlgoBase<EnvTp>::state_type bitrl::rl::algos::td::DoubleQLearning< EnvTp, ActionSelector >::state_type

◆ table_mixin_type

template<envs::discrete_world_concept EnvTp, typename ActionSelector>
typedef with_double_q_table_mixin<DynMat<real_t> > bitrl::rl::algos::td::DoubleQLearning< EnvTp, ActionSelector >::table_mixin_type

Constructor & Destructor Documentation

◆ DoubleQLearning()

template<envs::discrete_world_concept EnvTp, typename ActionSelector>
bitrl::rl::algos::td::DoubleQLearning< EnvTp, ActionSelector >::DoubleQLearning ( const DoubleQLearningConfig config,
const ActionSelector & selector )

Constructor.

Member Function Documentation

◆ actions_after_episode_ends()

template<envs::discrete_world_concept EnvTp, typename ActionSelector>
virtual void bitrl::rl::algos::td::DoubleQLearning< EnvTp, ActionSelector >::actions_after_episode_ends ( env_type & ,
uint_t episode_idx,
const EpisodeInfo &  )
inlinevirtual

Lets the action selector adjust itself, for example decay its epsilon.

◆ actions_after_training_ends()

template<envs::discrete_world_concept EnvTp, typename ActionSelector>
void bitrl::rl::algos::td::DoubleQLearning< EnvTp, ActionSelector >::actions_after_training_ends ( env_type & )
virtual

Saves the tables if the configuration gives a path.

◆ actions_before_episode_begins()

template<envs::discrete_world_concept EnvTp, typename ActionSelector>
virtual void bitrl::rl::algos::td::DoubleQLearning< EnvTp, ActionSelector >::actions_before_episode_begins ( env_type & ,
uint_t  )
inlinevirtual

◆ actions_before_training_begins()

template<envs::discrete_world_concept EnvTp, typename ActionSelector>
void bitrl::rl::algos::td::DoubleQLearning< EnvTp, ActionSelector >::actions_before_training_begins ( env_type & env)
virtual

Sets both tables to zero.

◆ on_training_episode()

template<envs::discrete_world_concept EnvTp, typename ActionSelector>
EpisodeInfo bitrl::rl::algos::td::DoubleQLearning< EnvTp, ActionSelector >::on_training_episode ( env_type & env,
uint_t episode_idx )
virtual

Plays one episode and updates the tables after every step.

◆ q_table_1()

template<envs::discrete_world_concept EnvTp, typename ActionSelector>
const DynMat< real_t > & bitrl::rl::algos::td::DoubleQLearning< EnvTp, ActionSelector >::q_table_1 ( ) const
inlinenoexcept

◆ q_table_2()

template<envs::discrete_world_concept EnvTp, typename ActionSelector>
const DynMat< real_t > & bitrl::rl::algos::td::DoubleQLearning< EnvTp, ActionSelector >::q_table_2 ( ) const
inlinenoexcept

◆ save()

template<envs::discrete_world_concept EnvTp, typename ActionSelector>
void bitrl::rl::algos::td::DoubleQLearning< EnvTp, ActionSelector >::save ( std::string filename) const

Writes the two tables to a CSV file, one row per state and table.


The documentation for this class was generated from the following file: