HalfCauchy
DistributionHalfCauchy(scale: Tensor | float, validate_args: bool | None = None)Half-Cauchy distribution — the absolute value of a zero-location Cauchy.
If then . The distribution is supported on and has no finite moments (mean and variance are undefined, like the full Cauchy).
It is a popular weakly-informative prior for scale parameters in Bayesian hierarchical models — heavy tails allow occasional large scales while the mode at zero permits near-zero scales.
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 Cauchy evaluated at .
Neither the mean nor the variance exists because the Cauchy distribution lacks finite moments of any positive order.
Reparameterised sampling folds a Cauchy sample via abs, so gradients
propagate through the scale parameter.
Examples
>>> import lucid
>>> from lucid.distributions import HalfCauchy
>>> dist = HalfCauchy(scale=1.0)
>>> samples = dist.rsample((200,))
>>> bool((samples >= 0.0).all())
TrueUsed by 1
Constructors
1Initialise a HalfCauchy distribution.
Parameters
scaleTensor | floatvalidate_argsbool | None= NoneTrue, validate parameter constraints at construction time.Properties
3Mean of the half-Cauchy — infinite.
Folding the Cauchy onto removes the cancellation that made the full distribution's mean undefined and leaves a single divergent tail, so the answer is rather than NaN.
Returns
TensorTensor of inf with shape batch_shape.
Standard deviation of the half-Cauchy — infinite.
Variance of the half-Cauchy — infinite.
Instance methods
2Draw reparameterised samples by folding a Cauchy sample.
Computes abs of a zero-location Cauchy sample, so
gradients propagate through the scale parameter.
Parameters
sample_shapetuple[int, ...]= ()Returns
TensorNon-negative samples of shape (*sample_shape, *batch_shape).