1#ifndef POLICY_IMPROVEMENT_H
2#define POLICY_IMPROVEMENT_H
22template <
typename EnvType,
typename PolicyType>
112template <
typename EnvType,
typename PolicyType>
121template <
typename EnvType,
typename PolicyType>
126 auto start = std::chrono::steady_clock::now();
128 std::map<std::string, std::any> options;
130 for (
uint_t s = 0; s < env.n_states(); ++s)
135 options.insert_or_assign(
"state", s);
136 options.insert_or_assign(
"state_actions", std::any(state_actions));
140 auto end = std::chrono::steady_clock::now();
141 std::chrono::duration<real_t> elapsed_seconds = end - start;
144 info.episode_index = episode_idx;
145 info.episode_iterations = env.n_states();
146 info.total_time = elapsed_seconds;
DPSolverBase()=default
DPAlgoBase.
RLSolverBase< EnvType >::env_type env_type
The environment type the solver is using.
Definition dp_algo_base.h:26
bitrl::rl::policies::StochasticAdaptorPolicy< policy_type > policy_adaptor_
How to adapt the policy.
Definition policy_improvement.h:109
DynVec< real_t > v_
v_
Definition policy_improvement.h:99
policy_type & policy_
policy_
Definition policy_improvement.h:104
virtual void actions_before_training_begins(env_type &) override
actions_before_training_begins. Execute any actions the algorithm needs before starting the iteration...
Definition policy_improvement.h:46
virtual void actions_after_training_ends(env_type &) override
actions_after_training_ends. Actions to execute after the training iterations have finisehd
Definition policy_improvement.h:52
PolicyType policy_type
policy_type
Definition policy_improvement.h:34
const policy_type & policy() const
Definition policy_improvement.h:76
virtual EpisodeInfo on_training_episode(env_type &env, uint_t episode_idx) override
on_episode Do one on_episode of the algorithm
Definition policy_improvement.h:122
PolicyImprovement(uint_t action_space_size, real_t gamma, const DynVec< real_t > &val_func, policy_type &policy)
IterativePolicyEval.
Definition policy_improvement.h:113
DPSolverBase< EnvType >::env_type env_type
env_t
Definition policy_improvement.h:29
virtual void actions_before_episode_begins(env_type &, uint_t) override
actions_before_training_episode
Definition policy_improvement.h:57
real_t gamma_
gamma_
Definition policy_improvement.h:94
void set_value_function(const DynVec< real_t > &v)
set_value_function
Definition policy_improvement.h:88
policy_type & policy()
policy
Definition policy_improvement.h:82
virtual void actions_after_episode_ends(env_type &, uint_t, const EpisodeInfo &) override
actions_after_training_episode
Definition policy_improvement.h:62
The StochasticAdaptorPolicy class.
Definition policy_stochastic_adaptor.h:29
Definition dp_algo_base.h:15
auto state_actions_from_v(const WorldTp &env, const DynVec< real_t > &v, real_t gamma, uint_t state) -> DynVec< real_t >
Given the state index returns the list of actions under the provided value functions.
Definition utils.h:24
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
Eigen::RowVectorX< T > DynVec
Dynamically sized row vector.
Definition bitsim_types.h:101
The EpisodeInfo struct.
Definition episode_info.h:21