ray.rllib.models.distributions.Distribution#
- class ray.rllib.models.distributions.Distribution[source]#
Bases:
ABC
The base class for distribution over a random variable.
Examples:
import torch from ray.rllib.core.models.configs import MLPHeadConfig from ray.rllib.models.torch.torch_distributions import TorchCategorical model = MLPHeadConfig(input_dims=[1]).build(framework="torch") # Create an action distribution from model logits action_logits = model(torch.Tensor([[1]])) action_dist = TorchCategorical.from_logits(action_logits) action = action_dist.sample() # Create another distribution from a dummy Tensor action_dist2 = TorchCategorical.from_logits(torch.Tensor([0])) # Compute some common metrics logp = action_dist.logp(action) kl = action_dist.kl(action_dist2) entropy = action_dist.entropy()
Methods
The entropy of the distribution.
Creates a Distribution from logits.
Returns a partial child of TorchMultiActionDistribution.
The KL-divergence between two distributions.
The log-likelihood of the distribution computed at
value
Returns the required length of an input parameter tensor.
Draw a re-parameterized sample from the action distribution.
Draw a sample from the distribution.
Returns a deterministic equivalent for this distribution.