HalfNormal
DistributionHalfNormal(scale: Tensor | float, validate_args: bool | None = None)Half-Normal distribution — the absolute value of a zero-mean Normal.
If then . The distribution is supported on and arises naturally as a scale prior in hierarchical Bayesian models (it is weakly informative while keeping probability mass away from zero).
Parameters
scaleTensor | floatvalidate_argsbool | None= NoneTrue, validate parameter constraints at construction time.Attributes
scaleTensorNotes
PDF:
Log-PDF:
where the right-hand side is the log-density of the full Normal evaluated at .
Moments:
- Mean:
- Variance:
Entropy:
Reparameterised sampling takes abs of a Normal sample, so
gradients flow through unobstructed.
Examples
>>> import lucid
>>> from lucid.distributions import HalfNormal
>>> dist = HalfNormal(scale=1.0)
>>> samples = dist.rsample((300,))
>>> (samples >= 0.0).all()Methods (6)
__init__
→None__init__(scale: Tensor | float, validate_args: bool | None = None)Initialise a HalfNormal distribution.
Parameters
scaleTensor | floatvalidate_argsbool | None= NoneTrue, validate parameter constraints at construction time.mean
→Tensormean: TensorMean of the HalfNormal distribution: .
Returns
TensorMean values of shape batch_shape.
variance
→Tensorvariance: TensorVariance of the HalfNormal distribution: .
Returns
TensorVariance values of shape batch_shape.
rsample
→Tensorrsample(sample_shape: tuple[int, ...] = ())Draw reparameterised samples by folding a Normal sample.
Computes abs of a Normal sample, so gradients propagate
through unobstructed.
Parameters
sample_shapetuple[int, ...]= ()Returns
TensorNon-negative samples of shape (*sample_shape, *batch_shape).
log_prob
→Tensorlog_prob(value: Tensor)Log-probability density of the HalfNormal distribution.
Parameters
valueTensorReturns
TensorLog-density values of the same shape as value.
entropy
→Tensorentropy()Entropy of the HalfNormal distribution.
Returns
TensorEntropy values of shape batch_shape (nats).