WeibullDistribution
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