Skip to content
class

Weibull

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

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/λ)k−1h(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 1−e−1≈63.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λ)k−1exp⁡ ⁣(−(xλ)k),x>0p(x; \lambda, k) = \frac{k}{\lambda} \left(\frac{x}{\lambda}\right)^{k-1} \exp\!\left(-\left(\frac{x}{\lambda}\right)^k\right), \quad x > 0

Log-PDF:

log⁡p(x)=log⁡k−klog⁡λ+(k−1)log⁡x−(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]=γ(1−1k)+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⁡(1−U))1/kX = \lambda(-\log(1-U))^{1/k} for U∼Uniform⁡(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,))

Used by 2

Constructors

1
dunder

__init__

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

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.

Properties

4
prop

mean

→Tensor
mean: Tensor

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

mode

→Tensor
mode: Tensor

Mode of the Weibull distribution.

λ(k−1k)1/k(k>1),0(k≤1)\lambda \left(\frac{k - 1}{k}\right)^{1/k} \quad (k > 1), \qquad 0 \quad (k \leq 1)

For k≤1k \leq 1 the density decreases from the origin, so the mode is 0. The reference framework evaluates the first formula there too and answers nan or a meaningless positive number; this answers 0.

prop

support

→Constraint
support: Constraint

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

Returns

Constraint

The positive constraint, as in the reference framework. At 0 the density is infinite for k<1k < 1 and 0 for k>1k > 1, and the closed form is not evaluated there.

prop

variance

→Tensor
variance: Tensor

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.

Instance methods

6
fn

cdf

→Tensor
cdf(value: Tensor)

Cumulative distribution function of the Weibull distribution.

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

The Exponential(1) CDF at (x/λ)k(x/\lambda)^k; 0 below 0.

Returns probabilities in [0,1][0, 1].

Examples

>>> Weibull(scale=1.0, concentration=1.0).cdf(lucid.tensor(1.0))
tensor(0.6321)
fn

entropy

→Tensor
entropy()

Entropy of the Weibull distribution.

H[X]=γ(1−1/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).

fn

expand

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

Return a new Weibull with batch dimensions expanded to batch_shape.

fn

icdf

→Tensor
icdf(value: Tensor)

Quantile function of the Weibull distribution.

Q(p)=λ(−ln⁡(1−p))1/kQ(p) = \lambda \left(-\ln(1 - p)\right)^{1/k}

Returns quantiles in [0,∞][0, \infty].

Examples

>>> Weibull(scale=2.0, concentration=1.0).icdf(lucid.tensor(0.5))
tensor(1.386)
fn

log_prob

→Tensor
log_prob(value: Tensor)

Log-probability density of the Weibull distribution.

log⁡p(x)=log⁡k−klog⁡λ+(k−1)log⁡x−(x/λ)k\log p(x) = \log k - k\log\lambda + (k-1)\log x - (x/\lambda)^k

Parameters

valueTensor
Positive points x>0x > 0 at which to evaluate.

Returns

Tensor

Log-density values of the same shape as value.

fn

rsample

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

Draw reparameterised samples via the inverse-CDF.

Uses X=λ(−log⁡(1−U))1/kX = \lambda (-\log(1-U))^{1/k} for U∼Uniform⁡(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).