Laplace
DistributionLaplace(loc: Tensor | float, scale: Tensor | float, validate_args: bool | None = None)Laplace (double-exponential) distribution on .
Symmetric continuous distribution composed of two mirrored Exponential densities placed back-to-back at the location . 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 floatscaleTensor or floatvalidate_argsbool= NoneTrue, validate parameter constraints at construction time.Notes
Probability density:
Moments:
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:
so rsample is exact and gradient-friendly through both
and .
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)
__init__
→None__init__(loc: Tensor | float, scale: Tensor | float, validate_args: bool | None = None)Construct a Laplace distribution.
Parameters
locTensor | floatscaleTensor | floatvalidate_argsbool | None= NoneTrue, validate parameter constraints at construction time.Notes
The Laplace distribution has PDF:
It is also called the double-exponential distribution because it resembles two mirrored Exponential densities placed back-to-back at the location . 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)mean
→Tensormean: TensorExpected value of the Laplace distribution.
Returns
TensorLocation parameter , shape batch_shape.
Examples
>>> Laplace(loc=3.0, scale=1.0).mean
Tensor(3.0)variance
→Tensorvariance: TensorVariance of the Laplace distribution.
Returns
TensorVariance , shape batch_shape.
Examples
>>> Laplace(loc=0.0, scale=1.0).variance
Tensor(2.0)rsample
→Tensorrsample(sample_shape: tuple[int, ...] = ())Reparameterised sample via the inverse-CDF method.
Uses the closed-form quantile function:
where and . Gradients flow through both and .
Parameters
sample_shapetuple[int, ...]= ()().Returns
TensorReparameterised samples of shape sample_shape + batch_shape.
Examples
>>> d = Laplace(loc=0.0, scale=1.0)
>>> x = d.rsample((200,))log_prob
→Tensorlog_prob(value: Tensor)Log-density of value under the Laplace distribution.
Parameters
valueTensorReturns
TensorElement-wise log-densities, shape batch_shape.
Examples
>>> Laplace(loc=0.0, scale=1.0).log_prob(lucid.tensor(0.0))
Tensor(-0.6931)cdf
→Tensorcdf(value: Tensor)Cumulative distribution function of the Laplace distribution.
Parameters
valueTensorReturns
TensorCDF values in , shape batch_shape.
entropy
→Tensorentropy()Shannon entropy of the Laplace distribution (in nats).
Returns
TensorEntropy in nats, shape batch_shape.
Examples
>>> Laplace(loc=0.0, scale=1.0).entropy() # 1 + log(2) ≈ 1.693
Tensor(1.6931)