class

Weibull

extendsDistribution
Weibull(scale: Tensor | float, concentration: Tensor | float, validate_args: bool | None = None)
source

Weibull distribution — a flexible family for lifetime and survival analysis.

Weibull(scale=λ, concentration=k) generalises both the Exponential (k=1k = 1) and Rayleigh (k=2k = 2) distributions. It is widely used for modelling time-to-failure data because the hazard rate h(t)=(k/λ)(t/λ)k1h(t) = (k/\lambda)(t/\lambda)^{k-1} can increase, be constant, or decrease depending on kk.

Parameters

scaleTensor | float
Scale parameter λ>0\lambda > 0 — a characteristic life value at which the CDF is 1e163.2%1 - e^{-1} \approx 63.2\%.
concentrationTensor | float
Shape parameter k>0k > 0. Values k<1k < 1 give a decreasing hazard (infant mortality); k=1k = 1 is constant (memoryless Exponential); k>1k > 1 gives an increasing hazard (wear-out).
validate_argsbool | None= None
If True, validate parameter constraints at construction time.

Attributes

scaleTensor
Scale parameter λ\lambda.
concentrationTensor
Shape parameter kk.

Notes

PDF:

p(x;λ,k)=kλ(xλ)k1exp ⁣((xλ)k),x0p(x; \lambda, k) = \frac{k}{\lambda} \left(\frac{x}{\lambda}\right)^{k-1} \exp\!\left(-\left(\frac{x}{\lambda}\right)^k\right), \quad x \geq 0

Log-PDF:

logp(x)=logkklogλ+(k1)logx(x/λ)k\log p(x) = \log k - k\log\lambda + (k-1)\log x - (x/\lambda)^k

Moments:

  • Mean: E[X]=λΓ(1+1/k)E[X] = \lambda \,\Gamma(1 + 1/k)
  • Variance: Var[X]=λ2[Γ(1+2/k)Γ(1+1/k)2]\operatorname{Var}[X] = \lambda^2 \left[\Gamma(1+2/k) - \Gamma(1+1/k)^2\right]

Entropy:

H[X]=γ(11k)+log(λ/k)+1H[X] = \gamma\left(1 - \tfrac{1}{k}\right) + \log(\lambda/k) + 1

where γ0.5772\gamma \approx 0.5772 is the Euler–Mascheroni constant.

Reparameterised sampling uses the inverse-CDF: X=λ(log(1U))1/kX = \lambda(-\log(1-U))^{1/k} for UUniform(0,1)U \sim \operatorname{Uniform}(0,1).

Examples

>>> import lucid
>>> from lucid.distributions import Weibull
>>> # Exponential(rate=1) as a special case
>>> dist_exp = Weibull(scale=1.0, concentration=1.0)
>>> dist = Weibull(scale=2.0, concentration=1.5)
>>> samples = dist.rsample((500,))

Methods (7)

dunder

__init__

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

Initialise a Weibull distribution.

Parameters

scaleTensor | float
Scale parameter λ>0\lambda > 0.
concentrationTensor | float
Shape parameter k>0k > 0. Values k<1k < 1 give a decreasing hazard; k=1k = 1 gives the Exponential; k>1k > 1 gives an increasing hazard.
validate_argsbool | None= None
If True, validate parameter constraints at construction time.
prop

support

Constraint
support: Constraint
source

Support of the Weibull distribution: [0,)[0, \infty).

Returns

Constraint

The nonnegative constraint.

prop

mean

Tensor
mean: Tensor
source

Mean of the Weibull distribution: E[X]=λΓ(1+1/k)E[X] = \lambda \Gamma(1 + 1/k).

Returns

Tensor

Mean values of shape batch_shape.

prop

variance

Tensor
variance: Tensor
source

Variance of the Weibull distribution.

Var[X]=λ2[Γ(1+2/k)Γ(1+1/k)2]\operatorname{Var}[X] = \lambda^2 [\Gamma(1+2/k) - \Gamma(1+1/k)^2]

Returns

Tensor

Variance values of shape batch_shape.

fn

rsample

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

Draw reparameterised samples via the inverse-CDF.

Uses X=λ(log(1U))1/kX = \lambda (-\log(1-U))^{1/k} for UUniform(0,1)U \sim \operatorname{Uniform}(0, 1). Gradients propagate through both scale and concentration.

Parameters

sample_shapetuple[int, ...]= ()
Leading shape of the output sample batch.

Returns

Tensor

Non-negative samples of shape (*sample_shape, *batch_shape).

fn

log_prob

Tensor
log_prob(value: Tensor)
source

Log-probability density of the Weibull distribution.

logp(x)=logkklogλ+(k1)logx(x/λ)k\log p(x) = \log k - k\log\lambda + (k-1)\log x - (x/\lambda)^k

Parameters

valueTensor
Non-negative points x0x \geq 0 at which to evaluate.

Returns

Tensor

Log-density values of the same shape as value.

fn

entropy

Tensor
entropy()
source

Entropy of the Weibull distribution.

H[X]=γ(11/k)+log(λ/k)+1H[X] = \gamma(1 - 1/k) + \log(\lambda/k) + 1

where γ0.5772\gamma \approx 0.5772 is the Euler-Mascheroni constant.

Returns

Tensor

Entropy values of shape batch_shape (nats).