Shortcuts

class torchrl.modules.MaskedCategorical(logits: Optional[Tensor] = None, probs: Optional[Tensor] = None, *, mask: Optional[Tensor] = None, indices: Optional[Tensor] = None, neg_inf: float = - inf, padding_value: Optional[int] = None)[source]

Parameters:
• logits (torch.Tensor) – event log probabilities (unnormalized)

• probs (torch.Tensor) – event probabilities. If provided, the probabilities corresponding to to masked items will be zeroed and the probability re-normalized along its last dimension.

Keyword Arguments:
• mask (torch.Tensor) – A boolean mask of the same shape as logits/probs where False entries are the ones to be masked. Alternatively, if sparse_mask is True, it represents the list of valid indices in the distribution. Exclusive with indices.

• indices (torch.Tensor) – A dense index tensor representing which actions must be taken into account. Exclusive with mask.

• neg_inf (float, optional) – The log-probability value allocated to invalid (out-of-mask) indices. Defaults to -inf.

• torch.manual_seed (>>>) –

• torch.randn (>>> logits =) –

• torch.tensor (>>> mask =) –

• MaskedCategorical (>>> dist =) –

• dist.sample (>>> sample =) –

• print (>>>) –

• tensor ([-inf, -inf, -inf, -inf, -inf, -inf, -inf, -inf, -inf, -inf]) –

• print

• -1.0831, (tensor([-1.1203, -1.0928, -1.0831, -1.1203, -1.1203, -1.0831, -1.1203,) – -1.1203, -1.1203])

• print

• tensor

• probabilities (>>> # with) –

• torch.ones (>>> prob =) –

• prob.sum() (>>> prob = prob /) –

• torch.tensor

• print

• -2.1972, (tensor([ -inf, -2.1972, -2.1972, -2.1972, -2.1972, -2.1972, -2.1972,) – -2.1972, -2.1972])

log_prob(value: Tensor) [source]

Returns the log of the probability density/mass function evaluated at value.

Parameters:

value (Tensor) –

sample(sample_shape: Optional[Union[Size, Sequence[int]]] = None) [source]

Generates a sample_shape shaped sample or sample_shape shaped batch of samples if the distribution parameters are batched.

## Docs

Access comprehensive developer documentation for PyTorch

View Docs

## Tutorials

Get in-depth tutorials for beginners and advanced developers

View Tutorials