...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
#include <boost/math/distributions/weibull.hpp>
namespace boost{ namespace math{ template <class RealType = double, class Policy = policies::policy<> > class weibull_distribution; typedef weibull_distribution<> weibull; template <class RealType, class Policy> class weibull_distribution { public: typedef RealType value_type; typedef Policy policy_type; // Construct: BOOST_MATH_GPU_ENABLED weibull_distribution(RealType shape, RealType scale = 1) // Accessors: BOOST_MATH_GPU_ENABLED RealType shape()const; BOOST_MATH_GPU_ENABLED RealType scale()const; }; }} // namespaces
The Weibull distribution is a continuous distribution with the probability density function:
f(x; α, β) = (α/β) * (x / β)α - 1 * e-(x/β)α
For shape parameter α > 0, and scale parameter β > 0, and x > 0.
The Weibull distribution is often used in the field of failure analysis; in particular it can mimic distributions where the failure rate varies over time. If the failure rate is:
The following graph illustrates how the PDF varies with the shape parameter α:
While this graph illustrates how the PDF varies with the scale parameter β:
When α = 3, the Weibull distribution appears similar to the normal distribution. When α = 1, the Weibull distribution reduces to the exponential distribution. The relationship of the types of extreme value distributions, of which the Weibull is but one, is discussed by Extreme Value Distributions, Theory and Applications Samuel Kotz & Saralees Nadarajah.
BOOST_MATH_GPU_ENABLED weibull_distribution(RealType shape, RealType scale = 1);
Constructs a Weibull distribution with shape shape and scale scale.
Requires that the shape and scale parameters are both greater than zero, otherwise calls domain_error.
BOOST_MATH_GPU_ENABLED RealType shape()const;
Returns the shape parameter of this distribution.
BOOST_MATH_GPU_ENABLED RealType scale()const;
Returns the scale parameter of this distribution.
All the usual non-member accessor
functions that are generic to all distributions are supported:
Cumulative Distribution Function,
Probability Density Function,
Quantile, Hazard Function, Cumulative Hazard Function,
__logcdf, __logpdf, mean,
median, mode,
variance, standard deviation, skewness, kurtosis,
kurtosis_excess,
range and support. For this distribution
all non-member accessor functions are marked with BOOST_MATH_GPU_ENABLED
and can be run on both host and device.
The domain of the random variable is [0, ∞].
In this distribution the implementation of both logcdf
,
and logpdf
are specialized
to improve numerical accuracy.
The Weibull distribution is implemented in terms of the standard library
log
and exp
functions plus expm1 and
log1p and as such should
have very low error rates.
In the following table α is the shape parameter of the distribution, β is its scale parameter, x is the random variate, p is the probability and q = 1-p.
Function |
Implementation Notes |
---|---|
|
Using the relation: pdf = αβ-α xα - 1 e-(x/beta)alpha |
logpdf |
log(pdf) = log(α) - α * log(β) + log(x) * (α-1) - pow(x/β, α) |
cdf |
Using the relation: p = -expm1(-(x/β)α) |
logcdf |
log(cdf) = log1p(-exp(-pow(x / β, α))) |
cdf complement |
Using the relation: q = e-(x/β)α |
quantile |
Using the relation: x = β * (-log1p(-p))1/α |
quantile from the complement |
Using the relation: x = β * (-log(q))1/α |
mean |
β * Γ(1 + 1/α) |
variance |
β2(Γ(1 + 2/α) - Γ2(1 + 1/α)) |
mode |
β((α - 1) / α)1/α |
skewness |
Refer to Weisstein, Eric W. "Weibull Distribution." From MathWorld--A Wolfram Web Resource. |
kurtosis |
Refer to Weisstein, Eric W. "Weibull Distribution." From MathWorld--A Wolfram Web Resource. |
kurtosis excess |
Refer to Weisstein, Eric W. "Weibull Distribution." From MathWorld--A Wolfram Web Resource. |