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 2
Constructors
1Initialise a HalfCauchy distribution.
Parameters
scaleTensor | floatvalidate_argsbool | None= NoneTrue, validate parameter constraints at construction time.Properties
4Mean 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.
Mode of the half-Cauchy distribution: 0, where the density peaks.
Standard deviation of the half-Cauchy — infinite.
Variance of the half-Cauchy — infinite.
Instance methods
5Cumulative distribution function of the half-Cauchy distribution.
Returns probabilities in ; 0 below 0.
Examples
>>> HalfCauchy(scale=1.0).cdf(lucid.tensor(1.0)) # the median is s
tensor(0.5)Entropy of the half-Cauchy distribution.
The full Cauchy's less : folding halves the support and doubles the density on it.
Returns
TensorEntropy values of shape batch_shape (nats).
Examples
>>> HalfCauchy(scale=1.0).entropy() # ln(2 pi)
tensor(1.838)Quantile function of the half-Cauchy distribution.
Returns quantiles in .
Examples
>>> HalfCauchy(scale=1.0).icdf(lucid.tensor(0.5))
tensor(1.)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).