class

Laplace

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

Laplace (double-exponential) distribution on R\mathbb{R}.

Symmetric continuous distribution composed of two mirrored Exponential densities placed back-to-back at the location μ\mu. It is the maximum-entropy distribution with a given mean and a given mean absolute deviation, and is the prior whose negative log-density induces the L1 (Lasso) penalty.

Parameters

locTensor or float
Location parameter μR\mu \in \mathbb{R} (mean = median = mode).
scaleTensor or float
Scale / diversity parameter b>0b > 0.
validate_argsbool= None
If True, validate parameter constraints at construction time.

Notes

Probability density:

p(x;μ,b)=12bexp ⁣(xμb)p(x; \mu, b) = \frac{1}{2b} \exp\!\left(-\frac{|x - \mu|}{b}\right)

Moments:

E[X]=μ,Var[X]=2b2,H[X]=1+log(2b)\mathbb{E}[X] = \mu, \qquad \mathrm{Var}[X] = 2 b^2, \qquad H[X] = 1 + \log(2b)

The Laplace has heavier tails than the Normal: its kurtosis is 6 vs. 3 for the Normal, and its tails decay exponentially rather than quadratically in log-space.

Sampling uses the closed-form inverse CDF:

X=μbsgn(U12)log(12U12),UUniform(0,1)X = \mu - b \operatorname{sgn}(U - \tfrac{1}{2}) \log(1 - 2|U - \tfrac{1}{2}|), \quad U \sim \mathrm{Uniform}(0, 1)

so rsample is exact and gradient-friendly through both μ\mu and bb.

Examples

>>> import lucid
>>> from lucid.distributions import Laplace
>>> d = Laplace(loc=0.0, scale=1.0)
>>> d.mean
Tensor(0.0)
>>> d.rsample((4,))
Tensor([...])
>>> d.log_prob(lucid.tensor(0.0))
Tensor(-0.6931)

Methods (7)

dunder

__init__

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

Construct a Laplace distribution.

Parameters

locTensor | float
Location parameter μR\mu \in \mathbb{R} (the mean and median of the distribution).
scaleTensor | float
Scale (diversity) parameter b>0b > 0.
validate_argsbool | None= None
If True, validate parameter constraints at construction time.

Notes

The Laplace distribution has PDF:

p(x;μ,b)=12bexp ⁣(xμb)p(x; \mu, b) = \frac{1}{2b} \exp\!\left(-\frac{|x - \mu|}{b}\right)

It is also called the double-exponential distribution because it resembles two mirrored Exponential densities placed back-to-back at the location μ\mu. It is frequently used in robust statistics and as the prior inducing L1 (Lasso) regularisation.

Examples

>>> from lucid.distributions import Laplace
>>> d = Laplace(loc=0.0, scale=1.0)
>>> d.mean
Tensor(0.0)
prop

mean

Tensor
mean: Tensor
source

Expected value of the Laplace distribution.

E[X]=μE[X] = \mu

Returns

Tensor

Location parameter μ\mu, shape batch_shape.

Examples

>>> Laplace(loc=3.0, scale=1.0).mean
Tensor(3.0)
prop

variance

Tensor
variance: Tensor
source

Variance of the Laplace distribution.

Var[X]=2b2\operatorname{Var}[X] = 2b^2

Returns

Tensor

Variance 2b22b^2, shape batch_shape.

Examples

>>> Laplace(loc=0.0, scale=1.0).variance
Tensor(2.0)
fn

rsample

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

Reparameterised sample via the inverse-CDF method.

Uses the closed-form quantile function:

X=μbsgn(u)log(12u)X = \mu - b \operatorname{sgn}(u) \log(1 - 2|u|)

where u=U0.5u = U - 0.5 and UUniform(0,1)U \sim \text{Uniform}(0, 1). Gradients flow through both μ\mu and bb.

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 = Laplace(loc=0.0, scale=1.0)
>>> x = d.rsample((200,))
fn

log_prob

Tensor
log_prob(value: Tensor)
source

Log-density of value under the Laplace distribution.

logp(x;μ,b)=xμblog(2b)\log p(x; \mu, b) = -\frac{|x - \mu|}{b} - \log(2b)

Parameters

valueTensor
Real-valued observations.

Returns

Tensor

Element-wise log-densities, shape batch_shape.

Examples

>>> Laplace(loc=0.0, scale=1.0).log_prob(lucid.tensor(0.0))
Tensor(-0.6931)
fn

cdf

Tensor
cdf(value: Tensor)
source

Cumulative distribution function of the Laplace distribution.

F(x;μ,b)=1212sgn(xμ)(1exμ/b)F(x; \mu, b) = \frac{1}{2} - \frac{1}{2} \operatorname{sgn}(x - \mu) \left(1 - e^{-|x-\mu|/b}\right)

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()
source

Shannon entropy of the Laplace distribution (in nats).

H(X)=1+log(2b)H(X) = 1 + \log(2b)

Returns

Tensor

Entropy in nats, shape batch_shape.

Examples

>>> Laplace(loc=0.0, scale=1.0).entropy()  # 1 + log(2) ≈ 1.693
Tensor(1.6931)