Gaussian action distribution for unbounded action spaces. More...
#include <LibtorchActionDistribution.h>
Public Member Functions | |
| LibtorchGaussianActionDistribution (const std::string &name, unsigned int num_inputs, unsigned int num_outputs, torch::DeviceType device_type=torch::kCPU, torch::ScalarType scalar_type=torch::kDouble, bool build_on_construct=true, const std::vector< Real > &output_scaling_factors={}, bool state_independent_std=true) | |
| Build the Gaussian action distribution used for unbounded controls. | |
| virtual void | initialize (c10::optional< at::Generator > generator=c10::nullopt) override |
| Initialize the trainable Gaussian distribution parameters. | |
| virtual void | reset (const torch::Tensor &input) override |
| Refresh the Gaussian distribution parameters from the latest actor features. | |
| virtual torch::Tensor | sample (c10::optional< at::Generator > generator=c10::nullopt) const override |
| Draw a stochastic Gaussian action sample in physical units. | |
| virtual torch::Tensor | deterministicAction () const override |
| Return the Gaussian mean action used for deterministic evaluation. | |
| virtual torch::Tensor | logProbability (const torch::Tensor &action) const override |
| Evaluate the log-probability of an action under the current Gaussian distribution. | |
| virtual torch::Tensor | entropy () const override |
| Compute the entropy of the current Gaussian distribution. | |
| virtual bool | isBounded () const override |
| Return false because the Gaussian distribution is unbounded. | |
| bool | stateIndependentStd () const |
| Return whether the Gaussian standard deviation ignores the current actor features. | |
| torch::nn::Linear & | meanModule () |
| Return the Gaussian mean head. | |
| const torch::nn::Linear & | meanModule () const |
| Return the Gaussian mean head. | |
| torch::nn::Linear & | stdModule () |
| Return the state-dependent Gaussian standard-deviation head. | |
| const torch::nn::Linear & | stdModule () const |
| Return the state-dependent Gaussian standard-deviation head. | |
| torch::Tensor & | logStd () |
| Return the state-independent Gaussian log-standard-deviation parameter. | |
| const torch::Tensor & | logStd () const |
| Return the state-independent Gaussian log-standard-deviation parameter. | |
| const torch::Tensor & | stdTensor () const |
| Return the cached Gaussian standard-deviation tensor. | |
| void | synchronizeScalingFactorsFromBuffer () |
| Sync cached scaling metadata from the registered buffers after loading state. | |
Protected Member Functions | |
| torch::Tensor | prepareFeatures (const torch::Tensor &input) const |
| Convert actor features to the configured device and scalar type. | |
| torch::Tensor | prepareAction (const torch::Tensor &action) const |
| Convert actions to the configured device and scalar type. | |
| const torch::Tensor & | actionScaleTensor () const |
| Return the registered tensor that stores per-action scaling factors. | |
Protected Attributes | |
| const std::string | _name |
| Module name used for registration and serialization. | |
| const unsigned int | _num_inputs |
| Number of actor features feeding this distribution. | |
| const unsigned int | _num_outputs |
| Number of action dimensions produced by this distribution. | |
| const torch::DeviceType | _device_type |
| Torch device used by this distribution. | |
| const torch::ScalarType | _data_type |
| Torch scalar type used by this distribution. | |
| std::vector< Real > | _output_scaling_factors |
| Cached per-action scaling factors applied in physical units. | |
| torch::Tensor | _action_scale_tensor |
| Registered libtorch buffer holding the per-action scaling factors. | |
Private Member Functions | |
| void | constructDistribution () |
| Build and register the Gaussian distribution heads. | |
Private Attributes | |
| const bool | _state_independent_std |
| Whether the Gaussian std ignores the current actor features. | |
| torch::nn::Linear | _mean_module {nullptr} |
| Linear head that produces the Gaussian action mean. | |
| torch::nn::Linear | _std_module {nullptr} |
| Linear head that produces state-dependent Gaussian log-std inputs. | |
| torch::Tensor | _log_std_parameter |
| Trainable state-independent Gaussian log-std. | |
| torch::Tensor | _mean |
| Cached Gaussian action mean from the latest reset. | |
| torch::Tensor | _std_tensor |
| Cached Gaussian action standard deviation from the latest reset. | |
| torch::Tensor | _log_std_tensor |
| Cached Gaussian action log standard deviation from the latest reset. | |
Gaussian action distribution for unbounded action spaces.
Definition at line 126 of file LibtorchActionDistribution.h.
| Moose::LibtorchGaussianActionDistribution::LibtorchGaussianActionDistribution | ( | const std::string & | name, |
| unsigned int | num_inputs, | ||
| unsigned int | num_outputs, | ||
| torch::DeviceType | device_type = torch::kCPU, |
||
| torch::ScalarType | scalar_type = torch::kDouble, |
||
| bool | build_on_construct = true, |
||
| const std::vector< Real > & | output_scaling_factors = {}, |
||
| bool | state_independent_std = true |
||
| ) |
Build the Gaussian action distribution used for unbounded controls.
| name | Module name used for registration and serialization. |
| num_inputs | Number of actor features feeding the distribution. |
| num_outputs | Number of action dimensions produced by the distribution. |
| device_type | Torch device used by the module. |
| scalar_type | Torch scalar type used by the module. |
| build_on_construct | Whether to build the torch modules right away. |
| output_scaling_factors | Optional per-action scaling applied in physical units. |
| state_independent_std | Whether the learned std should ignore the current state. |
Definition at line 102 of file LibtorchActionDistribution.C.
|
inlineprotectedinherited |
Return the registered tensor that stores per-action scaling factors.
Definition at line 104 of file LibtorchActionDistribution.h.
Referenced by deterministicAction(), Moose::LibtorchBetaActionDistribution::deterministicAction(), entropy(), Moose::LibtorchBetaActionDistribution::entropy(), logProbability(), Moose::LibtorchBetaActionDistribution::logProbability(), sample(), and Moose::LibtorchBetaActionDistribution::sample().
|
private |
Build and register the Gaussian distribution heads.
Definition at line 120 of file LibtorchActionDistribution.C.
Referenced by LibtorchGaussianActionDistribution().
|
overridevirtual |
Return the Gaussian mean action used for deterministic evaluation.
Implements Moose::LibtorchActionDistribution.
Definition at line 182 of file LibtorchActionDistribution.C.
|
overridevirtual |
Compute the entropy of the current Gaussian distribution.
Implements Moose::LibtorchActionDistribution.
Definition at line 201 of file LibtorchActionDistribution.C.
|
overridevirtual |
Initialize the trainable Gaussian distribution parameters.
| generator | Optional random-number generator used for reproducible initialization. |
Implements Moose::LibtorchActionDistribution.
Definition at line 140 of file LibtorchActionDistribution.C.
|
inlineoverridevirtual |
Return false because the Gaussian distribution is unbounded.
Implements Moose::LibtorchActionDistribution.
Definition at line 187 of file LibtorchActionDistribution.h.
|
overridevirtual |
Evaluate the log-probability of an action under the current Gaussian distribution.
| action | Action tensor in physical units. |
Implements Moose::LibtorchActionDistribution.
Definition at line 188 of file LibtorchActionDistribution.C.
|
inline |
Return the state-independent Gaussian log-standard-deviation parameter.
Definition at line 217 of file LibtorchActionDistribution.h.
|
inline |
Return the state-independent Gaussian log-standard-deviation parameter.
Definition at line 222 of file LibtorchActionDistribution.h.
|
inline |
|
inline |
|
protectedinherited |
Convert actions to the configured device and scalar type.
| action | Raw action tensor. |
Definition at line 92 of file LibtorchActionDistribution.C.
Referenced by logProbability(), and Moose::LibtorchBetaActionDistribution::logProbability().
|
protectedinherited |
Convert actor features to the configured device and scalar type.
| input | Raw actor feature tensor. |
Definition at line 81 of file LibtorchActionDistribution.C.
Referenced by reset(), and Moose::LibtorchBetaActionDistribution::reset().
|
overridevirtual |
Refresh the Gaussian distribution parameters from the latest actor features.
| input | Feature tensor coming from the actor body. |
Implements Moose::LibtorchActionDistribution.
Definition at line 156 of file LibtorchActionDistribution.C.
|
overridevirtual |
Draw a stochastic Gaussian action sample in physical units.
| generator | Optional random-number generator used for sampling. |
Implements Moose::LibtorchActionDistribution.
Definition at line 176 of file LibtorchActionDistribution.C.
|
inline |
Return whether the Gaussian standard deviation ignores the current actor features.
Definition at line 192 of file LibtorchActionDistribution.h.
|
inline |
Return the state-dependent Gaussian standard-deviation head.
Definition at line 207 of file LibtorchActionDistribution.h.
|
inline |
Return the state-dependent Gaussian standard-deviation head.
Definition at line 212 of file LibtorchActionDistribution.h.
|
inline |
Return the cached Gaussian standard-deviation tensor.
Definition at line 227 of file LibtorchActionDistribution.h.
|
inherited |
Sync cached scaling metadata from the registered buffers after loading state.
Definition at line 73 of file LibtorchActionDistribution.C.
Referenced by Moose::loadLibtorchActorNeuralNetState().
|
protectedinherited |
Registered libtorch buffer holding the per-action scaling factors.
Definition at line 120 of file LibtorchActionDistribution.h.
Referenced by Moose::LibtorchActionDistribution::actionScaleTensor(), Moose::LibtorchActionDistribution::LibtorchActionDistribution(), and Moose::LibtorchActionDistribution::synchronizeScalingFactorsFromBuffer().
|
protectedinherited |
Torch scalar type used by this distribution.
Definition at line 115 of file LibtorchActionDistribution.h.
Referenced by constructDistribution(), Moose::LibtorchBetaActionDistribution::constructDistribution(), Moose::LibtorchActionDistribution::LibtorchActionDistribution(), Moose::LibtorchBetaActionDistribution::LibtorchBetaActionDistribution(), Moose::LibtorchActionDistribution::prepareAction(), and Moose::LibtorchActionDistribution::prepareFeatures().
|
protectedinherited |
Torch device used by this distribution.
Definition at line 113 of file LibtorchActionDistribution.h.
Referenced by constructDistribution(), Moose::LibtorchBetaActionDistribution::constructDistribution(), Moose::LibtorchActionDistribution::LibtorchActionDistribution(), Moose::LibtorchBetaActionDistribution::LibtorchBetaActionDistribution(), Moose::LibtorchActionDistribution::prepareAction(), and Moose::LibtorchActionDistribution::prepareFeatures().
|
private |
Trainable state-independent Gaussian log-std.
Definition at line 242 of file LibtorchActionDistribution.h.
Referenced by constructDistribution(), initialize(), logStd(), logStd(), and reset().
|
private |
Cached Gaussian action log standard deviation from the latest reset.
Definition at line 248 of file LibtorchActionDistribution.h.
Referenced by entropy(), logProbability(), and reset().
|
private |
Cached Gaussian action mean from the latest reset.
Definition at line 244 of file LibtorchActionDistribution.h.
Referenced by deterministicAction(), logProbability(), reset(), and sample().
|
private |
Linear head that produces the Gaussian action mean.
Definition at line 238 of file LibtorchActionDistribution.h.
Referenced by constructDistribution(), initialize(), meanModule(), meanModule(), and reset().
|
protectedinherited |
Module name used for registration and serialization.
Definition at line 107 of file LibtorchActionDistribution.h.
|
protectedinherited |
Number of actor features feeding this distribution.
Definition at line 109 of file LibtorchActionDistribution.h.
Referenced by constructDistribution(), and Moose::LibtorchBetaActionDistribution::constructDistribution().
|
protectedinherited |
Number of action dimensions produced by this distribution.
Definition at line 111 of file LibtorchActionDistribution.h.
Referenced by constructDistribution(), Moose::LibtorchBetaActionDistribution::constructDistribution(), and Moose::LibtorchBetaActionDistribution::LibtorchBetaActionDistribution().
|
protectedinherited |
Cached per-action scaling factors applied in physical units.
Definition at line 117 of file LibtorchActionDistribution.h.
Referenced by Moose::LibtorchActionDistribution::LibtorchActionDistribution(), and Moose::LibtorchActionDistribution::synchronizeScalingFactorsFromBuffer().
|
private |
Whether the Gaussian std ignores the current actor features.
Definition at line 236 of file LibtorchActionDistribution.h.
Referenced by constructDistribution(), initialize(), reset(), and stateIndependentStd().
|
private |
Linear head that produces state-dependent Gaussian log-std inputs.
Definition at line 240 of file LibtorchActionDistribution.h.
Referenced by constructDistribution(), initialize(), reset(), stdModule(), and stdModule().
|
private |
Cached Gaussian action standard deviation from the latest reset.
Definition at line 246 of file LibtorchActionDistribution.h.
Referenced by logProbability(), reset(), sample(), and stdTensor().