IndependentNormal¶
- class torchrl.modules.IndependentNormal(loc: Tensor, scale: Tensor, upscale: float = 5.0, tanh_loc: bool = False, event_dim: int = 1, **kwargs)[source]¶
Implements a Normal distribution with location scaling.
Location scaling prevents the location to be “too far” from 0, which ultimately leads to numerically unstable samples and poor gradient computation (e.g. gradient explosion). In practice, the location is computed according to
\[loc = tanh(loc / upscale) * upscale.\]This behavior can be disabled by switching off the tanh_loc parameter (see below).
- Parameters:
loc (torch.Tensor) – normal distribution location parameter
scale (torch.Tensor) – normal distribution sigma parameter (squared root of variance)
upscale (torch.Tensor or number, optional) –
‘a’ scaling factor in the formula:
\[loc = tanh(loc / upscale) * upscale.\]Default is 5.0
tanh_loc (bool, optional) – if
False
, the above formula is used for the location scaling, otherwise the raw value is kept. Default isFalse
;
- property mode¶
Returns the mode of the distribution.