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,))
>>> (samples >= 0.0).all()Methods (3)
__init__
→None__init__(scale: Tensor | float, validate_args: bool | None = None)Initialise a HalfCauchy distribution.
Parameters
scaleTensor | floatvalidate_argsbool | None= NoneTrue, validate parameter constraints at construction time.rsample
→Tensorrsample(sample_shape: tuple[int, ...] = ())Draw 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).
log_prob
→Tensorlog_prob(value: Tensor)Log-probability density of the HalfCauchy distribution.
Parameters
valueTensorReturns
TensorLog-density values of the same shape as value.