Skip to content
class

Cauchy

extendsDistribution
Cauchy(loc: Tensor | float, scale: Tensor | float, validate_args: bool | None = None)

Cauchy distribution on R\mathbb{R} — heavy-tailed, all moments undefined.

The canonical example of a pathological heavy-tailed distribution: its tails decay so slowly that no integer moment (mean, variance, skew, kurtosis) is defined. The Cauchy is the Student's-t distribution with one degree of freedom and arises naturally as the ratio of two independent standard Normals.

Parameters

locTensor or float
Location parameter x0∈Rx_0 \in \mathbb{R} (median and mode). The "mean" does not exist.
scaleTensor or float
Scale parameter γ>0\gamma > 0 (half-width at half-maximum).
validate_argsbool= None
If True, validate parameter constraints at construction time.

Notes

Probability density:

p(x;x0,γ)=1πγ[1+(x−x0γ)2]−1p(x; x_0, \gamma) = \frac{1}{\pi \gamma} \left[1 + \left(\frac{x - x_0}{\gamma}\right)^2\right]^{-1}

Cumulative distribution:

F(x;x0,γ)=1πarctan⁡ ⁣(x−x0γ)+12F(x; x_0, \gamma) = \frac{1}{\pi} \arctan\!\left(\frac{x - x_0}{\gamma}\right) + \frac{1}{2}

Properties (no moments — all are undefined or infinite):

  • Median / mode: x0x_0
  • Mean / variance: undefined (integrals diverge)
  • Entropy: H[X]=log⁡(4πγ)H[X] = \log(4 \pi \gamma)

Sample mean does not converge — the strong law of large numbers fails for IID Cauchy variates. Any finite-sample average of Cauchy draws is itself Cauchy-distributed with the same parameters.

Stability: a sum of independent Cauchy variables remains Cauchy (it is an α\alpha-stable distribution with stability index 1).

Reparameterised sampling uses the inverse-CDF X=x0+γtan⁡(π(U−12))X = x_0 + \gamma \tan(\pi(U - \tfrac{1}{2})).

Examples

>>> import lucid
>>> from lucid.distributions import Cauchy
>>> d = Cauchy(loc=0.0, scale=1.0)
>>> d.rsample((4,)).shape
(4,)
>>> d.log_prob(lucid.tensor(0.0))
tensor(-1.145)

Used by 3

Constructors

1
dunder

__init__

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

Construct a Cauchy distribution.

Parameters

locTensor | float
Location parameter (median and mode) x0∈Rx_0 \in \mathbb{R}.
scaleTensor | float
Scale (half-width at half-maximum) parameter γ>0\gamma > 0.
validate_argsbool | None= None
If True, validate parameter constraints at construction time.

Notes

The Cauchy distribution has PDF:

p(x;x0,γ)=1πγ[1+(x−x0γ)2]−1p(x; x_0, \gamma) = \frac{1}{\pi \gamma} \left[1 + \left(\frac{x - x_0}{\gamma}\right)^2\right]^{-1}

The Cauchy is the Student's t-distribution with one degree of freedom. Because all moments of order ≥1\geq 1 are undefined, it is a canonical example of a heavy-tailed distribution where the sample mean does not converge to any value.

Examples

>>> from lucid.distributions import Cauchy
>>> d = Cauchy(loc=0.0, scale=1.0)
>>> x = d.rsample((1000,))

Properties

4
prop

mean

→Tensor
mean: Tensor

Mean of the Cauchy distribution — undefined, returns NaN.

The defining integral ∫x p(x) dx\int x\, p(x)\, dx does not converge for the Cauchy: the tails decay as x−2x^{-2}, so the two halves are each infinite and their difference has no value. This is not a limitation of the parameters — no Cauchy has a mean.

Returns

Tensor

Tensor of float('nan') with shape batch_shape.

prop

mode

→Tensor
mode: Tensor

Mode of the Cauchy distribution: the location x0x_0.

prop

stddev

→Tensor
stddev: Tensor

Standard deviation — infinite, as the square root of variance.

prop

variance

→Tensor
variance: Tensor

Variance of the Cauchy distribution — infinite.

Unlike the mean, the second moment integral diverges in one direction only, so the answer is +∞+\infty rather than NaN.

Returns

Tensor

Tensor of inf with shape batch_shape.

Instance methods

6
fn

cdf

→Tensor
cdf(value: Tensor)

Cumulative distribution function of the Cauchy distribution.

F(x;x0,γ)=1πarctan⁡ ⁣(x−x0γ)+12F(x; x_0, \gamma) = \frac{1}{\pi} \arctan\!\left(\frac{x - x_0}{\gamma}\right) + \frac{1}{2}

Parameters

valueTensor
Real values at which to evaluate the CDF.

Returns

Tensor

CDF values in (0,1)(0, 1), shape batch_shape.

fn

entropy

→Tensor
entropy()

Shannon entropy of the Cauchy distribution (in nats).

H(X)=log⁡(4πγ)H(X) = \log(4 \pi \gamma)

Returns

Tensor

Entropy in nats, shape batch_shape.

Examples

>>> Cauchy(loc=0.0, scale=1.0).entropy()  # log(4π) ≈ 2.531
tensor(2.531)
fn

expand

→Self
expand(batch_shape: Sequence[int], _instance: Self | None = None)

Return a new Cauchy with batch dimensions expanded to batch_shape.

fn

icdf

→Tensor
icdf(value: Tensor)

Quantile function of the Cauchy distribution.

Q(p)=x0+γtan⁡ ⁣(π(p−12))Q(p) = x_0 + \gamma \tan\!\left(\pi\left(p - \tfrac12\right)\right)

Returns quantiles. At p=0p = 0 and 11 the tangent of ∓π/2\mp\pi/2 is evaluated, which is a large finite number rather than an infinity, as in the reference framework.

Examples

>>> Cauchy(loc=0.0, scale=1.0).icdf(lucid.tensor(0.75))
tensor(1.)
fn

log_prob

→Tensor
log_prob(value: Tensor)

Log-density of value under the Cauchy distribution.

log⁡p(x;x0,γ)=−log⁡π−log⁡γ−log⁡ ⁣(1+(x−x0γ)2)\log p(x; x_0, \gamma) = -\log \pi - \log \gamma - \log\!\left(1 + \left(\frac{x - x_0}{\gamma}\right)^2\right)

Parameters

valueTensor
Real-valued observations.

Returns

Tensor

Element-wise log-densities, shape batch_shape.

Examples

>>> Cauchy(loc=0.0, scale=1.0).log_prob(lucid.tensor(0.0))
tensor(-1.145)
fn

rsample

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

Reparameterised sample via the inverse-CDF method.

Uses the quantile function of the Cauchy distribution:

X=x0+γtan⁡ ⁣(π(U−12))X = x_0 + \gamma \tan\!\bigl(\pi (U - \tfrac{1}{2})\bigr)

where U∼Uniform(0,1)U \sim \text{Uniform}(0, 1). Gradients flow through both x0x_0 and γ\gamma.

Parameters

sample_shapetuple[int, ...]= ()
Leading shape dimensions for the sample batch. Default is ().

Returns

Tensor

Reparameterised samples of shape sample_shape + batch_shape.

Examples

>>> d = Cauchy(loc=0.0, scale=1.0)
>>> x = d.rsample((500,))