Skip to content

lit_sb3.distributions.base

source module lit_sb3.distributions.base

Abstract base class for probability distributions.

Classes

Functions

source class Distribution()

Bases : ABC

Abstract base class for distributions.

Methods

  • proba_distribution_net — Create the layers and parameters that represent the distribution.

  • proba_distribution — Set parameters of the distribution.

  • log_prob — Returns the log likelihood.

  • entropy — Returns Shannon's entropy of the probability.

  • sample — Returns a sample from the probability distribution.

  • mode — Returns the most likely action (deterministic output).

  • get_actions — Return actions according to the probability distribution.

  • actions_from_params — Returns samples from the probability distribution.

  • log_prob_from_params — Returns samples and the associated log probabilities.

source method Distribution.proba_distribution_net(*args, **kwargs) → nn.Module | tuple[nn.Module, nn.Parameter]

Create the layers and parameters that represent the distribution.

Subclasses must define this, but the arguments and return type vary between concrete classes.

source method Distribution.proba_distribution(*args, **kwargs) → SelfDistribution

Set parameters of the distribution.

Returns

  • SelfDistribution — self

source method Distribution.log_prob(x: torch.Tensor) → torch.Tensor

Returns the log likelihood.

Parameters

  • x : torch.Tensor — the taken action

Returns

  • torch.Tensor — The log likelihood of the distribution

source method Distribution.entropy() → torch.Tensor | None

Returns Shannon's entropy of the probability.

Returns

  • torch.Tensor | None — the entropy, or None if no analytical form is known

source method Distribution.sample() → torch.Tensor

Returns a sample from the probability distribution.

Returns

  • torch.Tensor — the stochastic action

source method Distribution.mode() → torch.Tensor

Returns the most likely action (deterministic output).

from the probability distribution.

Returns

  • torch.Tensor — the stochastic action

source method Distribution.get_actions(deterministic: bool = False) → torch.Tensor

Return actions according to the probability distribution.

Parameters

  • deterministic : bool — Whether to use deterministic actions.

source method Distribution.actions_from_params(*args, **kwargs) → torch.Tensor

Returns samples from the probability distribution.

given its parameters.

Returns

  • torch.Tensor — actions

source method Distribution.log_prob_from_params(*args, **kwargs) → tuple[torch.Tensor, torch.Tensor]

Returns samples and the associated log probabilities.

from the probability distribution given its parameters.

Returns

  • tuple[torch.Tensor, torch.Tensor] — actions and log prob

source sum_independent_dims(tensor: torch.Tensor) → torch.Tensor

Continuous actions are usually considered to be independent,.

so we can sum components of the log_prob or the entropy.

Parameters

  • tensor : torch.Tensor — shape: (n_batch, n_actions) or (n_batch,)

Returns

  • shape — (n_batch,) for (n_batch, n_actions) input, scalar for (n_batch,) input