Shared observation history stacking and factor-expansion logic for libtorch-based controls and trainers. More...
#include <LibtorchObservationHistoryHelper.h>
Public Member Functions | |
| LibtorchObservationHistoryHelper (unsigned int input_timesteps) | |
| Build an observation-history helper for libtorch inputs. | |
| unsigned int | inputTimesteps () const |
| Return the number of timesteps stacked into each flattened input. | |
| void | initializeHistory (const std::vector< Real > &observation, std::vector< std::vector< Real > > &old_observations) const |
| Fill the history buffer with copies of the current observation. | |
| void | advanceHistory (const std::vector< Real > &observation, std::vector< std::vector< Real > > &old_observations) const |
| Advance the history buffer by inserting the latest observation. | |
| std::vector< Real > | expandObservationFactors (const std::vector< Real > &observation_factors) const |
| Repeat per-observation-entry factors across all stacked timesteps. | |
| std::vector< Real > | stackCurrentObservation (const std::vector< Real > &observation, const std::vector< std::vector< Real > > &old_observations) const |
| Flatten the current observation together with its stored history. | |
| std::vector< Real > | stackTrajectoryObservation (const std::vector< std::vector< Real > > &component_trajectories, unsigned int time_index) const |
| Flatten one time slice of observation-component trajectories with causal history. | |
Private Member Functions | |
| void | validateTrajectoryShape (const std::vector< std::vector< Real > > &component_trajectories) const |
| Check that all observation-component trajectories have a consistent shape. | |
Private Attributes | |
| const unsigned int | _input_timesteps |
| Number of timesteps stacked into each flattened observation. | |
Shared observation history stacking and factor-expansion logic for libtorch-based controls and trainers.
Definition at line 22 of file LibtorchObservationHistoryHelper.h.
| LibtorchObservationHistoryHelper::LibtorchObservationHistoryHelper | ( | unsigned int | input_timesteps | ) |
Build an observation-history helper for libtorch inputs.
| input_timesteps | Number of timesteps to stack into each flattened input. |
Definition at line 19 of file LibtorchObservationHistoryHelper.C.
| void LibtorchObservationHistoryHelper::advanceHistory | ( | const std::vector< Real > & | observation, |
| std::vector< std::vector< Real > > & | old_observations | ||
| ) | const |
Advance the history buffer by inserting the latest observation.
| observation | Current observation. |
| old_observations | History buffer ordered from newest to oldest. |
Definition at line 48 of file LibtorchObservationHistoryHelper.C.
Referenced by LibtorchNeuralNetControl::execute().
| std::vector< Real > LibtorchObservationHistoryHelper::expandObservationFactors | ( | const std::vector< Real > & | observation_factors | ) | const |
Repeat per-observation-entry factors across all stacked timesteps.
| observation_factors | Per-entry factors for one observation vector. |
Definition at line 59 of file LibtorchObservationHistoryHelper.C.
Referenced by LibtorchNeuralNetControl::loadControlNeuralNetFromFile(), and LibtorchNeuralNetControl::prepareInputTensor().
| void LibtorchObservationHistoryHelper::initializeHistory | ( | const std::vector< Real > & | observation, |
| std::vector< std::vector< Real > > & | old_observations | ||
| ) | const |
Fill the history buffer with copies of the current observation.
| observation | Current observation. |
| old_observations | History buffer that stores previous observations. |
Definition at line 41 of file LibtorchObservationHistoryHelper.C.
Referenced by LibtorchNeuralNetControl::execute().
|
inline |
Return the number of timesteps stacked into each flattened input.
Definition at line 34 of file LibtorchObservationHistoryHelper.h.
| std::vector< Real > LibtorchObservationHistoryHelper::stackCurrentObservation | ( | const std::vector< Real > & | observation, |
| const std::vector< std::vector< Real > > & | old_observations | ||
| ) | const |
Flatten the current observation together with its stored history.
| observation | Current observation. |
| old_observations | History buffer ordered from newest to oldest. |
Definition at line 78 of file LibtorchObservationHistoryHelper.C.
Referenced by LibtorchNeuralNetControl::prepareInputTensor().
| std::vector< Real > LibtorchObservationHistoryHelper::stackTrajectoryObservation | ( | const std::vector< std::vector< Real > > & | component_trajectories, |
| unsigned int | time_index | ||
| ) | const |
Flatten one time slice of observation-component trajectories with causal history.
This uses [component][time] because the trainer receives reporter data one observation component at a time, so keeping that layout avoids building an extra transposed [time][component] container before stacking.
| component_trajectories | Observation trajectories indexed as [component][time]. |
| time_index | Time index to stack. |
Definition at line 107 of file LibtorchObservationHistoryHelper.C.
|
private |
Check that all observation-component trajectories have a consistent shape.
Definition at line 28 of file LibtorchObservationHistoryHelper.C.
Referenced by stackTrajectoryObservation().
|
private |
Number of timesteps stacked into each flattened observation.
Definition at line 86 of file LibtorchObservationHistoryHelper.h.
Referenced by expandObservationFactors(), initializeHistory(), inputTimesteps(), LibtorchObservationHistoryHelper(), stackCurrentObservation(), and stackTrajectoryObservation().