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

Tabular expected SARSA, see Sutton and Barto, Reinforcement Learning: An Introduction, section 6.6. More...

#include <expected_sarsa.h>

Inheritance diagram for bitrl::rl::algos::td::ExpectedSarsaSolver< EnvType, PolicyType >:
Collaboration diagram for bitrl::rl::algos::td::ExpectedSarsaSolver< EnvType, PolicyType >:

Public Types

typedef TDAlgoBase< EnvType >::env_type env_type
typedef TDAlgoBase< EnvType >::action_type action_type
typedef TDAlgoBase< EnvType >::state_type state_type
typedef PolicyType policy_type
Public Types inherited from bitrl::rl::algos::td::TDAlgoBase< EnvType >
typedef EnvType 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< EnvType >
typedef EnvType env_type

Public Member Functions

 ExpectedSarsaSolver (const ExpectedSarsaConfig &config, const PolicyType &policy)
 Constructor.
virtual void actions_before_training_begins (env_type &)
 Sets every entry of the table to zero.
virtual void actions_after_training_ends (env_type &)
 Saves the table if the configuration gives a path.
virtual void actions_before_episode_begins (env_type &, uint_t)
 actions_before_training_episode
virtual void actions_after_episode_ends (env_type &, uint_t episode_idx, const EpisodeInfo &)
 Lets the policy adjust itself, for example decay its epsilon.
virtual EpisodeInfo on_training_episode (env_type &, uint_t episode_idx)
 Plays one episode and updates the table after every step.
void save (const std::string &filename) const
 Writes the table to a CSV file, one row per state.
bitrl::rl::policies::MaxTabularPolicy build_policy () const
 The greedy policy of the table.
const DynMat< real_t > & q_table () const noexcept
 The value of every state and action.
real_t expected_value (const state_type &state) const
 The value the policy expects at the given state: every action weighed with the probability the policy takes it.
Public Member Functions inherited from bitrl::rl::algos::td::TDAlgoBase< EnvType >
virtual ~TDAlgoBase ()=default
 Destructor.
Public Member Functions inherited from bitrl::rl::algos::RLSolverBase< EnvType >
virtual ~RLSolverBase ()=default
 Destructor.

Additional Inherited Members

Protected Member Functions inherited from bitrl::rl::algos::td::TDAlgoBase< EnvType >
 TDAlgoBase ()=default
 DPAlgoBase.
Protected Member Functions inherited from bitrl::rl::algos::RLSolverBase< EnvType >
 RLSolverBase ()=default
 Constructor.

Detailed Description

template<envs::discrete_world_concept EnvType, epsilon_greedy_policy_concept PolicyType>
class bitrl::rl::algos::td::ExpectedSarsaSolver< EnvType, PolicyType >

Tabular expected SARSA, see Sutton and Barto, Reinforcement Learning: An Introduction, section 6.6.

SARSA moves Q(s, a) towards r + gamma Q(s', a'), with a' the action its policy takes next. Expected SARSA uses the value the policy expects at s' instead,

r + gamma sum_a pi(a | s') Q(s', a),

