diff --git a/src/Numerics/Distributions/Beta.cs b/src/Numerics/Distributions/Beta.cs index 8e51fd7d..3e89eb25 100644 --- a/src/Numerics/Distributions/Beta.cs +++ b/src/Numerics/Distributions/Beta.cs @@ -92,6 +92,48 @@ namespace MathNet.Numerics.Distributions _shapeB = b; } + + /// + /// Create a Beta PERT distribution, used in risk analysis and other domains where an expert forecast + /// is used to construct an underlying beta distribution. + /// + /// The minimum value. + /// The maximum value. + /// The most likely value (mode). + /// The Beta distribution derived from the PERT parameters. + public static Beta PERT(double min, double max, double likely) + { + if( min > max || likely > max || likely < min ) + { + throw new ArgumentException(Resources.InvalidDistributionParameters); + } + + // specified to make the formulas match the literature; + // traditionally set to 4 so that the range between min and max + // represents six standard deviations (sometimes called + // "the six-sigma assumption"). + const double lambda = 4; + + // calculate the mean + double mean = (min + max + lambda * likely) / (lambda + 2); + + // derive the shape parameters a and b + double a; + // special case where mean and mode are identical + if (mean == likely) + { + a = (lambda/2) + 1; + } + else + { + a = ((mean - min) * (2 * likely - min - max)) / ((likely - mean) * (max - min)) + } + + double b = (a * (max - mean)) / (mean - min); + + return new Beta(a, b); + } + /// /// A string representation of the distribution. ///