class

HalfCauchy

extendsDistribution
HalfCauchy(scale: Tensor | float, validate_args: bool | None = None)
source

Half-Cauchy distribution — the absolute value of a zero-location Cauchy.

If XCauchy(0,s)X \sim \operatorname{Cauchy}(0, s) then XHalfCauchy(s)|X| \sim \operatorname{HalfCauchy}(s). The distribution is supported on [0,)[0, \infty) 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 | float
Scale parameter s>0s > 0. This is the half-width at half-maximum of the Cauchy density folded onto [0,)[0, \infty).
validate_argsbool | None= None
If True, validate parameter constraints at construction time.

Attributes

scaleTensor
Scale parameter ss.

Notes

PDF:

p(x;s)=2πs(1+(x/s)2),x0p(x; s) = \frac{2}{\pi s \left(1 + (x/s)^2\right)}, \quad x \geq 0

Log-PDF:

logp(x)=log2+logCauchy(x;0,s)\log p(x) = \log 2 + \log\operatorname{Cauchy}(x; 0, s)

where the right-hand side is the log-density of the full Cauchy evaluated at xx.

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)

dunder

__init__

None
__init__(scale: Tensor | float, validate_args: bool | None = None)
source

Initialise a HalfCauchy distribution.

Parameters

scaleTensor | float
Scale parameter s>0s > 0. The half-width at half-maximum of the Cauchy density folded onto [0,)[0, \infty).
validate_argsbool | None= None
If True, validate parameter constraints at construction time.
fn

rsample

Tensor
rsample(sample_shape: tuple[int, ...] = ())
source

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, ...]= ()
Leading shape of the output sample batch.

Returns

Tensor

Non-negative samples of shape (*sample_shape, *batch_shape).

fn

log_prob

Tensor
log_prob(value: Tensor)
source

Log-probability density of the HalfCauchy distribution.

logp(x)=log2+logCauchy(x;0,s)\log p(x) = \log 2 + \log\operatorname{Cauchy}(x; 0, s)

Parameters

valueTensor
Non-negative points x0x \geq 0 at which to evaluate.

Returns

Tensor

Log-density values of the same shape as value.