WeibullDistribution

class WeibullDistribution(val shape: Double, val scale: Double = 1.0) : ContinuousDistribution(source)

Represents the Weibull distribution.

The Weibull distribution is widely used in reliability engineering, survival analysis, and failure modeling. It generalizes the exponential distribution: when shape equals 1 the Weibull reduces to an exponential distribution with rate 1 / scale. A shape less than 1 indicates a decreasing failure rate (early-life failures), a shape of 1 indicates a constant failure rate (random failures), and a shape greater than 1 indicates an increasing failure rate (wear-out failures).

The distribution is supported on the interval from zero to positive infinity. The scale parameter stretches or compresses the distribution along the x-axis, while the shape parameter controls how steeply the density rises and falls.

Statistical properties (mean, variance, skewness, kurtosis) are computed using the gamma function. The quantile function has a closed-form expression, so sampling is performed via inverse CDF (no iterative root-finding is needed).

Example:

val weibull = WeibullDistribution(shape = 2.0, scale = 1.0)
weibull.pdf(0.5) // 0.7788... (density at x = 0.5)
weibull.cdf(1.0) // 0.6321... (probability that X <= 1)
weibull.quantile(0.5) // 0.8326... (median)
weibull.mean // 0.8862... (gamma(1.5) for shape=2, scale=1)
weibull.sample(Random(42)) // a single random draw from the distribution

Constructors

Link copied to clipboard
constructor(shape: Double, scale: Double = 1.0)

Properties

Link copied to clipboard
open override val entropy: Double

Returns the Shannon entropy of this distribution in nats, using the Euler-Mascheroni constant.

Link copied to clipboard
open override val kurtosis: Double

Returns the excess kurtosis, computed using the gamma function.

Link copied to clipboard
open override val mean: Double

Returns the mean, computed using the gamma function evaluated at 1 + 1/shape.

Link copied to clipboard

the scale parameter (often denoted lambda), stretching the distribution along the x-axis. Must be positive. Defaults to 1.0.

Link copied to clipboard

the shape parameter (often denoted k), controlling the failure rate behavior. Must be positive.

Link copied to clipboard
open override val skewness: Double

Returns the skewness, computed using the gamma function.

Link copied to clipboard
open override val variance: Double

Returns the variance, computed using the gamma function.

Functions

Link copied to clipboard
open override fun cdf(x: Double): Double

Returns the cumulative distribution function value at x.

Link copied to clipboard
open override fun logPdf(x: Double): Double

Returns the natural logarithm of the probability density at x.

Link copied to clipboard
open override fun pdf(x: Double): Double

Returns the probability density at x.

Link copied to clipboard
open override fun quantile(p: Double): Double

Returns the quantile (inverse CDF) for the given probability p.

Link copied to clipboard
open override fun sample(random: Random): Double

Draws a single random value from this Weibull distribution.

Link copied to clipboard
open override fun sf(x: Double): Double

Returns the survival function value at x, equal to 1 - cdf(x).