1#ifndef RL_SERIAL_AGENT_TRAINER_H
2#define RL_SERIAL_AGENT_TRAINER_H
11#include <boost/noncopyable.hpp>
39template <
typename EnvType,
typename AgentType>
128template <
typename EnvType,
typename AgentType>
137template <
typename EnvType,
typename AgentType>
141 agent_.actions_before_training_begins(env);
149template <
typename EnvType,
typename AgentType>
153 agent_.actions_before_episode_begins(env, episode_idx);
156template <
typename EnvType,
typename AgentType>
161 agent_.actions_after_episode_ends(env, episode_idx, einfo);
164template <
typename EnvType,
typename AgentType>
167 agent_.actions_after_training_ends(env);
170template <
typename EnvType,
typename AgentType>
178 auto start = std::chrono::steady_clock::now();
182 uint_t episode_counter = 0;
183 bool stop_training =
false;
188 auto episode_info =
agent_.on_training_episode(env, episode_counter);
201 if (episode_info.stop_training)
203 BITRL_LOG_INFO <<
" Stopping training at index=" << episode_counter;
207 stop_training =
true;
210 episode_counter += 1;
214 auto end = std::chrono::steady_clock::now();
215 std::chrono::duration<real_t> elapsed_seconds = end - start;
220 state.total_time = elapsed_seconds;
221 state.converged = stop_training;
bitrl's logging: the logger of bitsim, bitsim/utils/logger.h, with bitrl's messages going to the logg...
#define BITRL_LOG_INFO
Definition bitrl_log.h:36
virtual void actions_after_training_ends(env_type &)
actions_after_training_ends. Execute any actions the algorithm needs after the iterations are finishe...
Definition rl_serial_agent_trainer.h:165
virtual bitrl::utils::IterativeAlgorithmResult train(env_type &env)
train Iterate to train the agent on the given environment
Definition rl_serial_agent_trainer.h:172
agent_type & agent_
agent_
Definition rl_serial_agent_trainer.h:114
const std::vector< real_t > & episodes_total_rewards() const noexcept
episodes_total_rewards
Definition rl_serial_agent_trainer.h:88
RLSerialAgentTrainer(const RLSerialTrainerConfig &config, agent_type &agent)
RLSerialAgentTrainer.
Definition rl_serial_agent_trainer.h:129
const std::vector< uint_t > & n_itrs_per_episode() const noexcept
n_itrs_per_episode
Definition rl_serial_agent_trainer.h:97
virtual void actions_before_training_begins(env_type &)
actions_before_training_begins. Execute any actions the algorithm needs before starting the episode
Definition rl_serial_agent_trainer.h:138
bitrl::utils::IterativeAlgorithmController itr_ctrl_
itr_ctrl_ Handles the iteration over the episodes
Definition rl_serial_agent_trainer.h:109
AgentType agent_type
Definition rl_serial_agent_trainer.h:44
virtual void actions_after_episode_ends(env_type &, uint_t, const EpisodeInfo &einfo)
actions_after_episode_ends. Execute any actions the algorithm needs after ending the episode
Definition rl_serial_agent_trainer.h:157
std::vector< real_t > total_reward_per_episode_
total_reward_per_episode_
Definition rl_serial_agent_trainer.h:119
EnvType env_type
Definition rl_serial_agent_trainer.h:43
std::vector< uint_t > n_itrs_per_episode_
n_itrs_per_episode_ Holds the number of iterations performed per training episode
Definition rl_serial_agent_trainer.h:125
uint_t output_msg_frequency_
Definition rl_serial_agent_trainer.h:103
virtual void actions_before_episode_begins(env_type &, uint_t)
actions_before_episode_begins. Execute any actions the algorithm needs before starting the episode
Definition rl_serial_agent_trainer.h:150
Controller for iterative algorithms.
Definition iterative_algorithm_controller.h:17
Definition dummy_agent.h:9
Various utilities used when working with RL problems.
Definition bitrl_log.h:25
const real_t TOLERANCE
Tolerance used around the library.
Definition bitsim_consts.h:26
const uint_t INVALID_ID
Invalid id.
Definition bitsim_consts.h:16
std::size_t uint_t
uint_t
Definition bitsim_types.h:40
double real_t
real_t
Definition bitsim_types.h:20
The EpisodeInfo struct.
Definition episode_info.h:21
The RLSerialTrainerConfig struct. Configuration struct for the serial RL agent trainer.
Definition rl_serial_agent_trainer.h:29
uint_t n_episodes
Definition rl_serial_agent_trainer.h:31
uint_t output_msg_frequency
Definition rl_serial_agent_trainer.h:30
real_t tolerance
Definition rl_serial_agent_trainer.h:32
The IterativeAlgorithmResult struct. Helper struct to assemble the result of an iterative algorithm.
Definition iterative_algorithm_result.h:19