diff --git a/src/Numerics/Distributions/Beta.cs b/src/Numerics/Distributions/Beta.cs index 8b8a59da..a924f8b2 100644 --- a/src/Numerics/Distributions/Beta.cs +++ b/src/Numerics/Distributions/Beta.cs @@ -92,49 +92,6 @@ 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 random number generator which is used to draw random samples. - /// The Beta distribution derived from the PERT parameters. - public static Beta PERT(double min, double max, double likely, System.Random randomSource = null) - { - 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, randomSource); - } - /// /// A string representation of the distribution. /// diff --git a/src/Numerics/Distributions/BetaScaled.cs b/src/Numerics/Distributions/BetaScaled.cs index f7ec5bcc..2f9f004b 100644 --- a/src/Numerics/Distributions/BetaScaled.cs +++ b/src/Numerics/Distributions/BetaScaled.cs @@ -88,6 +88,49 @@ namespace MathNet.Numerics.Distributions _scale = scale; } + /// + /// 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 random number generator which is used to draw random samples. + /// The Beta distribution derived from the PERT parameters. + public static BetaScaled PERT(double min, double max, double likely, System.Random randomSource = null) + { + 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 BetaScaled(a, b, min, max - min, randomSource); + } + /// /// A string representation of the distribution. ///