Beta action distribution for bounded action spaces. More...
#include <LibtorchActionDistribution.h>
Public Member Functions | |
| LibtorchBetaActionDistribution (const std::string &name, unsigned int num_inputs, unsigned int num_outputs, const std::vector< Real > &minimum_values, const std::vector< Real > &maximum_values, torch::DeviceType device_type=torch::kCPU, torch::ScalarType scalar_type=torch::kDouble, bool build_on_construct=true, const std::vector< Real > &output_scaling_factors={}) | |
| Build the Beta action distribution used for bounded controls. | |
| virtual void | initialize (c10::optional< at::Generator > generator=c10::nullopt) override |
| Initialize the trainable Beta distribution parameters. | |
| virtual void | reset (const torch::Tensor &input) override |
| Refresh the Beta distribution parameters from the latest actor features. | |
| virtual torch::Tensor | sample (c10::optional< at::Generator > generator=c10::nullopt) const override |
| Draw a stochastic Beta action sample in physical units. | |
| virtual torch::Tensor | deterministicAction () const override |
| Return the Beta 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 Beta distribution. | |
| virtual torch::Tensor | entropy () const override |
| Compute the entropy of the current Beta distribution. | |
| virtual bool | isBounded () const override |
| Return true because the Beta distribution enforces action bounds. | |
| torch::nn::Linear & | alphaModule () |
| Return the Beta alpha head. | |
| const torch::nn::Linear & | alphaModule () const |
| Return the Beta alpha head. | |
| torch::nn::Linear & | betaModule () |
| Return the Beta beta head. | |
| const torch::nn::Linear & | betaModule () const |
| Return the Beta beta head. | |
| const torch::Tensor & | alphaTensor () const |
| Return the cached Beta alpha tensor. | |
| const torch::Tensor & | betaTensor () const |
| Return the cached Beta beta 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 Beta distribution heads. | |
Private Attributes | |
| const std::vector< Real > | _minimum_values |
| Lower action bounds in physical units. | |
| const std::vector< Real > | _maximum_values |
| Upper action bounds in physical units. | |
| torch::nn::Linear | _alpha_module {nullptr} |
| Linear head that produces the Beta alpha parameters. | |
| torch::nn::Linear | _beta_module {nullptr} |
| Linear head that produces the Beta beta parameters. | |
| torch::Tensor | _min_tensor |
| Tensor form of the lower action bounds. | |
| torch::Tensor | _max_tensor |
| Tensor form of the upper action bounds. | |
| torch::Tensor | _alpha_tensor |
| Cached Beta alpha parameters from the latest reset. | |
| torch::Tensor | _beta_tensor |
| Cached Beta beta parameters from the latest reset. | |
| torch::Tensor | _alpha_beta_tensor |
| Cached sum of the alpha and beta parameters. | |
| torch::Tensor | _log_norm |
| Cached log normalization factor for the latest Beta distribution state. | |
| torch::Tensor | _mean |
| Cached normalized Beta mean from the latest reset. | |
Beta action distribution for bounded action spaces.
Definition at line 254 of file LibtorchActionDistribution.h.
| Moose::LibtorchBetaActionDistribution::LibtorchBetaActionDistribution | ( | const std::string & | name, |
| unsigned int | num_inputs, | ||
| unsigned int | num_outputs, | ||
| const std::vector< Real > & | minimum_values, | ||
| const std::vector< Real > & | maximum_values, | ||
| torch::DeviceType | device_type = torch::kCPU, |
||
| torch::ScalarType | scalar_type = torch::kDouble, |
||
| bool | build_on_construct = true, |
||
| const std::vector< Real > & | output_scaling_factors = {} |
||
| ) |
Build the Beta action distribution used for bounded 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. |
| minimum_values | Lower action bounds in physical units. |
| maximum_values | Upper action bounds in physical units. |
| 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 extra per-action scaling in physical units. |
Definition at line 208 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 Moose::LibtorchGaussianActionDistribution::deterministicAction(), deterministicAction(), Moose::LibtorchGaussianActionDistribution::entropy(), entropy(), Moose::LibtorchGaussianActionDistribution::logProbability(), logProbability(), Moose::LibtorchGaussianActionDistribution::sample(), and sample().
|
inline |
Return the Beta alpha head.
Definition at line 322 of file LibtorchActionDistribution.h.
|
inline |
|
inline |
Return the cached Beta alpha tensor.
Definition at line 342 of file LibtorchActionDistribution.h.
|
inline |
Return the Beta beta head.
Definition at line 332 of file LibtorchActionDistribution.h.
|
inline |
|
inline |
Return the cached Beta beta tensor.
Definition at line 347 of file LibtorchActionDistribution.h.
|
private |
Build and register the Beta distribution heads.
Definition at line 243 of file LibtorchActionDistribution.C.
Referenced by LibtorchBetaActionDistribution().
|
overridevirtual |
Return the Beta mean action used for deterministic evaluation.
Implements Moose::LibtorchActionDistribution.
Definition at line 288 of file LibtorchActionDistribution.C.
|
overridevirtual |
Compute the entropy of the current Beta distribution.
Implements Moose::LibtorchActionDistribution.
Definition at line 316 of file LibtorchActionDistribution.C.
|
overridevirtual |
Initialize the trainable Beta distribution parameters.
| generator | Optional random-number generator used for reproducible initialization. |
Implements Moose::LibtorchActionDistribution.
Definition at line 255 of file LibtorchActionDistribution.C.
|
inlineoverridevirtual |
Return true because the Beta distribution enforces action bounds.
Implements Moose::LibtorchActionDistribution.
Definition at line 317 of file LibtorchActionDistribution.h.
|
overridevirtual |
Evaluate the log-probability of an action under the current Beta distribution.
| action | Action tensor in physical units. |
Implements Moose::LibtorchActionDistribution.
Definition at line 294 of file LibtorchActionDistribution.C.
|
protectedinherited |
Convert actions to the configured device and scalar type.
| action | Raw action tensor. |
Definition at line 92 of file LibtorchActionDistribution.C.
Referenced by Moose::LibtorchGaussianActionDistribution::logProbability(), and 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 Moose::LibtorchGaussianActionDistribution::reset(), and reset().
|
overridevirtual |
Refresh the Beta distribution parameters from the latest actor features.
| input | Feature tensor coming from the actor body. |
Implements Moose::LibtorchActionDistribution.
Definition at line 265 of file LibtorchActionDistribution.C.
|
overridevirtual |
Draw a stochastic Beta action sample in physical units.
| generator | Optional random-number generator used for sampling. |
Implements Moose::LibtorchActionDistribution.
Definition at line 279 of file LibtorchActionDistribution.C.
|
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().
|
private |
Cached sum of the alpha and beta parameters.
Definition at line 373 of file LibtorchActionDistribution.h.
|
private |
Linear head that produces the Beta alpha parameters.
Definition at line 361 of file LibtorchActionDistribution.h.
Referenced by alphaModule(), alphaModule(), constructDistribution(), initialize(), and reset().
|
private |
Cached Beta alpha parameters from the latest reset.
Definition at line 369 of file LibtorchActionDistribution.h.
Referenced by alphaTensor(), entropy(), logProbability(), reset(), and sample().
|
private |
Linear head that produces the Beta beta parameters.
Definition at line 363 of file LibtorchActionDistribution.h.
Referenced by betaModule(), betaModule(), constructDistribution(), initialize(), and reset().
|
private |
Cached Beta beta parameters from the latest reset.
Definition at line 371 of file LibtorchActionDistribution.h.
Referenced by betaTensor(), entropy(), logProbability(), reset(), and sample().
|
protectedinherited |
Torch scalar type used by this distribution.
Definition at line 115 of file LibtorchActionDistribution.h.
Referenced by Moose::LibtorchGaussianActionDistribution::constructDistribution(), constructDistribution(), Moose::LibtorchActionDistribution::LibtorchActionDistribution(), 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 Moose::LibtorchGaussianActionDistribution::constructDistribution(), constructDistribution(), Moose::LibtorchActionDistribution::LibtorchActionDistribution(), LibtorchBetaActionDistribution(), Moose::LibtorchActionDistribution::prepareAction(), and Moose::LibtorchActionDistribution::prepareFeatures().
|
private |
Cached log normalization factor for the latest Beta distribution state.
Definition at line 375 of file LibtorchActionDistribution.h.
Referenced by entropy(), logProbability(), and reset().
|
private |
Tensor form of the upper action bounds.
Definition at line 367 of file LibtorchActionDistribution.h.
Referenced by deterministicAction(), entropy(), LibtorchBetaActionDistribution(), logProbability(), and sample().
|
private |
Upper action bounds in physical units.
Definition at line 358 of file LibtorchActionDistribution.h.
Referenced by LibtorchBetaActionDistribution().
|
private |
Cached normalized Beta mean from the latest reset.
Definition at line 377 of file LibtorchActionDistribution.h.
Referenced by deterministicAction(), and reset().
|
private |
Tensor form of the lower action bounds.
Definition at line 365 of file LibtorchActionDistribution.h.
Referenced by deterministicAction(), entropy(), LibtorchBetaActionDistribution(), logProbability(), and sample().
|
private |
Lower action bounds in physical units.
Definition at line 356 of file LibtorchActionDistribution.h.
Referenced by LibtorchBetaActionDistribution().
|
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 Moose::LibtorchGaussianActionDistribution::constructDistribution(), and constructDistribution().
|
protectedinherited |
Number of action dimensions produced by this distribution.
Definition at line 111 of file LibtorchActionDistribution.h.
Referenced by Moose::LibtorchGaussianActionDistribution::constructDistribution(), constructDistribution(), and 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().