which does not depend on which action it happens to take, so its updates vary less. For an epsilon-greedy policy over n actions, pi(a | s') is epsilon / n for every action, plus 1 - epsilon for the greedy one. After a step that ends the episode the target is the reward alone.

Member Typedef Documentation

◆ action_type

template<envs::discrete_world_concept EnvType, epsilon_greedy_policy_concept PolicyType>
typedef TDAlgoBase<EnvType>::action_type bitrl::rl::algos::td::ExpectedSarsaSolver< EnvType, PolicyType >::action_type

◆ env_type

template<envs::discrete_world_concept EnvType, epsilon_greedy_policy_concept PolicyType>
typedef TDAlgoBase<EnvType>::env_type bitrl::rl::algos::td::ExpectedSarsaSolver< EnvType, PolicyType >::env_type

◆ policy_type

template<envs::discrete_world_concept EnvType, epsilon_greedy_policy_concept PolicyType>
typedef PolicyType bitrl::rl::algos::td::ExpectedSarsaSolver< EnvType, PolicyType >::policy_type

◆ state_type

template<envs::discrete_world_concept EnvType, epsilon_greedy_policy_concept PolicyType>
typedef TDAlgoBase<EnvType>::state_type bitrl::rl::algos::td::ExpectedSarsaSolver< EnvType, PolicyType >::state_type

Constructor & Destructor Documentation

◆ ExpectedSarsaSolver()

template<envs::discrete_world_concept EnvType, epsilon_greedy_policy_concept PolicyType>
bitrl::rl::algos::td::ExpectedSarsaSolver< EnvType, PolicyType >::ExpectedSarsaSolver ( const ExpectedSarsaConfig & config,
const PolicyType & policy )

Constructor.

Member Function Documentation

◆ actions_after_episode_ends()

template<envs::discrete_world_concept EnvType, epsilon_greedy_policy_concept PolicyType>
virtual void bitrl::rl::algos::td::ExpectedSarsaSolver< EnvType, PolicyType >::actions_after_episode_ends ( env_type & ,
uint_t episode_idx,
const EpisodeInfo &  )
inlinevirtual

Lets the policy adjust itself, for example decay its epsilon.

Reimplemented from bitrl::rl::algos::RLSolverBase< EnvType >.

◆ actions_after_training_ends()

template<envs::discrete_world_concept EnvType, epsilon_greedy_policy_concept PolicyType>
void bitrl::rl::algos::td::ExpectedSarsaSolver< EnvType, PolicyType >::actions_after_training_ends ( env_type & )
virtual

Saves the table if the configuration gives a path.

Implements bitrl::rl::algos::RLSolverBase< EnvType >.

◆ actions_before_episode_begins()

template<envs::discrete_world_concept EnvType, epsilon_greedy_policy_concept PolicyType>
virtual void bitrl::rl::algos::td::ExpectedSarsaSolver< EnvType, PolicyType >::actions_before_episode_begins ( env_type & ,
uint_t  )
inlinevirtual

actions_before_training_episode

Reimplemented from bitrl::rl::algos::RLSolverBase< EnvType >.

◆ actions_before_training_begins()

template<envs::discrete_world_concept EnvType, epsilon_greedy_policy_concept PolicyType>
void bitrl::rl::algos::td::ExpectedSarsaSolver< EnvType, PolicyType >::actions_before_training_begins ( env_type & env)
virtual

Sets every entry of the table to zero.

Implements bitrl::rl::algos::RLSolverBase< EnvType >.

◆ build_policy()

template<envs::discrete_world_concept EnvType, epsilon_greedy_policy_concept PolicyType>
bitrl::rl::policies::MaxTabularPolicy bitrl::rl::algos::td::ExpectedSarsaSolver< EnvType, PolicyType >::build_policy ( ) const

The greedy policy of the table.

◆ expected_value()

template<envs::discrete_world_concept EnvType, epsilon_greedy_policy_concept PolicyType>
real_t bitrl::rl::algos::td::ExpectedSarsaSolver< EnvType, PolicyType >::expected_value ( const state_type & state) const

The value the policy expects at the given state: every action weighed with the probability the policy takes it.

◆ on_training_episode()

template<envs::discrete_world_concept EnvType, epsilon_greedy_policy_concept PolicyType>
EpisodeInfo bitrl::rl::algos::td::ExpectedSarsaSolver< EnvType, PolicyType >::on_training_episode ( env_type & env,
uint_t episode_idx )
virtual

Plays one episode and updates the table after every step.

Implements bitrl::rl::algos::RLSolverBase< EnvType >.

◆ q_table()

template<envs::discrete_world_concept EnvType, epsilon_greedy_policy_concept PolicyType>
const DynMat< real_t > & bitrl::rl::algos::td::ExpectedSarsaSolver< EnvType, PolicyType >::q_table ( ) const
inlinenoexcept

The value of every state and action.

◆ save()

template<envs::discrete_world_concept EnvType, epsilon_greedy_policy_concept PolicyType>
void bitrl::rl::algos::td::ExpectedSarsaSolver< EnvType, PolicyType >::save ( const std::string & filename) const

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


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