Skip to content
class

Exponential

extendsExponentialFamily
Exponential(rate: Tensor | float, validate_args: bool | None = None)

Exponential distribution on [0,∞)[0, \infty).

Continuous distribution describing the waiting time between events of a Poisson process with rate λ\lambda. It is the continuous analogue of the lucid.distributions.Geometric distribution and the unique continuous distribution with the memoryless property.

Parameters

rateTensor or float
Rate parameter λ>0\lambda > 0. The mean of the distribution is 1/λ1/\lambda.
validate_argsbool= None
If True, validate parameter constraints at construction time.

Notes

Probability density on x≥0x \geq 0:

p(x;λ)=λe−λxp(x; \lambda) = \lambda e^{-\lambda x}

Moments:

E[X]=1λ,Var[X]=1λ2,H[X]=1−log⁡λ\mathbb{E}[X] = \frac{1}{\lambda}, \qquad \mathrm{Var}[X] = \frac{1}{\lambda^2}, \qquad H[X] = 1 - \log \lambda

Memoryless property:

P(X>s+t∣X>s)=P(X>t)P(X > s + t \mid X > s) = P(X > t)

Special cases / relations:

  • Exponential(λ)=Gamma(1,λ)\mathrm{Exponential}(\lambda) = \mathrm{Gamma}(1, \lambda)
  • The sum of kk IID Exponential(λ)\mathrm{Exponential}(\lambda) variables is Gamma(k,λ)\mathrm{Gamma}(k, \lambda) (Erlang).
  • −log⁡U/λ-\log U / \lambda with U∼Uniform(0,1)U \sim \mathrm{Uniform}(0, 1) is the inverse-CDF sampler used by rsample.

Examples

>>> import lucid
>>> from lucid.distributions import Exponential
>>> d = Exponential(rate=2.0)
>>> d.mean  # 1/rate
tensor(0.5)
>>> d.rsample((4,)).shape
(4,)
>>> d.log_prob(lucid.tensor(1.0))
tensor(-1.307)

Used by 4

Constructors

1
dunder

__init__

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

Construct an Exponential distribution.

Parameters

rateTensor | float
Rate parameter λ>0\lambda > 0. The mean of the distribution is 1/λ1/\lambda.
validate_argsbool | None= None
If True, validate parameter constraints at construction time.

Notes

The Exponential distribution with rate λ\lambda has PDF:

p(x;λ)=λe−λx,x≥0p(x; \lambda) = \lambda e^{-\lambda x}, \quad x \geq 0

It is the continuous analogue of the Geometric distribution and describes the waiting time between events in a Poisson process.

Examples

>>> from lucid.distributions import Exponential
>>> d = Exponential(rate=2.0)
>>> d.mean  # 1/rate = 0.5
tensor(0.5)

Properties

3
prop

mean

→Tensor
mean: Tensor

Expected value of the Exponential distribution.

E[X]=1λE[X] = \frac{1}{\lambda}

Returns

Tensor

Mean 1/λ1/\lambda, shape batch_shape.

Examples

>>> Exponential(rate=4.0).mean
tensor(0.25)
prop

mode

→Tensor
mode: Tensor

Mode of the Exponential distribution.

The Exponential distribution is monotonically decreasing on [0,∞)[0, \infty), so the mode is always zero regardless of the rate parameter.

mode=0\text{mode} = 0

Returns

Tensor

Zero tensor of shape batch_shape.

Examples

>>> Exponential(rate=5.0).mode
tensor(0.)
prop

variance

→Tensor
variance: Tensor

Variance of the Exponential distribution.

Var⁡[X]=1λ2\operatorname{Var}[X] = \frac{1}{\lambda^2}

Returns

Tensor

Variance 1/λ21/\lambda^2, shape batch_shape.

Examples

>>> Exponential(rate=2.0).variance
tensor(0.25)

Instance methods

6
fn

cdf

→Tensor
cdf(value: Tensor)

Cumulative distribution function of the Exponential distribution.

F(x;λ)=1−e−λx,x≥0F(x; \lambda) = 1 - e^{-\lambda x}, \quad x \geq 0

Parameters

valueTensor
Non-negative real values at which to evaluate the CDF.

Returns

Tensor

CDF values in [0,1][0, 1], shape batch_shape.

Notes

Clamped below the support. 1 - exp(-λx) is the formula on [0,∞)[0, \infty); evaluated at a negative argument it grows without bound and returned -1.718 for x = -1, while the line above this one promises a value in [0,1][0, 1]. A CDF is defined on the whole line and is zero to the left of its support; with validation on (the default) such a value raises ValueError instead.

Examples

>>> Exponential(rate=1.0).cdf(lucid.tensor(1.0))  # 1 - e^-1 ≈ 0.632
tensor(0.6321)
>>> # below the support: refused under validation, 0 without it
>>> Exponential(rate=1.0, validate_args=False).cdf(lucid.tensor(-1.0))
tensor(0.)
fn

entropy

→Tensor
entropy()

Shannon entropy of the Exponential distribution (in nats).

H(X)=1−log⁡λH(X) = 1 - \log \lambda

The entropy decreases as the rate increases (concentrated distributions have lower uncertainty).

Returns

Tensor

Entropy in nats, shape batch_shape.

Examples

>>> Exponential(rate=1.0).entropy()  # 1 - log(1) = 1.0
tensor(1.)
fn

expand

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

Return a new Exponential with batch dimensions expanded to batch_shape.

fn

icdf

→Tensor
icdf(value: Tensor)

Inverse CDF (quantile function) of the Exponential distribution.

F−1(u;λ)=−log⁡(1−u)λF^{-1}(u; \lambda) = -\frac{\log(1 - u)}{\lambda}

Parameters

valueTensor
Probability values u∈[0,1)u \in [0, 1).

Returns

Tensor

Quantiles in [0,∞)[0, \infty), shape batch_shape.

Notes

-log1p(-u) rather than -log(1 - u): for a small u the subtraction rounds 1 - u to 1 and the quantile to 0 — every u below 6e-8 in float32 — where the reference answers u.

Examples

>>> Exponential(rate=1.0).icdf(lucid.tensor(0.5))  # log(2) ≈ 0.693
tensor(0.6931)
fn

log_prob

→Tensor
log_prob(value: Tensor)

Log-density of value under the Exponential distribution.

log⁡p(x;λ)=log⁡λ−λx\log p(x; \lambda) = \log \lambda - \lambda x

Parameters

valueTensor
Non-negative real values x≥0x \geq 0.

Returns

Tensor

Element-wise log-densities, shape batch_shape.

Examples

>>> d = Exponential(rate=1.0)
>>> d.log_prob(lucid.tensor(1.0))  # -1.0
tensor(-1.)
fn

rsample

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

Reparameterised sample via the inverse-CDF method.

Uses the transform X=−log⁡(1−U)/λX = -\log(1 - U) / \lambda where U∼Uniform(0,1)U \sim \text{Uniform}(0, 1). This is an exact reparameterisation — gradients flow through λ\lambda.

X=−log⁡(1−U)λX = -\frac{\log(1 - U)}{\lambda}

Subtracting from 1 (rather than directly using UU) ensures the argument to log⁡\log is bounded away from zero.

Parameters

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

Returns

Tensor

Reparameterised samples of shape sample_shape + batch_shape.

Examples

>>> _ = lucid.manual_seed(0)
>>> d = Exponential(rate=1.0)
>>> x = d.rsample((500,))
>>> x.shape
(500,)
>>> bool((x.mean() - 1.0).abs() < 0.15)  # the sample mean approaches 1/rate
True