diff --git a/src/Numerics/Distributions/NegativeBinomial.cs b/src/Numerics/Distributions/NegativeBinomial.cs index d5cdf08f..8fdd1fb9 100644 --- a/src/Numerics/Distributions/NegativeBinomial.cs +++ b/src/Numerics/Distributions/NegativeBinomial.cs @@ -36,22 +36,22 @@ namespace MathNet.Numerics.Distributions { /// /// Discrete Univariate Negative Binomial distribution. - /// The negative binomial is a distribution over the natural numbers with two parameters r,p. For the special - /// case that r is an integer one can interpret the distribution as the number of tails before the r'th head - /// when the probability of head is p. + /// The negative binomial is a distribution over the natural numbers with two parameters r, p. For the special + /// case that r is an integer one can interpret the distribution as the number of failures before the r'th success + /// when the probability of success is p. /// Wikipedia - NegativeBinomial distribution. /// public class NegativeBinomial : IDiscreteDistribution { System.Random _random; - readonly double _trials; + readonly double _r; readonly double _p; /// /// Initializes a new instance of the class. /// - /// The number of failures (r) until the experiment stopped. Range: r ≥ 0. + /// The number of successes (r) required to stop the experiment. Range: r ≥ 0. /// The probability (p) of a trial resulting in success. Range: 0 ≤ p ≤ 1. public NegativeBinomial(double r, double p) { @@ -62,13 +62,13 @@ namespace MathNet.Numerics.Distributions _random = SystemRandomSource.Default; _p = p; - _trials = r; + _r = r; } /// /// Initializes a new instance of the class. /// - /// The number of failures (r) until the experiment stopped. Range: r ≥ 0. + /// The number of successes (r) required to stop the experiment. Range: r ≥ 0. /// The probability (p) of a trial resulting in success. Range: 0 ≤ p ≤ 1. /// The random number generator which is used to draw random samples. public NegativeBinomial(double r, double p, System.Random randomSource) @@ -80,7 +80,7 @@ namespace MathNet.Numerics.Distributions _random = randomSource ?? SystemRandomSource.Default; _p = p; - _trials = r; + _r = r; } /// @@ -91,13 +91,13 @@ namespace MathNet.Numerics.Distributions /// public override string ToString() { - return "NegativeBinomial(R = " + _trials + ", P = " + _p + ")"; + return "NegativeBinomial(R = " + _r + ", P = " + _p + ")"; } /// /// Tests whether the provided values are valid parameters for this distribution. /// - /// The number of failures (r) until the experiment stopped. Range: r ≥ 0. + /// The number of successes (r) required to stop the experiment. Range: r ≥ 0. /// The probability (p) of a trial resulting in success. Range: 0 ≤ p ≤ 1. public static bool IsValidParameterSet(double r, double p) { @@ -105,11 +105,11 @@ namespace MathNet.Numerics.Distributions } /// - /// Gets the number of trials. Range: r ≥ 0. + /// Gets the number of successes. Range: r ≥ 0. /// public double R { - get { return _trials; } + get { return _r; } } /// @@ -134,7 +134,7 @@ namespace MathNet.Numerics.Distributions /// public double Mean { - get { return _trials*(1.0 - _p)/_p; } + get { return _r*(1.0 - _p)/_p; } } /// @@ -142,7 +142,7 @@ namespace MathNet.Numerics.Distributions /// public double Variance { - get { return _trials*(1.0 - _p)/(_p*_p); } + get { return _r*(1.0 - _p)/(_p*_p); } } /// @@ -150,7 +150,7 @@ namespace MathNet.Numerics.Distributions /// public double StdDev { - get { return Math.Sqrt(_trials*(1.0 - _p))/_p; } + get { return Math.Sqrt(_r*(1.0 - _p))/_p; } } /// @@ -166,7 +166,7 @@ namespace MathNet.Numerics.Distributions /// public double Skewness { - get { return (2.0 - _p)/Math.Sqrt(_trials*(1.0 - _p)); } + get { return (2.0 - _p)/Math.Sqrt(_r*(1.0 - _p)); } } /// @@ -174,7 +174,7 @@ namespace MathNet.Numerics.Distributions /// public int Mode { - get { return _trials > 1.0 ? (int)Math.Floor((_trials - 1.0)*(1.0 - _p)/_p) : 0; } + get { return _r > 1.0 ? (int)Math.Floor((_r - 1.0)*(1.0 - _p)/_p) : 0; } } /// @@ -208,7 +208,7 @@ namespace MathNet.Numerics.Distributions /// the probability mass at location . public double Probability(int k) { - return PMF(_trials, _p, k); + return PMF(_r, _p, k); } /// @@ -218,7 +218,7 @@ namespace MathNet.Numerics.Distributions /// the log probability mass at location . public double ProbabilityLn(int k) { - return PMFLn(_trials, _p, k); + return PMFLn(_r, _p, k); } /// @@ -228,14 +228,14 @@ namespace MathNet.Numerics.Distributions /// the cumulative distribution at location . public double CumulativeDistribution(double x) { - return CDF(_trials, _p, x); + return CDF(_r, _p, x); } /// /// Computes the probability mass (PMF) at k, i.e. P(X = k). /// /// The location in the domain where we want to evaluate the probability mass function. - /// The number of failures (r) until the experiment stopped. Range: r ≥ 0. + /// The number of successes (r) required to stop the experiment. Range: r ≥ 0. /// The probability (p) of a trial resulting in success. Range: 0 ≤ p ≤ 1. /// the probability mass at location . public static double PMF(double r, double p, int k) @@ -247,7 +247,7 @@ namespace MathNet.Numerics.Distributions /// Computes the log probability mass (lnPMF) at k, i.e. ln(P(X = k)). /// /// The location in the domain where we want to evaluate the log probability mass function. - /// The number of failures (r) until the experiment stopped. Range: r ≥ 0. + /// The number of successes (r) required to stop the experiment. Range: r ≥ 0. /// The probability (p) of a trial resulting in success. Range: 0 ≤ p ≤ 1. /// the log probability mass at location . public static double PMFLn(double r, double p, int k) @@ -268,7 +268,7 @@ namespace MathNet.Numerics.Distributions /// Computes the cumulative distribution (CDF) of the distribution at x, i.e. P(X ≤ x). /// /// The location at which to compute the cumulative distribution function. - /// The number of failures (r) until the experiment stopped. Range: r ≥ 0. + /// The number of successes (r) required to stop the experiment. Range: r ≥ 0. /// The probability (p) of a trial resulting in success. Range: 0 ≤ p ≤ 1. /// the cumulative distribution at location . /// @@ -286,7 +286,7 @@ namespace MathNet.Numerics.Distributions /// Samples a negative binomial distributed random variable. /// /// The random number generator to use. - /// The number of failures (r) until the experiment stopped. Range: r ≥ 0. + /// The number of successes (r) required to stop the experiment. Range: r ≥ 0. /// The probability (p) of a trial resulting in success. Range: 0 ≤ p ≤ 1. /// a sample from the distribution. static int SampleUnchecked(System.Random rnd, double r, double p) @@ -326,7 +326,7 @@ namespace MathNet.Numerics.Distributions /// a sample from the distribution. public int Sample() { - return SampleUnchecked(_random, _trials, _p); + return SampleUnchecked(_random, _r, _p); } /// @@ -334,7 +334,7 @@ namespace MathNet.Numerics.Distributions /// public void Samples(int[] values) { - SamplesUnchecked(_random, values, _trials, _p); + SamplesUnchecked(_random, values, _r, _p); } /// @@ -343,14 +343,14 @@ namespace MathNet.Numerics.Distributions /// a sequence of samples from the distribution. public IEnumerable Samples() { - return SamplesUnchecked(_random, _trials, _p); + return SamplesUnchecked(_random, _r, _p); } /// /// Samples a random variable. /// /// The random number generator to use. - /// The number of failures (r) until the experiment stopped. Range: r ≥ 0. + /// The number of successes (r) required to stop the experiment. Range: r ≥ 0. /// The probability (p) of a trial resulting in success. Range: 0 ≤ p ≤ 1. public static int Sample(System.Random rnd, double r, double p) { @@ -366,7 +366,7 @@ namespace MathNet.Numerics.Distributions /// Samples a sequence of this random variable. /// /// The random number generator to use. - /// The number of failures (r) until the experiment stopped. Range: r ≥ 0. + /// The number of successes (r) required to stop the experiment. Range: r ≥ 0. /// The probability (p) of a trial resulting in success. Range: 0 ≤ p ≤ 1. public static IEnumerable Samples(System.Random rnd, double r, double p) { @@ -383,7 +383,7 @@ namespace MathNet.Numerics.Distributions /// /// The random number generator to use. /// The array to fill with the samples. - /// The number of failures (r) until the experiment stopped. Range: r ≥ 0. + /// The number of successes (r) required to stop the experiment. Range: r ≥ 0. /// The probability (p) of a trial resulting in success. Range: 0 ≤ p ≤ 1. public static void Samples(System.Random rnd, int[] values, double r, double p) { @@ -398,7 +398,7 @@ namespace MathNet.Numerics.Distributions /// /// Samples a random variable. /// - /// The number of failures (r) until the experiment stopped. Range: r ≥ 0. + /// The number of successes (r) required to stop the experiment. Range: r ≥ 0. /// The probability (p) of a trial resulting in success. Range: 0 ≤ p ≤ 1. public static int Sample(double r, double p) { @@ -413,7 +413,7 @@ namespace MathNet.Numerics.Distributions /// /// Samples a sequence of this random variable. /// - /// The number of failures (r) until the experiment stopped. Range: r ≥ 0. + /// The number of successes (r) required to stop the experiment. Range: r ≥ 0. /// The probability (p) of a trial resulting in success. Range: 0 ≤ p ≤ 1. public static IEnumerable Samples(double r, double p) { @@ -429,7 +429,7 @@ namespace MathNet.Numerics.Distributions /// Fills an array with samples generated from the distribution. /// /// The array to fill with the samples. - /// The number of failures (r) until the experiment stopped. Range: r ≥ 0. + /// The number of successes (r) required to stop the experiment. Range: r ≥ 0. /// The probability (p) of a trial resulting in success. Range: 0 ≤ p ≤ 1. public static void Samples(int[] values, double r, double p) {