Builds fixed-horizon RL trajectories from raw per-sample reporter sequences. More...
#include <LibtorchRLTrajectoryAssembler.h>
Public Types | |
| using | ReporterData = std::vector< const std::vector< std::vector< Real > > * > |
| Raw reporter data for one rollout quantity, indexed as [component][sample][raw time]. | |
Public Member Functions | |
| LibtorchRLTrajectoryAssembler (unsigned int input_timesteps, unsigned int timestep_window, bool shift_outputs, bool average_reward_over_timestep_window) | |
| Build the trajectory assembler. | |
| std::vector< LibtorchRLTrajectoryBuffer::Trajectory > | assemble (const ReporterData &observations, const ReporterData &actions, const ReporterData &log_probabilities, const std::vector< std::vector< Real > > &rewards) const |
| Assemble one trajectory per sample that holds at least one transition. | |
| unsigned int | numTransitions (std::size_t raw_sequence_size) const |
| Count the transitions available in a raw reporter sequence. | |
Private Member Functions | |
| std::vector< Real > | downsample (const std::vector< Real > &sample, unsigned int offset, unsigned int num_entries) const |
| Take every timestep_window-th entry of a raw reporter sequence. | |
| std::vector< Real > | windowAverage (const std::vector< Real > &sample, unsigned int num_entries) const |
| Average a raw reporter sequence over consecutive timestep windows after the initial entry. | |
Static Private Member Functions | |
| static void | checkSampleCount (const ReporterData &data, const std::string &quantity, std::size_t num_samples) |
| Check that every component of a rollout quantity holds one sequence per sample. | |
Private Attributes | |
| const unsigned int | _timestep_window |
| Raw reporter entries per transition. | |
| const bool | _shift_outputs |
| Whether actions and log probabilities are read one raw entry after the observation. | |
| const bool | _average_reward_over_timestep_window |
| Whether rewards are averaged over each window instead of sampled at its end. | |
| const LibtorchObservationHistoryHelper | _observation_history |
| Observation history stacking helper. | |
Builds fixed-horizon RL trajectories from raw per-sample reporter sequences.
Raw index 0 of every sequence holds the initial value and raw index n holds the value at the end of time step n. Transition k uses the observation at raw index k * W, the action and log probability at raw index k * W (+ 1 when outputs are shifted), and the reward at raw index (k + 1) * W, or the mean over raw indices k * W + 1 through (k + 1) * W. Here W is the timestep window. Observation history lags also span W raw entries.
Definition at line 29 of file LibtorchRLTrajectoryAssembler.h.
| using LibtorchRLTrajectoryAssembler::ReporterData = std::vector<const std::vector<std::vector<Real> > *> |
Raw reporter data for one rollout quantity, indexed as [component][sample][raw time].
Definition at line 33 of file LibtorchRLTrajectoryAssembler.h.
| LibtorchRLTrajectoryAssembler::LibtorchRLTrajectoryAssembler | ( | unsigned int | input_timesteps, |
| unsigned int | timestep_window, | ||
| bool | shift_outputs, | ||
| bool | average_reward_over_timestep_window | ||
| ) |
Build the trajectory assembler.
| input_timesteps | Number of stacked observation time levels. |
| timestep_window | Raw reporter entries per transition. |
| shift_outputs | Whether actions and log probabilities are read one raw entry later. |
| average_reward_over_timestep_window | Whether rewards are averaged over each window. |
Definition at line 20 of file LibtorchRLTrajectoryAssembler.C.
| std::vector< LibtorchRLTrajectoryBuffer::Trajectory > LibtorchRLTrajectoryAssembler::assemble | ( | const ReporterData & | observations, |
| const ReporterData & | actions, | ||
| const ReporterData & | log_probabilities, | ||
| const std::vector< std::vector< Real > > & | rewards | ||
| ) | const |
Assemble one trajectory per sample that holds at least one transition.
| observations | Observation reporter data. |
| actions | Action reporter data. |
| log_probabilities | Log-probability reporter data, one entry per action. |
| rewards | Reward reporter data indexed as [sample][raw time]. |
Definition at line 35 of file LibtorchRLTrajectoryAssembler.C.
Referenced by LibtorchDRLControlTrainer::collectTrajectoriesFromReporters().
|
staticprivate |
Check that every component of a rollout quantity holds one sequence per sample.
| data | Reporter data to check. |
| quantity | Name of the rollout quantity used in the error message. |
| num_samples | Number of samples held by the reward reporter. |
Definition at line 119 of file LibtorchRLTrajectoryAssembler.C.
Referenced by assemble().
|
private |
Take every timestep_window-th entry of a raw reporter sequence.
| sample | Raw reporter sequence. |
| offset | Raw index of the first entry. |
| num_entries | Number of entries to extract. |
Definition at line 137 of file LibtorchRLTrajectoryAssembler.C.
Referenced by assemble().
| unsigned int LibtorchRLTrajectoryAssembler::numTransitions | ( | std::size_t | raw_sequence_size | ) | const |
Count the transitions available in a raw reporter sequence.
| raw_sequence_size | Number of raw time entries in the reporter sequence. |
Definition at line 112 of file LibtorchRLTrajectoryAssembler.C.
Referenced by assemble().
|
private |
Average a raw reporter sequence over consecutive timestep windows after the initial entry.
| sample | Raw reporter sequence. |
| num_entries | Number of windows to average. |
Definition at line 157 of file LibtorchRLTrajectoryAssembler.C.
Referenced by assemble().
|
private |
Whether rewards are averaged over each window instead of sampled at its end.
Definition at line 102 of file LibtorchRLTrajectoryAssembler.h.
Referenced by assemble().
|
private |
Observation history stacking helper.
Definition at line 104 of file LibtorchRLTrajectoryAssembler.h.
Referenced by assemble().
|
private |
Whether actions and log probabilities are read one raw entry after the observation.
Definition at line 100 of file LibtorchRLTrajectoryAssembler.h.
Referenced by assemble().
|
private |
Raw reporter entries per transition.
Definition at line 98 of file LibtorchRLTrajectoryAssembler.h.
Referenced by assemble(), downsample(), LibtorchRLTrajectoryAssembler(), numTransitions(), and windowAverage().