jaxdem.rl.action_spaces#
Interface for bijectors that constrain the policy probability distribution.
Classes
Registry/namespace for action-space constraints implemented as |
|
|
|
- class jaxdem.rl.action_spaces.ActionSpace#
Bases:
FactoryRegistry/namespace for action-space constraints implemented as
distrax.Bijectorobjects.Wrap these bijectors around a base policy distribution (e.g.,
MultivariateNormalDiag) withdistrax.Transformed. The bijector’s ‘forward_and_log_det’ / ‘inverse_and_log_det’ methods then adjust sampling and log-probabilities correctly. See the Distrax/TFP bijector interface for details on shape semantics and ‘event_ndims_in/out’.Example
To define a custom action space, inherit from
distrax.BijectorandActionSpaceand implement its abstract methods:>>> @ActionSpace.register("myCustomActionSpace") ... class MyCustomActionSpace(distrax.Bijector, ActionSpace): ... ...
- class jaxdem.rl.action_spaces.Transformed(*args, **kwargs)[source]#
Bases:
Transformeddistrax.Transformedwith entropy support for action-space bijectors.For \(Y = f(X)\) where \(X \sim \text{base}\),
\[H(Y) = H(X) + \mathbb{E}_X[\log|\det J_f(X)|].\]This is the differential-entropy identity for an invertible differentiable transform. For the diagonal-Gaussian policies used here, the bijector’s
log_det_expectation()supplies the correction. FreeSpace and MaxNormSpace return it analytically. BoxSpace uses componentwise Gauss–Hermite quadrature, whose accuracy depends on the policy parameters and quadrature order. BlockwiseSpace sums its children’s corrections.- sample_and_log_prob_with_latent(*, seed: Array, sample_shape: tuple[int, ...] = ()) tuple[Array, Array, Array, Array][source]#
Sample an action and retain its latent and base log-probability.
PPO can compute same-transform likelihood ratios in base coordinates, where the Jacobian cancels, without inverting a rounded/saturated action. Returns action, transformed log-probability, latent, base log-probability.
- entropy(input_hint: Array | ndarray | bool | number | None = None) Array[source]#
Calculates the Shannon entropy (in Nats).
Only works for bijectors with constant Jacobian determinant.
- Parameters:
input_hint – an example sample from the base distribution, used to compute the constant forward log-determinant. If not specified, it is computed using a zero array of the shape and dtype of a sample from the base distribution.
- Returns:
the entropy of the distribution.
- Raises:
NotImplementedError – if bijector’s Jacobian determinant is not known to be constant.
Modules
Apply action-space bijectors to contiguous parts of one action vector. |
|
Bijector that constrains actions elementwise to a box. |
|
Identity bijector that applies no constraint. |
|
Bijector that maps Gaussian actions into a ball with analytic entropy. |