Browse Source

Distributions: inline docs, range information

optimization-1
Christoph Ruegg 13 years ago
parent
commit
1a8c5cc42a
  1. 18
      src/Numerics/Distributions/Bernoulli.cs
  2. 160
      src/Numerics/Distributions/Beta.cs
  3. 131
      src/Numerics/Distributions/Binomial.cs
  4. 18
      src/Numerics/Distributions/Cauchy.cs
  5. 16
      src/Numerics/Distributions/Chi.cs
  6. 18
      src/Numerics/Distributions/ChiSquared.cs
  7. 28
      src/Numerics/Distributions/ContinuousUniform.cs
  8. 32
      src/Numerics/Distributions/ConwayMaxwellPoisson.cs
  9. 28
      src/Numerics/Distributions/DiscreteUniform.cs
  10. 62
      src/Numerics/Distributions/Erlang.cs
  11. 16
      src/Numerics/Distributions/Exponential.cs
  12. 32
      src/Numerics/Distributions/FisherSnedecor.cs
  13. 40
      src/Numerics/Distributions/Gamma.cs
  14. 30
      src/Numerics/Distributions/Geometric.cs
  15. 32
      src/Numerics/Distributions/InverseGamma.cs
  16. 30
      src/Numerics/Distributions/Laplace.cs
  17. 32
      src/Numerics/Distributions/NegativeBinomial.cs
  18. 32
      src/Numerics/Distributions/Pareto.cs
  19. 20
      src/Numerics/Distributions/Poisson.cs
  20. 16
      src/Numerics/Distributions/Rayleigh.cs
  21. 48
      src/Numerics/Distributions/Stable.cs
  22. 32
      src/Numerics/Distributions/StudentT.cs
  23. 32
      src/Numerics/Distributions/Weibull.cs

18
src/Numerics/Distributions/Bernoulli.cs

@ -54,7 +54,7 @@ namespace MathNet.Numerics.Distributions
/// <summary> /// <summary>
/// Initializes a new instance of the Bernoulli class. /// Initializes a new instance of the Bernoulli class.
/// </summary> /// </summary>
/// <param name="p">The probability of generating one.</param> /// <param name="p">The probability (p) of generating one. Range: 0 ≤ p ≤ 1.</param>
/// <exception cref="ArgumentOutOfRangeException">If the Bernoulli parameter is not in the range [0,1].</exception> /// <exception cref="ArgumentOutOfRangeException">If the Bernoulli parameter is not in the range [0,1].</exception>
public Bernoulli(double p) public Bernoulli(double p)
{ {
@ -65,7 +65,7 @@ namespace MathNet.Numerics.Distributions
/// <summary> /// <summary>
/// Initializes a new instance of the Bernoulli class. /// Initializes a new instance of the Bernoulli class.
/// </summary> /// </summary>
/// <param name="p">The probability of generating one.</param> /// <param name="p">The probability (p) of generating one. Range: 0 ≤ p ≤ 1.</param>
/// <param name="randomSource">The random number generator which is used to draw random samples.</param> /// <param name="randomSource">The random number generator which is used to draw random samples.</param>
/// <exception cref="ArgumentOutOfRangeException">If the Bernoulli parameter is not in the range [0,1].</exception> /// <exception cref="ArgumentOutOfRangeException">If the Bernoulli parameter is not in the range [0,1].</exception>
public Bernoulli(double p, System.Random randomSource) public Bernoulli(double p, System.Random randomSource)
@ -80,13 +80,13 @@ namespace MathNet.Numerics.Distributions
/// <returns>a string representation of the distribution.</returns> /// <returns>a string representation of the distribution.</returns>
public override string ToString() public override string ToString()
{ {
return "Bernoulli(P = " + _p + ")"; return "Bernoulli(p = " + _p + ")";
} }
/// <summary> /// <summary>
/// Checks whether the parameters of the distribution are valid. /// Checks whether the parameters of the distribution are valid.
/// </summary> /// </summary>
/// <param name="p">The probability of generating a one.</param> /// <param name="p">The probability (p) of generating one. Range: 0 ≤ p ≤ 1.</param>
/// <returns><c>true</c> when the parameters are valid, <c>false</c> otherwise.</returns> /// <returns><c>true</c> when the parameters are valid, <c>false</c> otherwise.</returns>
static bool IsValidParameterSet(double p) static bool IsValidParameterSet(double p)
{ {
@ -96,7 +96,7 @@ namespace MathNet.Numerics.Distributions
/// <summary> /// <summary>
/// Sets the parameters of the distribution after checking their validity. /// Sets the parameters of the distribution after checking their validity.
/// </summary> /// </summary>
/// <param name="p">The probability of generating a one.</param> /// <param name="p">The probability (p) of generating one. Range: 0 ≤ p ≤ 1.</param>
/// <exception cref="ArgumentOutOfRangeException">When the parameters are out of range.</exception> /// <exception cref="ArgumentOutOfRangeException">When the parameters are out of range.</exception>
void SetParameters(double p) void SetParameters(double p)
{ {
@ -109,7 +109,7 @@ namespace MathNet.Numerics.Distributions
} }
/// <summary> /// <summary>
/// Gets or sets the probability of generating a one. /// Gets or sets the probability of generating a one. Range: 0 ≤ p ≤ 1.
/// </summary> /// </summary>
public double P public double P
{ {
@ -257,7 +257,7 @@ namespace MathNet.Numerics.Distributions
/// Generates one sample from the Bernoulli distribution. /// Generates one sample from the Bernoulli distribution.
/// </summary> /// </summary>
/// <param name="rnd">The random source to use.</param> /// <param name="rnd">The random source to use.</param>
/// <param name="p">The probability of generating a one.</param> /// <param name="p">The probability (p) of generating one. Range: 0 ≤ p ≤ 1.</param>
/// <returns>A random sample from the Bernoulli distribution.</returns> /// <returns>A random sample from the Bernoulli distribution.</returns>
static int SampleUnchecked(System.Random rnd, double p) static int SampleUnchecked(System.Random rnd, double p)
{ {
@ -294,7 +294,7 @@ namespace MathNet.Numerics.Distributions
/// Samples a Bernoulli distributed random variable. /// Samples a Bernoulli distributed random variable.
/// </summary> /// </summary>
/// <param name="rnd">The random number generator to use.</param> /// <param name="rnd">The random number generator to use.</param>
/// <param name="p">The probability of generating a 1.</param> /// <param name="p">The probability (p) of generating one. Range: 0 ≤ p ≤ 1.</param>
/// <returns>A sample from the Bernoulli distribution.</returns> /// <returns>A sample from the Bernoulli distribution.</returns>
public static int Sample(System.Random rnd, double p) public static int Sample(System.Random rnd, double p)
{ {
@ -310,7 +310,7 @@ namespace MathNet.Numerics.Distributions
/// Samples a sequence of Bernoulli distributed random variables. /// Samples a sequence of Bernoulli distributed random variables.
/// </summary> /// </summary>
/// <param name="rnd">The random number generator to use.</param> /// <param name="rnd">The random number generator to use.</param>
/// <param name="p">The probability of generating a 1.</param> /// <param name="p">The probability (p) of generating one. Range: 0 ≤ p ≤ 1.</param>
/// <returns>a sequence of samples from the distribution.</returns> /// <returns>a sequence of samples from the distribution.</returns>
public static IEnumerable<int> Samples(System.Random rnd, double p) public static IEnumerable<int> Samples(System.Random rnd, double p)
{ {

160
src/Numerics/Distributions/Beta.cs

@ -61,8 +61,8 @@ namespace MathNet.Numerics.Distributions
/// <summary> /// <summary>
/// Initializes a new instance of the Beta class. /// Initializes a new instance of the Beta class.
/// </summary> /// </summary>
/// <param name="a">The α shape parameter of the Beta distribution.</param> /// <param name="a">The α shape parameter of the Beta distribution. Range: α ≥ 0.</param>
/// <param name="b">The β shape parameter of the Beta distribution.</param> /// <param name="b">The β shape parameter of the Beta distribution. Range: β ≥ 0.</param>
/// <exception cref="ArgumentOutOfRangeException">If any of the Beta parameters are negative.</exception> /// <exception cref="ArgumentOutOfRangeException">If any of the Beta parameters are negative.</exception>
public Beta(double a, double b) public Beta(double a, double b)
{ {
@ -73,8 +73,8 @@ namespace MathNet.Numerics.Distributions
/// <summary> /// <summary>
/// Initializes a new instance of the Beta class. /// Initializes a new instance of the Beta class.
/// </summary> /// </summary>
/// <param name="a">The α shape parameter of the Beta distribution.</param> /// <param name="a">The α shape parameter of the Beta distribution. Range: α ≥ 0.</param>
/// <param name="b">The β shape parameter of the Beta distribution.</param> /// <param name="b">The β shape parameter of the Beta distribution. Range: β ≥ 0.</param>
/// <param name="randomSource">The random number generator which is used to draw random samples.</param> /// <param name="randomSource">The random number generator which is used to draw random samples.</param>
/// <exception cref="ArgumentOutOfRangeException">If any of the Beta parameters are negative.</exception> /// <exception cref="ArgumentOutOfRangeException">If any of the Beta parameters are negative.</exception>
public Beta(double a, double b, System.Random randomSource) public Beta(double a, double b, System.Random randomSource)
@ -95,8 +95,8 @@ namespace MathNet.Numerics.Distributions
/// <summary> /// <summary>
/// Checks whether the parameters of the distribution are valid. /// Checks whether the parameters of the distribution are valid.
/// </summary> /// </summary>
/// <param name="a">The α shape parameter of the Beta distribution.</param> /// <param name="a">The α shape parameter of the Beta distribution. Range: α ≥ 0.</param>
/// <param name="b">The β shape parameter of the Beta distribution.</param> /// <param name="b">The β shape parameter of the Beta distribution. Range: β ≥ 0.</param>
/// <returns><c>true</c> when the parameters are valid, <c>false</c> otherwise.</returns> /// <returns><c>true</c> when the parameters are valid, <c>false</c> otherwise.</returns>
static bool IsValidParameterSet(double a, double b) static bool IsValidParameterSet(double a, double b)
{ {
@ -106,8 +106,8 @@ namespace MathNet.Numerics.Distributions
/// <summary> /// <summary>
/// Sets the parameters of the distribution after checking their validity. /// Sets the parameters of the distribution after checking their validity.
/// </summary> /// </summary>
/// <param name="a">The α shape parameter of the Beta distribution.</param> /// <param name="a">The α shape parameter of the Beta distribution. Range: α ≥ 0.</param>
/// <param name="b">The β shape parameter of the Beta distribution.</param> /// <param name="b">The β shape parameter of the Beta distribution. Range: β ≥ 0.</param>
/// <exception cref="ArgumentOutOfRangeException">When the parameters are out of range.</exception> /// <exception cref="ArgumentOutOfRangeException">When the parameters are out of range.</exception>
void SetParameters(double a, double b) void SetParameters(double a, double b)
{ {
@ -121,7 +121,7 @@ namespace MathNet.Numerics.Distributions
} }
/// <summary> /// <summary>
/// Gets or sets the α shape parameter of the Beta distribution. /// Gets or sets the α shape parameter of the Beta distribution. Range: α ≥ 0.
/// </summary> /// </summary>
public double A public double A
{ {
@ -130,7 +130,7 @@ namespace MathNet.Numerics.Distributions
} }
/// <summary> /// <summary>
/// Gets or sets the β shape parameter of the Beta distribution. /// Gets or sets the β shape parameter of the Beta distribution. Range: β ≥ 0.
/// </summary> /// </summary>
public double B public double B
{ {
@ -154,20 +154,9 @@ namespace MathNet.Numerics.Distributions
{ {
get get
{ {
if (_shapeA == 0.0 && _shapeB == 0.0) if (_shapeA == 0.0 && _shapeB == 0.0) return 0.5;
{ if (_shapeA == 0.0) return 0.0;
return 0.5; if (_shapeB == 0.0) return 1.0;
}
if (_shapeA == 0.0)
{
return 0.0;
}
if (_shapeB == 0.0)
{
return 1.0;
}
if (Double.IsPositiveInfinity(_shapeA) && Double.IsPositiveInfinity(_shapeB)) if (Double.IsPositiveInfinity(_shapeA) && Double.IsPositiveInfinity(_shapeB))
{ {
@ -255,20 +244,9 @@ namespace MathNet.Numerics.Distributions
return 2.0; return 2.0;
} }
if (_shapeA == 0.0 && _shapeB == 0.0) if (_shapeA == 0.0 && _shapeB == 0.0) return 0.0;
{ if (_shapeA == 0.0) return 2.0;
return 0.0; if (_shapeB == 0.0) return -2.0;
}
if (_shapeA == 0.0)
{
return 2.0;
}
if (_shapeB == 0.0)
{
return -2.0;
}
return 2.0*(_shapeB - _shapeA)*Math.Sqrt(_shapeA + _shapeB + 1.0) return 2.0*(_shapeB - _shapeA)*Math.Sqrt(_shapeA + _shapeB + 1.0)
/((_shapeA + _shapeB + 2.0)*Math.Sqrt(_shapeA*_shapeB)); /((_shapeA + _shapeB + 2.0)*Math.Sqrt(_shapeA*_shapeB));
@ -282,20 +260,9 @@ namespace MathNet.Numerics.Distributions
{ {
get get
{ {
if (_shapeA == 0.0 && _shapeB == 0.0) if (_shapeA == 0.0 && _shapeB == 0.0) return 0.5;
{ if (_shapeA == 0.0) return 0.0;
return 0.5; if (_shapeB == 0.0) return 1.0;
}
if (_shapeA == 0.0)
{
return 0.0;
}
if (_shapeB == 0.0)
{
return 1.0;
}
if (Double.IsPositiveInfinity(_shapeA) && Double.IsPositiveInfinity(_shapeB)) if (Double.IsPositiveInfinity(_shapeA) && Double.IsPositiveInfinity(_shapeB))
{ {
@ -312,10 +279,7 @@ namespace MathNet.Numerics.Distributions
return 0.0; return 0.0;
} }
if (_shapeA == 1.0 && _shapeB == 1.0) if (_shapeA == 1.0 && _shapeB == 1.0) return 0.5;
{
return 0.5;
}
return (_shapeA - 1)/(_shapeA + _shapeB - 2); return (_shapeA - 1)/(_shapeA + _shapeB - 2);
} }
@ -352,10 +316,7 @@ namespace MathNet.Numerics.Distributions
/// <returns>the density at <paramref name="x"/>.</returns> /// <returns>the density at <paramref name="x"/>.</returns>
public double Density(double x) public double Density(double x)
{ {
if (x < 0.0 || x > 1.0) if (x < 0.0 || x > 1.0) return 0.0;
{
return 0.0;
}
if (Double.IsPositiveInfinity(_shapeA) && Double.IsPositiveInfinity(_shapeB)) if (Double.IsPositiveInfinity(_shapeA) && Double.IsPositiveInfinity(_shapeB))
{ {
@ -382,20 +343,9 @@ namespace MathNet.Numerics.Distributions
return 0.0; return 0.0;
} }
if (_shapeA == 0.0) if (_shapeA == 0.0) return x == 0.0 ? Double.PositiveInfinity : 0.0;
{ if (_shapeB == 0.0) return x == 1.0 ? Double.PositiveInfinity : 0.0;
return x == 0.0 ? Double.PositiveInfinity : 0.0; if (_shapeA == 1.0 && _shapeB == 1.0) return 1.0;
}
if (_shapeB == 0.0)
{
return x == 1.0 ? Double.PositiveInfinity : 0.0;
}
if (_shapeA == 1.0 && _shapeB == 1.0)
{
return 1.0;
}
var b = SpecialFunctions.Gamma(_shapeA + _shapeB)/(SpecialFunctions.Gamma(_shapeA)*SpecialFunctions.Gamma(_shapeB)); var b = SpecialFunctions.Gamma(_shapeA + _shapeB)/(SpecialFunctions.Gamma(_shapeA)*SpecialFunctions.Gamma(_shapeB));
return b*Math.Pow(x, _shapeA - 1.0)*Math.Pow(1.0 - x, _shapeB - 1.0); return b*Math.Pow(x, _shapeA - 1.0)*Math.Pow(1.0 - x, _shapeB - 1.0);
@ -408,10 +358,7 @@ namespace MathNet.Numerics.Distributions
/// <returns>the log density at <paramref name="x"/>.</returns> /// <returns>the log density at <paramref name="x"/>.</returns>
public double DensityLn(double x) public double DensityLn(double x)
{ {
if (x < 0.0 || x > 1.0) if (x < 0.0 || x > 1.0) return Double.NegativeInfinity;
{
return Double.NegativeInfinity;
}
if (Double.IsPositiveInfinity(_shapeA) && Double.IsPositiveInfinity(_shapeB)) if (Double.IsPositiveInfinity(_shapeA) && Double.IsPositiveInfinity(_shapeB))
{ {
@ -438,20 +385,9 @@ namespace MathNet.Numerics.Distributions
return Double.NegativeInfinity; return Double.NegativeInfinity;
} }
if (_shapeA == 0.0) if (_shapeA == 0.0) return x == 0.0 ? Double.PositiveInfinity : Double.NegativeInfinity;
{ if (_shapeB == 0.0) return x == 1.0 ? Double.PositiveInfinity : Double.NegativeInfinity;
return x == 0.0 ? Double.PositiveInfinity : Double.NegativeInfinity; if (_shapeA == 1.0 && _shapeB == 1.0) return 0.0;
}
if (_shapeB == 0.0)
{
return x == 1.0 ? Double.PositiveInfinity : Double.NegativeInfinity;
}
if (_shapeA == 1.0 && _shapeB == 1.0)
{
return 0.0;
}
var a = SpecialFunctions.GammaLn(_shapeA + _shapeB) - SpecialFunctions.GammaLn(_shapeA) - SpecialFunctions.GammaLn(_shapeB); var a = SpecialFunctions.GammaLn(_shapeA + _shapeB) - SpecialFunctions.GammaLn(_shapeA) - SpecialFunctions.GammaLn(_shapeB);
var b = x == 0.0 ? (_shapeA == 1.0 ? 0.0 : Double.NegativeInfinity) : (_shapeA - 1.0)*Math.Log(x); var b = x == 0.0 ? (_shapeA == 1.0 ? 0.0 : Double.NegativeInfinity) : (_shapeA - 1.0)*Math.Log(x);
@ -467,15 +403,8 @@ namespace MathNet.Numerics.Distributions
/// <returns>the cumulative distribution at location <paramref name="x"/>.</returns> /// <returns>the cumulative distribution at location <paramref name="x"/>.</returns>
public double CumulativeDistribution(double x) public double CumulativeDistribution(double x)
{ {
if (x < 0.0) if (x < 0.0) return 0.0;
{ if (x >= 1.0) return 1.0;
return 0.0;
}
if (x >= 1.0)
{
return 1.0;
}
if (Double.IsPositiveInfinity(_shapeA) && Double.IsPositiveInfinity(_shapeB)) if (Double.IsPositiveInfinity(_shapeA) && Double.IsPositiveInfinity(_shapeB))
{ {
@ -502,20 +431,9 @@ namespace MathNet.Numerics.Distributions
return 1.0; return 1.0;
} }
if (_shapeA == 0.0) if (_shapeA == 0.0) return 1.0;
{ if (_shapeB == 0.0) return x >= 1.0 ? 1.0 : 0.0;
return 1.0; if (_shapeA == 1.0 && _shapeB == 1.0) return x;
}
if (_shapeB == 0.0)
{
return x >= 1.0 ? 1.0 : 0.0;
}
if (_shapeA == 1.0 && _shapeB == 1.0)
{
return x;
}
return SpecialFunctions.BetaRegularized(_shapeA, _shapeB, x); return SpecialFunctions.BetaRegularized(_shapeA, _shapeB, x);
} }
@ -524,8 +442,8 @@ namespace MathNet.Numerics.Distributions
/// Samples Beta distributed random variables by sampling two Gamma variables and normalizing. /// Samples Beta distributed random variables by sampling two Gamma variables and normalizing.
/// </summary> /// </summary>
/// <param name="rnd">The random number generator to use.</param> /// <param name="rnd">The random number generator to use.</param>
/// <param name="a">The α shape parameter of the Beta distribution.</param> /// <param name="a">The α shape parameter of the Beta distribution. Range: α ≥ 0.</param>
/// <param name="b">The β shape parameter of the Beta distribution.</param> /// <param name="b">The β shape parameter of the Beta distribution. Range: β ≥ 0.</param>
/// <returns>a random number from the Beta distribution.</returns> /// <returns>a random number from the Beta distribution.</returns>
static double SampleUnchecked(System.Random rnd, double a, double b) static double SampleUnchecked(System.Random rnd, double a, double b)
{ {
@ -559,8 +477,8 @@ namespace MathNet.Numerics.Distributions
/// Generates a sample from the distribution. /// Generates a sample from the distribution.
/// </summary> /// </summary>
/// <param name="rnd">The random number generator to use.</param> /// <param name="rnd">The random number generator to use.</param>
/// <param name="a">The α shape parameter of the Beta distribution.</param> /// <param name="a">The α shape parameter of the Beta distribution. Range: α ≥ 0.</param>
/// <param name="b">The β shape parameter of the Beta distribution.</param> /// <param name="b">The β shape parameter of the Beta distribution. Range: β ≥ 0.</param>
/// <returns>a sample from the distribution.</returns> /// <returns>a sample from the distribution.</returns>
public static double Sample(System.Random rnd, double a, double b) public static double Sample(System.Random rnd, double a, double b)
{ {
@ -576,8 +494,8 @@ namespace MathNet.Numerics.Distributions
/// Generates a sequence of samples from the distribution. /// Generates a sequence of samples from the distribution.
/// </summary> /// </summary>
/// <param name="rnd">The random number generator to use.</param> /// <param name="rnd">The random number generator to use.</param>
/// <param name="a">The α shape parameter of the Beta distribution.</param> /// <param name="a">The α shape parameter of the Beta distribution. Range: α ≥ 0.</param>
/// <param name="b">The β shape parameter of the Beta distribution.</param> /// <param name="b">The β shape parameter of the Beta distribution. Range: β ≥ 0.</param>
/// <returns>a sequence of samples from the distribution.</returns> /// <returns>a sequence of samples from the distribution.</returns>
public static IEnumerable<double> Samples(System.Random rnd, double a, double b) public static IEnumerable<double> Samples(System.Random rnd, double a, double b)
{ {

131
src/Numerics/Distributions/Binomial.cs

@ -55,8 +55,8 @@ namespace MathNet.Numerics.Distributions
/// <summary> /// <summary>
/// Initializes a new instance of the Binomial class. /// Initializes a new instance of the Binomial class.
/// </summary> /// </summary>
/// <param name="p">The success probability in each trial.</param> /// <param name="p">The success probability (p) in each trial. Range: 0 ≤ p ≤ 1.</param>
/// <param name="n">The number of trials.</param> /// <param name="n">The number of trials (n). Range: n ≥ 0.</param>
/// <exception cref="ArgumentOutOfRangeException">If <paramref name="p"/> is not in the interval [0.0,1.0].</exception> /// <exception cref="ArgumentOutOfRangeException">If <paramref name="p"/> is not in the interval [0.0,1.0].</exception>
/// <exception cref="ArgumentOutOfRangeException">If <paramref name="n"/> is negative.</exception> /// <exception cref="ArgumentOutOfRangeException">If <paramref name="n"/> is negative.</exception>
public Binomial(double p, int n) public Binomial(double p, int n)
@ -68,8 +68,8 @@ namespace MathNet.Numerics.Distributions
/// <summary> /// <summary>
/// Initializes a new instance of the Binomial class. /// Initializes a new instance of the Binomial class.
/// </summary> /// </summary>
/// <param name="p">The success probability in each trial.</param> /// <param name="p">The success probability (p) in each trial. Range: 0 ≤ p ≤ 1.</param>
/// <param name="n">The number of trials.</param> /// <param name="n">The number of trials (n). Range: n ≥ 0.</param>
/// <param name="randomSource">The random number generator which is used to draw random samples.</param> /// <param name="randomSource">The random number generator which is used to draw random samples.</param>
/// <exception cref="ArgumentOutOfRangeException">If <paramref name="p"/> is not in the interval [0.0,1.0].</exception> /// <exception cref="ArgumentOutOfRangeException">If <paramref name="p"/> is not in the interval [0.0,1.0].</exception>
/// <exception cref="ArgumentOutOfRangeException">If <paramref name="n"/> is negative.</exception> /// <exception cref="ArgumentOutOfRangeException">If <paramref name="n"/> is negative.</exception>
@ -85,14 +85,14 @@ namespace MathNet.Numerics.Distributions
/// <returns>a string representation of the distribution.</returns> /// <returns>a string representation of the distribution.</returns>
public override string ToString() public override string ToString()
{ {
return "Binomial(Success Probability = " + _p + ", Number of Trials = " + _trials + ")"; return "Binomial(p = " + _p + ", n = " + _trials + ")";
} }
/// <summary> /// <summary>
/// Checks whether the parameters of the distribution are valid. /// Checks whether the parameters of the distribution are valid.
/// </summary> /// </summary>
/// <param name="p">The success probability of a trial.</param> /// <param name="p">The success probability (p) in each trial. Range: 0 ≤ p ≤ 1.</param>
/// <param name="n">The number of trials.</param> /// <param name="n">The number of trials (n). Range: n ≥ 0.</param>
/// <returns><c>false</c> <paramref name="p"/> is not in the interval [0.0,1.0] or <paramref name="n"/> is negative, <c>true</c> otherwise.</returns> /// <returns><c>false</c> <paramref name="p"/> is not in the interval [0.0,1.0] or <paramref name="n"/> is negative, <c>true</c> otherwise.</returns>
static bool IsValidParameterSet(double p, int n) static bool IsValidParameterSet(double p, int n)
{ {
@ -102,8 +102,8 @@ namespace MathNet.Numerics.Distributions
/// <summary> /// <summary>
/// Sets the parameters of the distribution after checking their validity. /// Sets the parameters of the distribution after checking their validity.
/// </summary> /// </summary>
/// <param name="p">The success probability of a trial.</param> /// <param name="p">The success probability (p) in each trial. Range: 0 ≤ p ≤ 1.</param>
/// <param name="n">The number of trials.</param> /// <param name="n">The number of trials (n). Range: n ≥ 0.</param>
/// <exception cref="ArgumentOutOfRangeException">If <paramref name="p"/> is not in the interval [0.0,1.0].</exception> /// <exception cref="ArgumentOutOfRangeException">If <paramref name="p"/> is not in the interval [0.0,1.0].</exception>
/// <exception cref="ArgumentOutOfRangeException">If <paramref name="n"/> is negative.</exception> /// <exception cref="ArgumentOutOfRangeException">If <paramref name="n"/> is negative.</exception>
void SetParameters(double p, int n) void SetParameters(double p, int n)
@ -118,7 +118,7 @@ namespace MathNet.Numerics.Distributions
} }
/// <summary> /// <summary>
/// Gets or sets the success probability in each trial. /// Gets or sets the success probability in each trial. Range: 0 ≤ p ≤ 1.
/// </summary> /// </summary>
public double P public double P
{ {
@ -127,7 +127,7 @@ namespace MathNet.Numerics.Distributions
} }
/// <summary> /// <summary>
/// Gets or sets the number of trials. /// Gets or sets the number of trials. Range: n ≥ 0.
/// </summary> /// </summary>
public int N public int N
{ {
@ -175,10 +175,7 @@ namespace MathNet.Numerics.Distributions
{ {
get get
{ {
if (_p == 0.0 || _p == 1.0) if (_p == 0.0 || _p == 1.0) return 0.0;
{
return 0.0;
}
var e = 0.0; var e = 0.0;
for (var i = 0; i <= _trials; i++) for (var i = 0; i <= _trials; i++)
@ -222,15 +219,8 @@ namespace MathNet.Numerics.Distributions
{ {
get get
{ {
if (_p == 1.0) if (_p == 1.0) return _trials;
{ if (_p == 0.0) return 0;
return _trials;
}
if (_p == 0.0)
{
return 0;
}
return (int) Math.Floor((_trials + 1)*_p); return (int) Math.Floor((_trials + 1)*_p);
} }
@ -251,35 +241,12 @@ namespace MathNet.Numerics.Distributions
/// <returns>the probability mass at location <paramref name="k"/>.</returns> /// <returns>the probability mass at location <paramref name="k"/>.</returns>
public double Probability(int k) public double Probability(int k)
{ {
if (k < 0) if (k < 0) return 0.0;
{ if (k > _trials) return 0.0;
return 0.0; if (_p == 0.0 && k == 0) return 1.0;
} if (_p == 0.0) return 0.0;
if (_p == 1.0 && k == _trials) return 1.0;
if (k > _trials) if (_p == 1.0) return 0.0;
{
return 0.0;
}
if (_p == 0.0 && k == 0)
{
return 1.0;
}
if (_p == 0.0)
{
return 0.0;
}
if (_p == 1.0 && k == _trials)
{
return 1.0;
}
if (_p == 1.0)
{
return 0.0;
}
return SpecialFunctions.Binomial(_trials, k)*Math.Pow(_p, k)*Math.Pow(1.0 - _p, _trials - k); return SpecialFunctions.Binomial(_trials, k)*Math.Pow(_p, k)*Math.Pow(1.0 - _p, _trials - k);
} }
@ -291,35 +258,12 @@ namespace MathNet.Numerics.Distributions
/// <returns>the log probability mass at location <paramref name="k"/>.</returns> /// <returns>the log probability mass at location <paramref name="k"/>.</returns>
public double ProbabilityLn(int k) public double ProbabilityLn(int k)
{ {
if (k < 0) if (k < 0) return Double.NegativeInfinity;
{ if (k > _trials) return Double.NegativeInfinity;
return Double.NegativeInfinity; if (_p == 0.0 && k == 0) return 0.0;
} if (_p == 0.0) return Double.NegativeInfinity;
if (_p == 1.0 && k == _trials) return 0.0;
if (k > _trials) if (_p == 1.0) return Double.NegativeInfinity;
{
return Double.NegativeInfinity;
}
if (_p == 0.0 && k == 0)
{
return 0.0;
}
if (_p == 0.0)
{
return Double.NegativeInfinity;
}
if (_p == 1.0 && k == _trials)
{
return 0.0;
}
if (_p == 1.0)
{
return Double.NegativeInfinity;
}
return SpecialFunctions.BinomialLn(_trials, k) + (k*Math.Log(_p)) + ((_trials - k)*Math.Log(1.0 - _p)); return SpecialFunctions.BinomialLn(_trials, k) + (k*Math.Log(_p)) + ((_trials - k)*Math.Log(1.0 - _p));
} }
@ -331,15 +275,8 @@ namespace MathNet.Numerics.Distributions
/// <returns>the cumulative distribution at location <paramref name="x"/>.</returns> /// <returns>the cumulative distribution at location <paramref name="x"/>.</returns>
public double CumulativeDistribution(double x) public double CumulativeDistribution(double x)
{ {
if (x < 0.0) if (x < 0.0) return 0.0;
{ if (x > _trials) return 1.0;
return 0.0;
}
if (x > _trials)
{
return 1.0;
}
var cdf = 0.0; var cdf = 0.0;
for (var i = 0; i <= (int) Math.Floor(x); i++) for (var i = 0; i <= (int) Math.Floor(x); i++)
@ -354,8 +291,8 @@ namespace MathNet.Numerics.Distributions
/// Generates a sample from the Binomial distribution without doing parameter checking. /// Generates a sample from the Binomial distribution without doing parameter checking.
/// </summary> /// </summary>
/// <param name="rnd">The random number generator to use.</param> /// <param name="rnd">The random number generator to use.</param>
/// <param name="p">The success probability of a trial; must be in the interval [0.0, 1.0].</param> /// <param name="p">The success probability (p) in each trial. Range: 0 ≤ p ≤ 1.</param>
/// <param name="n">The number of trials; must be positive.</param> /// <param name="n">The number of trials (n). Range: n ≥ 0.</param>
/// <returns>The number of successful trials.</returns> /// <returns>The number of successful trials.</returns>
static int SampleUnchecked(System.Random rnd, double p, int n) static int SampleUnchecked(System.Random rnd, double p, int n)
{ {
@ -393,8 +330,8 @@ namespace MathNet.Numerics.Distributions
/// Samples a binomially distributed random variable. /// Samples a binomially distributed random variable.
/// </summary> /// </summary>
/// <param name="rnd">The random number generator to use.</param> /// <param name="rnd">The random number generator to use.</param>
/// <param name="p">The success probability of a trial; must be in the interval [0.0, 1.0].</param> /// <param name="p">The success probability (p) in each trial. Range: 0 ≤ p ≤ 1.</param>
/// <param name="n">The number of trials; must be positive.</param> /// <param name="n">The number of trials (n). Range: n ≥ 0.</param>
/// <returns>The number of successes in <paramref name="n"/> trials.</returns> /// <returns>The number of successes in <paramref name="n"/> trials.</returns>
public static int Sample(System.Random rnd, double p, int n) public static int Sample(System.Random rnd, double p, int n)
{ {
@ -410,8 +347,8 @@ namespace MathNet.Numerics.Distributions
/// Samples a sequence of binomially distributed random variable. /// Samples a sequence of binomially distributed random variable.
/// </summary> /// </summary>
/// <param name="rnd">The random number generator to use.</param> /// <param name="rnd">The random number generator to use.</param>
/// <param name="p">The success probability of a trial; must be in the interval [0.0, 1.0].</param> /// <param name="p">The success probability (p) in each trial. Range: 0 ≤ p ≤ 1.</param>
/// <param name="n">The number of trials; must be positive.</param> /// <param name="n">The number of trials (n). Range: n ≥ 0.</param>
/// <returns>a sequence of successes in <paramref name="n"/> trials.</returns> /// <returns>a sequence of successes in <paramref name="n"/> trials.</returns>
public static IEnumerable<int> Samples(System.Random rnd, double p, int n) public static IEnumerable<int> Samples(System.Random rnd, double p, int n)
{ {

18
src/Numerics/Distributions/Cauchy.cs

@ -58,8 +58,7 @@ namespace MathNet.Numerics.Distributions
/// Initializes a new instance of the <see cref="Cauchy"/> class. /// Initializes a new instance of the <see cref="Cauchy"/> class.
/// </summary> /// </summary>
/// <param name="location">The location (x0) of the distribution.</param> /// <param name="location">The location (x0) of the distribution.</param>
/// <param name="scale">The scale (γ) of the distribution.</param> /// <param name="scale">The scale (γ) of the distribution. Range: γ > 0.</param>
/// <exception cref="ArgumentException">If <paramref name="scale"/> is negative.</exception>
public Cauchy(double location, double scale) public Cauchy(double location, double scale)
{ {
_random = new System.Random(); _random = new System.Random();
@ -70,9 +69,8 @@ namespace MathNet.Numerics.Distributions
/// Initializes a new instance of the <see cref="Cauchy"/> class. /// Initializes a new instance of the <see cref="Cauchy"/> class.
/// </summary> /// </summary>
/// <param name="location">The location (x0) of the distribution.</param> /// <param name="location">The location (x0) of the distribution.</param>
/// <param name="scale">The scale (γ) of the distribution.</param> /// <param name="scale">The scale (γ) of the distribution. Range: γ > 0.</param>
/// <param name="randomSource">The random number generator which is used to draw random samples.</param> /// <param name="randomSource">The random number generator which is used to draw random samples.</param>
/// <exception cref="ArgumentException">If <paramref name="scale"/> is negative.</exception>
public Cauchy(double location, double scale, System.Random randomSource) public Cauchy(double location, double scale, System.Random randomSource)
{ {
_random = randomSource ?? new System.Random(); _random = randomSource ?? new System.Random();
@ -92,7 +90,7 @@ namespace MathNet.Numerics.Distributions
/// Checks whether the parameters of the distribution are valid. /// Checks whether the parameters of the distribution are valid.
/// </summary> /// </summary>
/// <param name="location">The location (x0) of the distribution.</param> /// <param name="location">The location (x0) of the distribution.</param>
/// <param name="scale">The scale (γ) of the distribution. Must be greater than 0.</param> /// <param name="scale">The scale (γ) of the distribution. Range: γ > 0.</param>
/// <returns>True when the parameters are valid, <c>false</c> otherwise.</returns> /// <returns>True when the parameters are valid, <c>false</c> otherwise.</returns>
static bool IsValidParameterSet(double location, double scale) static bool IsValidParameterSet(double location, double scale)
{ {
@ -103,7 +101,7 @@ namespace MathNet.Numerics.Distributions
/// Sets the parameters of the distribution after checking their validity. /// Sets the parameters of the distribution after checking their validity.
/// </summary> /// </summary>
/// <param name="location">The location (x0) of the distribution.</param> /// <param name="location">The location (x0) of the distribution.</param>
/// <param name="scale">The scale (γ) of the distribution. Must be greater than 0.</param> /// <param name="scale">The scale (γ) of the distribution. Range: γ > 0.</param>
/// <exception cref="ArgumentOutOfRangeException">When the parameters are out of range.</exception> /// <exception cref="ArgumentOutOfRangeException">When the parameters are out of range.</exception>
void SetParameters(double location, double scale) void SetParameters(double location, double scale)
{ {
@ -126,7 +124,7 @@ namespace MathNet.Numerics.Distributions
} }
/// <summary> /// <summary>
/// Gets or sets the scale (γ) of the distribution. /// Gets or sets the scale (γ) of the distribution. Range: γ > 0.
/// </summary> /// </summary>
public double Scale public double Scale
{ {
@ -250,7 +248,7 @@ namespace MathNet.Numerics.Distributions
/// </summary> /// </summary>
/// <param name="rnd">The random number generator to use.</param> /// <param name="rnd">The random number generator to use.</param>
/// <param name="location">The location (x0) of the distribution.</param> /// <param name="location">The location (x0) of the distribution.</param>
/// <param name="scale">The scale (γ) of the distribution.</param> /// <param name="scale">The scale (γ) of the distribution. Range: γ > 0.</param>
/// <returns>a random number from the distribution.</returns> /// <returns>a random number from the distribution.</returns>
static double SampleUnchecked(System.Random rnd, double location, double scale) static double SampleUnchecked(System.Random rnd, double location, double scale)
{ {
@ -284,7 +282,7 @@ namespace MathNet.Numerics.Distributions
/// </summary> /// </summary>
/// <param name="rnd">The random number generator to use.</param> /// <param name="rnd">The random number generator to use.</param>
/// <param name="location">The location (x0) of the distribution.</param> /// <param name="location">The location (x0) of the distribution.</param>
/// <param name="scale">The scale (γ) of the distribution.</param> /// <param name="scale">The scale (γ) of the distribution. Range: γ > 0.</param>
/// <returns>a sample from the distribution.</returns> /// <returns>a sample from the distribution.</returns>
public static double Sample(System.Random rnd, double location, double scale) public static double Sample(System.Random rnd, double location, double scale)
{ {
@ -301,7 +299,7 @@ namespace MathNet.Numerics.Distributions
/// </summary> /// </summary>
/// <param name="rnd">The random number generator to use.</param> /// <param name="rnd">The random number generator to use.</param>
/// <param name="location">The location (x0) of the distribution.</param> /// <param name="location">The location (x0) of the distribution.</param>
/// <param name="scale">The scale (γ) of the distribution.</param> /// <param name="scale">The scale (γ) of the distribution. Range: γ > 0.</param>
/// <returns>a sequence of samples from the distribution.</returns> /// <returns>a sequence of samples from the distribution.</returns>
public static IEnumerable<double> Samples(System.Random rnd, double location, double scale) public static IEnumerable<double> Samples(System.Random rnd, double location, double scale)
{ {

16
src/Numerics/Distributions/Chi.cs

@ -55,7 +55,7 @@ namespace MathNet.Numerics.Distributions
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="Chi"/> class. /// Initializes a new instance of the <see cref="Chi"/> class.
/// </summary> /// </summary>
/// <param name="freedom">The degrees of freedom (k) of the distribution.</param> /// <param name="freedom">The degrees of freedom (k) of the distribution. Range: k > 0.</param>
public Chi(double freedom) public Chi(double freedom)
{ {
_random = new System.Random(); _random = new System.Random();
@ -65,7 +65,7 @@ namespace MathNet.Numerics.Distributions
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="Chi"/> class. /// Initializes a new instance of the <see cref="Chi"/> class.
/// </summary> /// </summary>
/// <param name="freedom">The degrees of freedom (k) of the distribution.</param> /// <param name="freedom">The degrees of freedom (k) of the distribution. Range: k > 0.</param>
/// <param name="randomSource">The random number generator which is used to draw random samples.</param> /// <param name="randomSource">The random number generator which is used to draw random samples.</param>
public Chi(double freedom, System.Random randomSource) public Chi(double freedom, System.Random randomSource)
{ {
@ -85,7 +85,7 @@ namespace MathNet.Numerics.Distributions
/// <summary> /// <summary>
/// Checks whether the parameters of the distribution are valid. /// Checks whether the parameters of the distribution are valid.
/// </summary> /// </summary>
/// <param name="freedom">The degrees of freedom for the Chi distribution.</param> /// <param name="freedom">The degrees of freedom (k) of the distribution. Range: k > 0.</param>
/// <returns><c>true</c> when the parameters are valid, <c>false</c> otherwise.</returns> /// <returns><c>true</c> when the parameters are valid, <c>false</c> otherwise.</returns>
static bool IsValidParameterSet(double freedom) static bool IsValidParameterSet(double freedom)
{ {
@ -95,7 +95,7 @@ namespace MathNet.Numerics.Distributions
/// <summary> /// <summary>
/// Sets the parameters of the distribution after checking their validity. /// Sets the parameters of the distribution after checking their validity.
/// </summary> /// </summary>
/// <param name="freedom">The degrees of freedom for the Chi distribution.</param> /// <param name="freedom">The degrees of freedom (k) of the distribution. Range: k > 0.</param>
/// <exception cref="ArgumentOutOfRangeException">When the parameters are out of range.</exception> /// <exception cref="ArgumentOutOfRangeException">When the parameters are out of range.</exception>
void SetParameters(double freedom) void SetParameters(double freedom)
{ {
@ -108,7 +108,7 @@ namespace MathNet.Numerics.Distributions
} }
/// <summary> /// <summary>
/// Gets or sets the degrees of freedom (k) of the Chi distribution. /// Gets or sets the degrees of freedom (k) of the Chi distribution. Range: k > 0.
/// </summary> /// </summary>
public double DegreesOfFreedom public double DegreesOfFreedom
{ {
@ -243,7 +243,7 @@ namespace MathNet.Numerics.Distributions
/// Samples the distribution. /// Samples the distribution.
/// </summary> /// </summary>
/// <param name="rnd">The random number generator to use.</param> /// <param name="rnd">The random number generator to use.</param>
/// <param name="freedom">The degrees of freedom (k) of the distribution.</param> /// <param name="freedom">The degrees of freedom (k) of the distribution. Range: k > 0.</param>
/// <returns>a random number from the distribution.</returns> /// <returns>a random number from the distribution.</returns>
static double SampleUnchecked(System.Random rnd, int freedom) static double SampleUnchecked(System.Random rnd, int freedom)
{ {
@ -282,7 +282,7 @@ namespace MathNet.Numerics.Distributions
/// Generates a sample from the distribution. /// Generates a sample from the distribution.
/// </summary> /// </summary>
/// <param name="rnd">The random number generator to use.</param> /// <param name="rnd">The random number generator to use.</param>
/// <param name="freedom">The degrees of freedom (k) of the distribution.</param> /// <param name="freedom">The degrees of freedom (k) of the distribution. Range: k > 0.</param>
/// <returns>a sample from the distribution.</returns> /// <returns>a sample from the distribution.</returns>
public static double Sample(System.Random rnd, int freedom) public static double Sample(System.Random rnd, int freedom)
{ {
@ -298,7 +298,7 @@ namespace MathNet.Numerics.Distributions
/// Generates a sequence of samples from the distribution. /// Generates a sequence of samples from the distribution.
/// </summary> /// </summary>
/// <param name="rnd">The random number generator to use.</param> /// <param name="rnd">The random number generator to use.</param>
/// <param name="freedom">The degrees of freedom (k) of the distribution.</param> /// <param name="freedom">The degrees of freedom (k) of the distribution. Range: k > 0.</param>
/// <returns>a sequence of samples from the distribution.</returns> /// <returns>a sequence of samples from the distribution.</returns>
public static IEnumerable<double> Samples(System.Random rnd, int freedom) public static IEnumerable<double> Samples(System.Random rnd, int freedom)
{ {

18
src/Numerics/Distributions/ChiSquared.cs

@ -53,7 +53,7 @@ namespace MathNet.Numerics.Distributions
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="ChiSquared"/> class. /// Initializes a new instance of the <see cref="ChiSquared"/> class.
/// </summary> /// </summary>
/// <param name="freedom">The degrees of freedom (k) of the distribution.</param> /// <param name="freedom">The degrees of freedom (k) of the distribution. Range: k > 0.</param>
public ChiSquared(double freedom) public ChiSquared(double freedom)
{ {
_random = new System.Random(); _random = new System.Random();
@ -63,7 +63,7 @@ namespace MathNet.Numerics.Distributions
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="ChiSquared"/> class. /// Initializes a new instance of the <see cref="ChiSquared"/> class.
/// </summary> /// </summary>
/// <param name="freedom">The degrees of freedom (k) of the distribution.</param> /// <param name="freedom">The degrees of freedom (k) of the distribution. Range: k > 0.</param>
/// <param name="randomSource">The random number generator which is used to draw random samples.</param> /// <param name="randomSource">The random number generator which is used to draw random samples.</param>
public ChiSquared(double freedom, System.Random randomSource) public ChiSquared(double freedom, System.Random randomSource)
{ {
@ -83,17 +83,17 @@ namespace MathNet.Numerics.Distributions
/// <summary> /// <summary>
/// Checks whether the parameters of the distribution are valid. /// Checks whether the parameters of the distribution are valid.
/// </summary> /// </summary>
/// <param name="freedom">The degrees of freedom (k) of the distribution.</param> /// <param name="freedom">The degrees of freedom (k) of the distribution. Range: k > 0.</param>
/// <returns><c>true</c> when the parameters are valid, <c>false</c> otherwise.</returns> /// <returns><c>true</c> when the parameters are valid, <c>false</c> otherwise.</returns>
static bool IsValidParameterSet(double freedom) static bool IsValidParameterSet(double freedom)
{ {
return freedom > 0 && !Double.IsNaN(freedom); return freedom > 0;
} }
/// <summary> /// <summary>
/// Sets the parameters of the distribution after checking their validity. /// Sets the parameters of the distribution after checking their validity.
/// </summary> /// </summary>
/// <param name="freedom">The degrees of freedom (k) of the distribution.</param> /// <param name="freedom">The degrees of freedom (k) of the distribution. Range: k > 0.</param>
/// <exception cref="ArgumentOutOfRangeException">When the parameters are out of range.</exception> /// <exception cref="ArgumentOutOfRangeException">When the parameters are out of range.</exception>
void SetParameters(double freedom) void SetParameters(double freedom)
{ {
@ -106,7 +106,7 @@ namespace MathNet.Numerics.Distributions
} }
/// <summary> /// <summary>
/// Gets or sets the degrees of freedom (k) of the Chi-Squared distribution. /// Gets or sets the degrees of freedom (k) of the Chi-Squared distribution. Range: k > 0.
/// </summary> /// </summary>
public double DegreesOfFreedom public double DegreesOfFreedom
{ {
@ -229,7 +229,7 @@ namespace MathNet.Numerics.Distributions
/// Samples the distribution. /// Samples the distribution.
/// </summary> /// </summary>
/// <param name="rnd">The random number generator to use.</param> /// <param name="rnd">The random number generator to use.</param>
/// <param name="freedom">The degrees of freedom (k) of the distribution.</param> /// <param name="freedom">The degrees of freedom (k) of the distribution. Range: k > 0.</param>
/// <returns>a random number from the distribution.</returns> /// <returns>a random number from the distribution.</returns>
static double SampleUnchecked(System.Random rnd, double freedom) static double SampleUnchecked(System.Random rnd, double freedom)
{ {
@ -275,7 +275,7 @@ namespace MathNet.Numerics.Distributions
/// Generates a sample from the <c>ChiSquare</c> distribution. /// Generates a sample from the <c>ChiSquare</c> distribution.
/// </summary> /// </summary>
/// <param name="rnd">The random number generator to use.</param> /// <param name="rnd">The random number generator to use.</param>
/// <param name="freedom">The degrees of freedom (k) of the distribution.</param> /// <param name="freedom">The degrees of freedom (k) of the distribution. Range: k > 0.</param>
/// <returns>a sample from the distribution. </returns> /// <returns>a sample from the distribution. </returns>
public static double Sample(System.Random rnd, double freedom) public static double Sample(System.Random rnd, double freedom)
{ {
@ -291,7 +291,7 @@ namespace MathNet.Numerics.Distributions
/// Generates a sequence of samples from the distribution. /// Generates a sequence of samples from the distribution.
/// </summary> /// </summary>
/// <param name="rnd">The random number generator to use.</param> /// <param name="rnd">The random number generator to use.</param>
/// <param name="freedom">The degrees of freedom (k) of the distribution.</param> /// <param name="freedom">The degrees of freedom (k) of the distribution. Range: k > 0.</param>
/// <returns>a sample from the distribution. </returns> /// <returns>a sample from the distribution. </returns>
public static IEnumerable<double> Samples(System.Random rnd, double freedom) public static IEnumerable<double> Samples(System.Random rnd, double freedom)
{ {

28
src/Numerics/Distributions/ContinuousUniform.cs

@ -61,8 +61,8 @@ namespace MathNet.Numerics.Distributions
/// <summary> /// <summary>
/// Initializes a new instance of the ContinuousUniform class with given lower and upper bounds. /// Initializes a new instance of the ContinuousUniform class with given lower and upper bounds.
/// </summary> /// </summary>
/// <param name="lower">Lower bound.</param> /// <param name="lower">Lower bound. Range: lower ≤ upper.</param>
/// <param name="upper">Upper bound; must be at least as large as <paramref name="lower"/>.</param> /// <param name="upper">Upper bound. Range: lower ≤ upper.</param>
/// <exception cref="ArgumentException">If the upper bound is smaller than the lower bound.</exception> /// <exception cref="ArgumentException">If the upper bound is smaller than the lower bound.</exception>
public ContinuousUniform(double lower, double upper) public ContinuousUniform(double lower, double upper)
{ {
@ -73,8 +73,8 @@ namespace MathNet.Numerics.Distributions
/// <summary> /// <summary>
/// Initializes a new instance of the ContinuousUniform class with given lower and upper bounds. /// Initializes a new instance of the ContinuousUniform class with given lower and upper bounds.
/// </summary> /// </summary>
/// <param name="lower">Lower bound.</param> /// <param name="lower">Lower bound. Range: lower ≤ upper.</param>
/// <param name="upper">Upper bound; must be at least as large as lower.</param> /// <param name="upper">Upper bound. Range: lower ≤ upper.</param>
/// <param name="randomSource">The random number generator which is used to draw random samples.</param> /// <param name="randomSource">The random number generator which is used to draw random samples.</param>
/// <exception cref="ArgumentException">If the upper bound is smaller than the lower bound.</exception> /// <exception cref="ArgumentException">If the upper bound is smaller than the lower bound.</exception>
public ContinuousUniform(double lower, double upper, System.Random randomSource) public ContinuousUniform(double lower, double upper, System.Random randomSource)
@ -95,8 +95,8 @@ namespace MathNet.Numerics.Distributions
/// <summary> /// <summary>
/// Checks whether the parameters of the distribution are valid. /// Checks whether the parameters of the distribution are valid.
/// </summary> /// </summary>
/// <param name="lower">Lower bound.</param> /// <param name="lower">Lower bound. Range: lower ≤ upper.</param>
/// <param name="upper">Upper bound; must be at least as large as <paramref name="lower"/>.</param> /// <param name="upper">Upper bound. Range: lower ≤ upper.</param>
/// <returns><c>true</c> when the parameters are valid, <c>false</c> otherwise.</returns> /// <returns><c>true</c> when the parameters are valid, <c>false</c> otherwise.</returns>
static bool IsValidParameterSet(double lower, double upper) static bool IsValidParameterSet(double lower, double upper)
{ {
@ -106,8 +106,8 @@ namespace MathNet.Numerics.Distributions
/// <summary> /// <summary>
/// Sets the parameters of the distribution after checking their validity. /// Sets the parameters of the distribution after checking their validity.
/// </summary> /// </summary>
/// <param name="lower">Lower bound.</param> /// <param name="lower">Lower bound. Range: lower ≤ upper.</param>
/// <param name="upper">Upper bound; must be at least as large as <paramref name="lower"/>.</param> /// <param name="upper">Upper bound. Range: lower ≤ upper.</param>
/// <exception cref="ArgumentOutOfRangeException">When the parameters are out of range.</exception> /// <exception cref="ArgumentOutOfRangeException">When the parameters are out of range.</exception>
void SetParameters(double lower, double upper) void SetParameters(double lower, double upper)
{ {
@ -276,8 +276,8 @@ namespace MathNet.Numerics.Distributions
/// Generates one sample from the <c>ContinuousUniform</c> distribution without parameter checking. /// Generates one sample from the <c>ContinuousUniform</c> distribution without parameter checking.
/// </summary> /// </summary>
/// <param name="rnd">The random number generator to use.</param> /// <param name="rnd">The random number generator to use.</param>
/// <param name="lower">The lower bound of the uniform random variable.</param> /// <param name="lower">Lower bound. Range: lower ≤ upper.</param>
/// <param name="upper">The upper bound of the uniform random variable.</param> /// <param name="upper">Upper bound. Range: lower ≤ upper.</param>
/// <returns>a uniformly distributed random number.</returns> /// <returns>a uniformly distributed random number.</returns>
static double SampleUnchecked(System.Random rnd, double lower, double upper) static double SampleUnchecked(System.Random rnd, double lower, double upper)
{ {
@ -309,8 +309,8 @@ namespace MathNet.Numerics.Distributions
/// Generates a sample from the <c>ContinuousUniform</c> distribution. /// Generates a sample from the <c>ContinuousUniform</c> distribution.
/// </summary> /// </summary>
/// <param name="rnd">The random number generator to use.</param> /// <param name="rnd">The random number generator to use.</param>
/// <param name="lower">The lower bound of the uniform random variable.</param> /// <param name="lower">Lower bound. Range: lower ≤ upper.</param>
/// <param name="upper">The upper bound of the uniform random variable.</param> /// <param name="upper">Upper bound. Range: lower ≤ upper.</param>
/// <returns>a uniformly distributed sample.</returns> /// <returns>a uniformly distributed sample.</returns>
public static double Sample(System.Random rnd, double lower, double upper) public static double Sample(System.Random rnd, double lower, double upper)
{ {
@ -326,8 +326,8 @@ namespace MathNet.Numerics.Distributions
/// Generates a sequence of samples from the <c>ContinuousUniform</c> distribution. /// Generates a sequence of samples from the <c>ContinuousUniform</c> distribution.
/// </summary> /// </summary>
/// <param name="rnd">The random number generator to use.</param> /// <param name="rnd">The random number generator to use.</param>
/// <param name="lower">The lower bound of the uniform random variable.</param> /// <param name="lower">Lower bound. Range: lower ≤ upper.</param>
/// <param name="upper">The upper bound of the uniform random variable.</param> /// <param name="upper">Upper bound. Range: lower ≤ upper.</param>
/// <returns>a sequence of uniformly distributed samples.</returns> /// <returns>a sequence of uniformly distributed samples.</returns>
public static IEnumerable<double> Samples(System.Random rnd, double lower, double upper) public static IEnumerable<double> Samples(System.Random rnd, double lower, double upper)
{ {

32
src/Numerics/Distributions/ConwayMaxwellPoisson.cs

@ -82,8 +82,8 @@ namespace MathNet.Numerics.Distributions
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="ConwayMaxwellPoisson"/> class. /// Initializes a new instance of the <see cref="ConwayMaxwellPoisson"/> class.
/// </summary> /// </summary>
/// <param name="lambda">The lambda (λ) parameter.</param> /// <param name="lambda">The lambda (λ) parameter. Range: λ > 0.</param>
/// <param name="nu">The rate of decay (ν) parameter.</param> /// <param name="nu">The rate of decay (ν) parameter. Range: ν ≥ 0.</param>
public ConwayMaxwellPoisson(double lambda, double nu) public ConwayMaxwellPoisson(double lambda, double nu)
{ {
_random = new System.Random(); _random = new System.Random();
@ -93,8 +93,8 @@ namespace MathNet.Numerics.Distributions
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="ConwayMaxwellPoisson"/> class. /// Initializes a new instance of the <see cref="ConwayMaxwellPoisson"/> class.
/// </summary> /// </summary>
/// <param name="lambda">The lambda (λ) parameter.</param> /// <param name="lambda">The lambda (λ) parameter. Range: λ > 0.</param>
/// <param name="nu">The rate of decay (ν) parameter.</param> /// <param name="nu">The rate of decay (ν) parameter. Range: ν ≥ 0.</param>
/// <param name="randomSource">The random number generator which is used to draw random samples.</param> /// <param name="randomSource">The random number generator which is used to draw random samples.</param>
public ConwayMaxwellPoisson(double lambda, double nu, System.Random randomSource) public ConwayMaxwellPoisson(double lambda, double nu, System.Random randomSource)
{ {
@ -114,8 +114,8 @@ namespace MathNet.Numerics.Distributions
/// <summary> /// <summary>
/// Checks whether the parameters of the distribution are valid. /// Checks whether the parameters of the distribution are valid.
/// </summary> /// </summary>
/// <param name="lambda">The lambda (λ) parameter.</param> /// <param name="lambda">The lambda (λ) parameter. Range: λ > 0.</param>
/// <param name="nu">The rate of decay (ν) parameter.</param> /// <param name="nu">The rate of decay (ν) parameter. Range: ν ≥ 0.</param>
/// <returns><c>true</c> when the parameters are valid, <c>false</c> otherwise.</returns> /// <returns><c>true</c> when the parameters are valid, <c>false</c> otherwise.</returns>
static bool IsValidParameterSet(double lambda, double nu) static bool IsValidParameterSet(double lambda, double nu)
{ {
@ -125,8 +125,8 @@ namespace MathNet.Numerics.Distributions
/// <summary> /// <summary>
/// Sets the parameters of the distribution after checking their validity. /// Sets the parameters of the distribution after checking their validity.
/// </summary> /// </summary>
/// <param name="lambda">The lambda (λ) parameter.</param> /// <param name="lambda">The lambda (λ) parameter. Range: λ > 0.</param>
/// <param name="nu">The rate of decay (ν) parameter.</param> /// <param name="nu">The rate of decay (ν) parameter. Range: ν ≥ 0.</param>
/// <exception cref="ArgumentOutOfRangeException">When the parameters are out of range.</exception> /// <exception cref="ArgumentOutOfRangeException">When the parameters are out of range.</exception>
void SetParameters(double lambda, double nu) void SetParameters(double lambda, double nu)
{ {
@ -140,7 +140,7 @@ namespace MathNet.Numerics.Distributions
} }
/// <summary> /// <summary>
/// Gets or sets the lambda (λ) parameter. /// Gets or sets the lambda (λ) parameter. Range: λ > 0.
/// </summary> /// </summary>
public double Lambda public double Lambda
{ {
@ -149,7 +149,7 @@ namespace MathNet.Numerics.Distributions
} }
/// <summary> /// <summary>
/// Gets or sets the rate of decay (ν) parameter. /// Gets or sets the rate of decay (ν) parameter. Range: ν ≥ 0.
/// </summary> /// </summary>
public double Nu public double Nu
{ {
@ -443,8 +443,8 @@ namespace MathNet.Numerics.Distributions
/// Returns one trials from the distribution. /// Returns one trials from the distribution.
/// </summary> /// </summary>
/// <param name="rnd">The random number generator to use.</param> /// <param name="rnd">The random number generator to use.</param>
/// <param name="lambda">The lambda (λ) parameter.</param> /// <param name="lambda">The lambda (λ) parameter. Range: λ > 0.</param>
/// <param name="nu">The rate of decay (ν) parameter.</param> /// <param name="nu">The rate of decay (ν) parameter. Range: ν ≥ 0.</param>
/// <param name="z">The z parameter.</param> /// <param name="z">The z parameter.</param>
/// <returns> /// <returns>
/// One sample from the distribution implied by <paramref name="lambda"/>, <paramref name="nu"/>, and <paramref name="z"/>. /// One sample from the distribution implied by <paramref name="lambda"/>, <paramref name="nu"/>, and <paramref name="z"/>.
@ -493,8 +493,8 @@ namespace MathNet.Numerics.Distributions
/// Samples a random variable. /// Samples a random variable.
/// </summary> /// </summary>
/// <param name="rnd">The random number generator to use.</param> /// <param name="rnd">The random number generator to use.</param>
/// <param name="lambda">The lambda (λ) parameter.</param> /// <param name="lambda">The lambda (λ) parameter. Range: λ > 0.</param>
/// <param name="nu">The rate of decay (ν) parameter.</param> /// <param name="nu">The rate of decay (ν) parameter. Range: ν ≥ 0.</param>
public static int Sample(System.Random rnd, double lambda, double nu) public static int Sample(System.Random rnd, double lambda, double nu)
{ {
if (Control.CheckDistributionParameters && !IsValidParameterSet(lambda, nu)) if (Control.CheckDistributionParameters && !IsValidParameterSet(lambda, nu))
@ -510,8 +510,8 @@ namespace MathNet.Numerics.Distributions
/// Samples a sequence of this random variable. /// Samples a sequence of this random variable.
/// </summary> /// </summary>
/// <param name="rnd">The random number generator to use.</param> /// <param name="rnd">The random number generator to use.</param>
/// <param name="lambda">The lambda (λ) parameter.</param> /// <param name="lambda">The lambda (λ) parameter. Range: λ > 0.</param>
/// <param name="nu">The rate of decay (ν) parameter.</param> /// <param name="nu">The rate of decay (ν) parameter. Range: ν ≥ 0.</param>
public static IEnumerable<int> Samples(System.Random rnd, double lambda, double nu) public static IEnumerable<int> Samples(System.Random rnd, double lambda, double nu)
{ {
if (Control.CheckDistributionParameters && !IsValidParameterSet(lambda, nu)) if (Control.CheckDistributionParameters && !IsValidParameterSet(lambda, nu))

28
src/Numerics/Distributions/DiscreteUniform.cs

@ -55,8 +55,8 @@ namespace MathNet.Numerics.Distributions
/// <summary> /// <summary>
/// Initializes a new instance of the DiscreteUniform class. /// Initializes a new instance of the DiscreteUniform class.
/// </summary> /// </summary>
/// <param name="lower">Lower bound.</param> /// <param name="lower">Lower bound. Range: lower ≤ upper.</param>
/// <param name="upper">Upper bound; must be at least as large as <paramref name="lower"/>.</param> /// <param name="upper">Upper bound. Range: lower ≤ upper.</param>
public DiscreteUniform(int lower, int upper) public DiscreteUniform(int lower, int upper)
{ {
_random = new System.Random(); _random = new System.Random();
@ -66,8 +66,8 @@ namespace MathNet.Numerics.Distributions
/// <summary> /// <summary>
/// Initializes a new instance of the DiscreteUniform class. /// Initializes a new instance of the DiscreteUniform class.
/// </summary> /// </summary>
/// <param name="lower">Lower bound.</param> /// <param name="lower">Lower bound. Range: lower ≤ upper.</param>
/// <param name="upper">Upper bound; must be at least as large as <paramref name="lower"/>.</param> /// <param name="upper">Upper bound. Range: lower ≤ upper.</param>
/// <param name="randomSource">The random number generator which is used to draw random samples.</param> /// <param name="randomSource">The random number generator which is used to draw random samples.</param>
public DiscreteUniform(int lower, int upper, System.Random randomSource) public DiscreteUniform(int lower, int upper, System.Random randomSource)
{ {
@ -89,8 +89,8 @@ namespace MathNet.Numerics.Distributions
/// <summary> /// <summary>
/// Checks whether the parameters of the distribution are valid. /// Checks whether the parameters of the distribution are valid.
/// </summary> /// </summary>
/// <param name="lower">Lower bound.</param> /// <param name="lower">Lower bound. Range: lower ≤ upper.</param>
/// <param name="upper">Upper bound; must be at least as large as <paramref name="lower"/>.</param> /// <param name="upper">Upper bound. Range: lower ≤ upper.</param>
/// <returns><c>true</c> when the parameters are valid, <c>false</c> otherwise.</returns> /// <returns><c>true</c> when the parameters are valid, <c>false</c> otherwise.</returns>
static bool IsValidParameterSet(int lower, int upper) static bool IsValidParameterSet(int lower, int upper)
{ {
@ -100,8 +100,8 @@ namespace MathNet.Numerics.Distributions
/// <summary> /// <summary>
/// Sets the parameters of the distribution after checking their validity. /// Sets the parameters of the distribution after checking their validity.
/// </summary> /// </summary>
/// <param name="lower">Lower bound.</param> /// <param name="lower">Lower bound. Range: lower ≤ upper.</param>
/// <param name="upper">Upper bound; must be at least as large as <paramref name="lower"/>.</param> /// <param name="upper">Upper bound. Range: lower ≤ upper.</param>
/// <exception cref="ArgumentOutOfRangeException">When the parameters are out of range.</exception> /// <exception cref="ArgumentOutOfRangeException">When the parameters are out of range.</exception>
void SetParameters(int lower, int upper) void SetParameters(int lower, int upper)
{ {
@ -267,8 +267,8 @@ namespace MathNet.Numerics.Distributions
/// Generates one sample from the discrete uniform distribution. This method does not do any parameter checking. /// Generates one sample from the discrete uniform distribution. This method does not do any parameter checking.
/// </summary> /// </summary>
/// <param name="rnd">The random source to use.</param> /// <param name="rnd">The random source to use.</param>
/// <param name="lower">The lower bound of the uniform random variable.</param> /// <param name="lower">Lower bound. Range: lower ≤ upper.</param>
/// <param name="upper">The upper bound of the uniform random variable.</param> /// <param name="upper">Upper bound. Range: lower ≤ upper.</param>
/// <returns>A random sample from the discrete uniform distribution.</returns> /// <returns>A random sample from the discrete uniform distribution.</returns>
static int SampleUnchecked(System.Random rnd, int lower, int upper) static int SampleUnchecked(System.Random rnd, int lower, int upper)
{ {
@ -300,8 +300,8 @@ namespace MathNet.Numerics.Distributions
/// Samples a uniformly distributed random variable. /// Samples a uniformly distributed random variable.
/// </summary> /// </summary>
/// <param name="rnd">The random number generator to use.</param> /// <param name="rnd">The random number generator to use.</param>
/// <param name="lower">The lower bound of the uniform random variable.</param> /// <param name="lower">Lower bound. Range: lower ≤ upper.</param>
/// <param name="upper">The upper bound of the uniform random variable.</param> /// <param name="upper">Upper bound. Range: lower ≤ upper.</param>
/// <returns>A sample from the discrete uniform distribution.</returns> /// <returns>A sample from the discrete uniform distribution.</returns>
public static int Sample(System.Random rnd, int lower, int upper) public static int Sample(System.Random rnd, int lower, int upper)
{ {
@ -317,8 +317,8 @@ namespace MathNet.Numerics.Distributions
/// Samples a sequence of uniformly distributed random variables. /// Samples a sequence of uniformly distributed random variables.
/// </summary> /// </summary>
/// <param name="rnd">The random number generator to use.</param> /// <param name="rnd">The random number generator to use.</param>
/// <param name="lower">The lower bound of the uniform random variable.</param> /// <param name="lower">Lower bound. Range: lower ≤ upper.</param>
/// <param name="upper">The upper bound of the uniform random variable.</param> /// <param name="upper">Upper bound. Range: lower ≤ upper.</param>
/// <returns>a sequence of samples from the discrete uniform distribution.</returns> /// <returns>a sequence of samples from the discrete uniform distribution.</returns>
public static IEnumerable<int> Samples(System.Random rnd, int lower, int upper) public static IEnumerable<int> Samples(System.Random rnd, int lower, int upper)
{ {

62
src/Numerics/Distributions/Erlang.cs

@ -55,8 +55,8 @@ namespace MathNet.Numerics.Distributions
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="Erlang"/> class. /// Initializes a new instance of the <see cref="Erlang"/> class.
/// </summary> /// </summary>
/// <param name="shape">The shape (k) of the Erlang distribution.</param> /// <param name="shape">The shape (k) of the Erlang distribution. Range: k ≥ 0.</param>
/// <param name="rate">The rate or inverse scale (λ) of the Erlang distribution.</param> /// <param name="rate">The rate or inverse scale (λ) of the Erlang distribution. Range: λ ≥ 0.</param>
public Erlang(int shape, double rate) public Erlang(int shape, double rate)
{ {
_random = new System.Random(); _random = new System.Random();
@ -66,8 +66,8 @@ namespace MathNet.Numerics.Distributions
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="Erlang"/> class. /// Initializes a new instance of the <see cref="Erlang"/> class.
/// </summary> /// </summary>
/// <param name="shape">The shape (k) of the Erlang distribution.</param> /// <param name="shape">The shape (k) of the Erlang distribution. Range: k ≥ 0.</param>
/// <param name="rate">The rate or inverse scale (λ) of the Erlang distribution.</param> /// <param name="rate">The rate or inverse scale (λ) of the Erlang distribution. Range: λ ≥ 0.</param>
/// <param name="randomSource">The random number generator which is used to draw random samples.</param> /// <param name="randomSource">The random number generator which is used to draw random samples.</param>
public Erlang(int shape, double rate, System.Random randomSource) public Erlang(int shape, double rate, System.Random randomSource)
{ {
@ -79,9 +79,8 @@ namespace MathNet.Numerics.Distributions
/// Constructs a Erlang distribution from a shape and scale parameter. The distribution will /// Constructs a Erlang distribution from a shape and scale parameter. The distribution will
/// be initialized with the default <seealso cref="System.Random"/> random number generator. /// be initialized with the default <seealso cref="System.Random"/> random number generator.
/// </summary> /// </summary>
/// <param name="shape">The shape (k) of the Erlang distribution.</param> /// <param name="shape">The shape (k) of the Erlang distribution. Range: k ≥ 0.</param>
/// <param name="scale">The scale (mu) of the Erlang distribution.</param> /// <param name="scale">The scale (μ) of the Erlang distribution. Range: μ ≥ 0.</param>
/// <returns>a normal distribution.</returns>
public static Erlang WithShapeScale(int shape, double scale) public static Erlang WithShapeScale(int shape, double scale)
{ {
return new Erlang(shape, 1.0/scale); return new Erlang(shape, 1.0/scale);
@ -91,9 +90,8 @@ namespace MathNet.Numerics.Distributions
/// Constructs a Erlang distribution from a shape and inverse scale parameter. The distribution will /// Constructs a Erlang distribution from a shape and inverse scale parameter. The distribution will
/// be initialized with the default <seealso cref="System.Random"/> random number generator. /// be initialized with the default <seealso cref="System.Random"/> random number generator.
/// </summary> /// </summary>
/// <param name="shape">The shape (k) of the Erlang distribution.</param> /// <param name="shape">The shape (k) of the Erlang distribution. Range: k ≥ 0.</param>
/// <param name="rate">The rate or inverse scale (λ) of the Erlang distribution.</param> /// <param name="rate">The rate or inverse scale (λ) of the Erlang distribution. Range: λ ≥ 0.</param>
/// <returns>a normal distribution.</returns>
public static Erlang WithShapeRate(int shape, double rate) public static Erlang WithShapeRate(int shape, double rate)
{ {
return new Erlang(shape, rate); return new Erlang(shape, rate);
@ -111,8 +109,8 @@ namespace MathNet.Numerics.Distributions
/// <summary> /// <summary>
/// Checks whether the parameters of the distribution are valid. /// Checks whether the parameters of the distribution are valid.
/// </summary> /// </summary>
/// <param name="shape">The shape (k) of the Erlang distribution.</param> /// <param name="shape">The shape (k) of the Erlang distribution. Range: k ≥ 0.</param>
/// <param name="rate">The rate or inverse scale (λ) of the Erlang distribution.</param> /// <param name="rate">The rate or inverse scale (λ) of the Erlang distribution. Range: λ ≥ 0.</param>
/// <returns><c>true</c> when the parameters are valid, <c>false</c> otherwise.</returns> /// <returns><c>true</c> when the parameters are valid, <c>false</c> otherwise.</returns>
static bool IsValidParameterSet(double shape, double rate) static bool IsValidParameterSet(double shape, double rate)
{ {
@ -122,8 +120,8 @@ namespace MathNet.Numerics.Distributions
/// <summary> /// <summary>
/// Sets the parameters of the distribution after checking their validity. /// Sets the parameters of the distribution after checking their validity.
/// </summary> /// </summary>
/// <param name="shape">The shape (k) of the Erlang distribution.</param> /// <param name="shape">The shape (k) of the Erlang distribution. Range: k ≥ 0.</param>
/// <param name="rate">The rate or inverse scale (λ) of the Erlang distribution.</param> /// <param name="rate">The rate or inverse scale (λ) of the Erlang distribution. Range: λ ≥ 0.</param>
/// <exception cref="ArgumentOutOfRangeException">When the parameters are out of range.</exception> /// <exception cref="ArgumentOutOfRangeException">When the parameters are out of range.</exception>
void SetParameters(double shape, double rate) void SetParameters(double shape, double rate)
{ {
@ -137,7 +135,7 @@ namespace MathNet.Numerics.Distributions
} }
/// <summary> /// <summary>
/// Gets or sets the shape (k) of the Erlang distribution. /// Gets or sets the shape (k) of the Erlang distribution. Range: k ≥ 0.
/// </summary> /// </summary>
public int Shape public int Shape
{ {
@ -146,7 +144,7 @@ namespace MathNet.Numerics.Distributions
} }
/// <summary> /// <summary>
/// Gets or sets the rate or inverse scale (λ) of the Erlang distribution. /// Gets or sets the rate or inverse scale (λ) of the Erlang distribution. Range: λ ≥ 0.
/// </summary> /// </summary>
public double Rate public double Rate
{ {
@ -412,12 +410,12 @@ namespace MathNet.Numerics.Distributions
/// <para>This method performs no parameter checks.</para> /// <para>This method performs no parameter checks.</para>
/// </summary> /// </summary>
/// <param name="rnd">The random number generator to use.</param> /// <param name="rnd">The random number generator to use.</param>
/// <param name="shape">The shape of the Gamma distribution.</param> /// <param name="shape">The shape (k) of the Erlang distribution. Range: k ≥ 0.</param>
/// <param name="invScale">The inverse scale of the Gamma distribution.</param> /// <param name="rate">The rate or inverse scale (λ) of the Erlang distribution. Range: λ ≥ 0.</param>
/// <returns>A sample from a Erlang distributed random variable.</returns> /// <returns>A sample from a Erlang distributed random variable.</returns>
static double SampleUnchecked(System.Random rnd, double shape, double invScale) static double SampleUnchecked(System.Random rnd, double shape, double rate)
{ {
if (Double.IsPositiveInfinity(invScale)) if (Double.IsPositiveInfinity(rate))
{ {
return shape; return shape;
} }
@ -449,12 +447,12 @@ namespace MathNet.Numerics.Distributions
x = x*x; x = x*x;
if (u < 1.0 - (0.0331*x*x)) if (u < 1.0 - (0.0331*x*x))
{ {
return alphafix*d*v/invScale; return alphafix*d*v/rate;
} }
if (Math.Log(u) < (0.5*x) + (d*(1.0 - v + Math.Log(v)))) if (Math.Log(u) < (0.5*x) + (d*(1.0 - v + Math.Log(v))))
{ {
return alphafix*d*v/invScale; return alphafix*d*v/rate;
} }
} }
} }
@ -484,36 +482,36 @@ namespace MathNet.Numerics.Distributions
/// Generates a sample from the distribution. /// Generates a sample from the distribution.
/// </summary> /// </summary>
/// <param name="rnd">The random number generator to use.</param> /// <param name="rnd">The random number generator to use.</param>
/// <param name="shape">The shape of the Gamma distribution.</param> /// <param name="shape">The shape (k) of the Erlang distribution. Range: k ≥ 0.</param>
/// <param name="invScale">The inverse scale of the Gamma distribution.</param> /// <param name="rate">The rate or inverse scale (λ) of the Erlang distribution. Range: λ ≥ 0.</param>
/// <returns>a sample from the distribution.</returns> /// <returns>a sample from the distribution.</returns>
public static double Sample(System.Random rnd, double shape, double invScale) public static double Sample(System.Random rnd, double shape, double rate)
{ {
if (Control.CheckDistributionParameters && !IsValidParameterSet(shape, invScale)) if (Control.CheckDistributionParameters && !IsValidParameterSet(shape, rate))
{ {
throw new ArgumentOutOfRangeException(Resources.InvalidDistributionParameters); throw new ArgumentOutOfRangeException(Resources.InvalidDistributionParameters);
} }
return SampleUnchecked(rnd, shape, invScale); return SampleUnchecked(rnd, shape, rate);
} }
/// <summary> /// <summary>
/// Generates a sequence of samples from the distribution. /// Generates a sequence of samples from the distribution.
/// </summary> /// </summary>
/// <param name="rnd">The random number generator to use.</param> /// <param name="rnd">The random number generator to use.</param>
/// <param name="shape">The shape of the Gamma distribution.</param> /// <param name="shape">The shape (k) of the Erlang distribution. Range: k ≥ 0.</param>
/// <param name="invScale">The inverse scale of the Gamma distribution.</param> /// <param name="rate">The rate or inverse scale (λ) of the Erlang distribution. Range: λ ≥ 0.</param>
/// <returns>a sequence of samples from the distribution.</returns> /// <returns>a sequence of samples from the distribution.</returns>
public static IEnumerable<double> Samples(System.Random rnd, double shape, double invScale) public static IEnumerable<double> Samples(System.Random rnd, double shape, double rate)
{ {
if (Control.CheckDistributionParameters && !IsValidParameterSet(shape, invScale)) if (Control.CheckDistributionParameters && !IsValidParameterSet(shape, rate))
{ {
throw new ArgumentOutOfRangeException(Resources.InvalidDistributionParameters); throw new ArgumentOutOfRangeException(Resources.InvalidDistributionParameters);
} }
while (true) while (true)
{ {
yield return SampleUnchecked(rnd, shape, invScale); yield return SampleUnchecked(rnd, shape, rate);
} }
} }
} }

16
src/Numerics/Distributions/Exponential.cs

@ -53,7 +53,7 @@ namespace MathNet.Numerics.Distributions
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="Exponential"/> class. /// Initializes a new instance of the <see cref="Exponential"/> class.
/// </summary> /// </summary>
/// <param name="rate">The rate (λ) parameter of the Exponential distribution.</param> /// <param name="rate">The rate (λ) parameter of the distribution. Range: λ ≥ 0.</param>
public Exponential(double rate) public Exponential(double rate)
{ {
_random = new System.Random(); _random = new System.Random();
@ -63,7 +63,7 @@ namespace MathNet.Numerics.Distributions
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="Exponential"/> class. /// Initializes a new instance of the <see cref="Exponential"/> class.
/// </summary> /// </summary>
/// <param name="rate">The rate (λ) parameter of the Exponential distribution.</param> /// <param name="rate">The rate (λ) parameter of the distribution. Range: λ ≥ 0.</param>
/// <param name="randomSource">The random number generator which is used to draw random samples.</param> /// <param name="randomSource">The random number generator which is used to draw random samples.</param>
public Exponential(double rate, System.Random randomSource) public Exponential(double rate, System.Random randomSource)
{ {
@ -83,7 +83,7 @@ namespace MathNet.Numerics.Distributions
/// <summary> /// <summary>
/// Checks whether the parameters of the distribution are valid. /// Checks whether the parameters of the distribution are valid.
/// </summary> /// </summary>
/// <param name="rate">The rate (λ) parameter of the Exponential distribution.</param> /// <param name="rate">The rate (λ) parameter of the distribution. Range: λ ≥ 0.</param>
/// <returns><c>true</c> when the parameters are valid, <c>false</c> otherwise.</returns> /// <returns><c>true</c> when the parameters are valid, <c>false</c> otherwise.</returns>
static bool IsValidParameterSet(double rate) static bool IsValidParameterSet(double rate)
{ {
@ -93,7 +93,7 @@ namespace MathNet.Numerics.Distributions
/// <summary> /// <summary>
/// Sets the parameters of the distribution after checking their validity. /// Sets the parameters of the distribution after checking their validity.
/// </summary> /// </summary>
/// <param name="rate">The rate (λ) parameter of the Exponential distribution.</param> /// <param name="rate">The rate (λ) parameter of the distribution. Range: λ ≥ 0.</param>
/// <exception cref="ArgumentOutOfRangeException">When the parameters are out of range.</exception> /// <exception cref="ArgumentOutOfRangeException">When the parameters are out of range.</exception>
void SetParameters(double rate) void SetParameters(double rate)
{ {
@ -106,7 +106,7 @@ namespace MathNet.Numerics.Distributions
} }
/// <summary> /// <summary>
/// Gets or sets the rate (λ) parameter of the distribution. /// Gets or sets the rate (λ) parameter of the distribution. Range: λ ≥ 0.
/// </summary> /// </summary>
public double Rate public double Rate
{ {
@ -239,7 +239,7 @@ namespace MathNet.Numerics.Distributions
/// Samples the distribution. /// Samples the distribution.
/// </summary> /// </summary>
/// <param name="rnd">The random number generator to use.</param> /// <param name="rnd">The random number generator to use.</param>
/// <param name="rate">The rate (λ) parameter of the Exponential distribution.</param> /// <param name="rate">The rate (λ) parameter of the distribution. Range: λ ≥ 0.</param>
/// <returns>a random number from the distribution.</returns> /// <returns>a random number from the distribution.</returns>
static double SampleUnchecked(System.Random rnd, double rate) static double SampleUnchecked(System.Random rnd, double rate)
{ {
@ -277,7 +277,7 @@ namespace MathNet.Numerics.Distributions
/// Draws a random sample from the distribution. /// Draws a random sample from the distribution.
/// </summary> /// </summary>
/// <param name="rnd">The random number generator to use.</param> /// <param name="rnd">The random number generator to use.</param>
/// <param name="rate">The rate (λ) parameter of the Exponential distribution.</param> /// <param name="rate">The rate (λ) parameter of the distribution. Range: λ ≥ 0.</param>
/// <returns>A random number from this distribution.</returns> /// <returns>A random number from this distribution.</returns>
public static double Sample(System.Random rnd, double rate) public static double Sample(System.Random rnd, double rate)
{ {
@ -293,7 +293,7 @@ namespace MathNet.Numerics.Distributions
/// Generates a sequence of samples from the Exponential distribution. /// Generates a sequence of samples from the Exponential distribution.
/// </summary> /// </summary>
/// <param name="rnd">The random number generator to use.</param> /// <param name="rnd">The random number generator to use.</param>
/// <param name="rate">The rate (λ) parameter of the Exponential distribution.</param> /// <param name="rate">The rate (λ) parameter of the distribution. Range: λ ≥ 0.</param>
/// <returns>a sequence of samples from the distribution.</returns> /// <returns>a sequence of samples from the distribution.</returns>
public static IEnumerable<double> Samples(System.Random rnd, double rate) public static IEnumerable<double> Samples(System.Random rnd, double rate)
{ {

32
src/Numerics/Distributions/FisherSnedecor.cs

@ -54,8 +54,8 @@ namespace MathNet.Numerics.Distributions
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="FisherSnedecor"/> class. /// Initializes a new instance of the <see cref="FisherSnedecor"/> class.
/// </summary> /// </summary>
/// <param name="d1">The first degree of freedom (d1) of the distribution.</param> /// <param name="d1">The first degree of freedom (d1) of the distribution. Range: d1 > 0.</param>
/// <param name="d2">The second degree of freedom (d2) of the distribution.</param> /// <param name="d2">The second degree of freedom (d2) of the distribution. Range: d2 > 0.</param>
public FisherSnedecor(double d1, double d2) public FisherSnedecor(double d1, double d2)
{ {
_random = new System.Random(); _random = new System.Random();
@ -65,8 +65,8 @@ namespace MathNet.Numerics.Distributions
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="FisherSnedecor"/> class. /// Initializes a new instance of the <see cref="FisherSnedecor"/> class.
/// </summary> /// </summary>
/// <param name="d1">The first degree of freedom (d1) of the distribution.</param> /// <param name="d1">The first degree of freedom (d1) of the distribution. Range: d1 > 0.</param>
/// <param name="d2">The second degree of freedom (d2) of the distribution.</param> /// <param name="d2">The second degree of freedom (d2) of the distribution. Range: d2 > 0.</param>
/// <param name="randomSource">The random number generator which is used to draw random samples.</param> /// <param name="randomSource">The random number generator which is used to draw random samples.</param>
public FisherSnedecor(double d1, double d2, System.Random randomSource) public FisherSnedecor(double d1, double d2, System.Random randomSource)
{ {
@ -86,8 +86,8 @@ namespace MathNet.Numerics.Distributions
/// <summary> /// <summary>
/// Checks whether the parameters of the distribution are valid. /// Checks whether the parameters of the distribution are valid.
/// </summary> /// </summary>
/// <param name="d1">The first degree of freedom (d1) of the distribution.</param> /// <param name="d1">The first degree of freedom (d1) of the distribution. Range: d1 > 0.</param>
/// <param name="d2">The second degree of freedom (d2) of the distribution.</param> /// <param name="d2">The second degree of freedom (d2) of the distribution. Range: d2 > 0.</param>
/// <returns><c>true</c> when the parameters are valid, <c>false</c> otherwise.</returns> /// <returns><c>true</c> when the parameters are valid, <c>false</c> otherwise.</returns>
static bool IsValidParameterSet(double d1, double d2) static bool IsValidParameterSet(double d1, double d2)
{ {
@ -97,8 +97,8 @@ namespace MathNet.Numerics.Distributions
/// <summary> /// <summary>
/// Sets the parameters of the distribution after checking their validity. /// Sets the parameters of the distribution after checking their validity.
/// </summary> /// </summary>
/// <param name="d1">The first degree of freedom (d1) of the distribution.</param> /// <param name="d1">The first degree of freedom (d1) of the distribution. Range: d1 > 0.</param>
/// <param name="d2">The second degree of freedom (d2) of the distribution.</param> /// <param name="d2">The second degree of freedom (d2) of the distribution. Range: d2 > 0.</param>
/// <exception cref="ArgumentOutOfRangeException">When the parameters are out of range.</exception> /// <exception cref="ArgumentOutOfRangeException">When the parameters are out of range.</exception>
void SetParameters(double d1, double d2) void SetParameters(double d1, double d2)
{ {
@ -112,7 +112,7 @@ namespace MathNet.Numerics.Distributions
} }
/// <summary> /// <summary>
/// Gets or sets the first parameter - degree of freedom. /// Gets or sets the first degree of freedom (d1) of the distribution. Range: d1 > 0.
/// </summary> /// </summary>
public double DegreesOfFreedom1 public double DegreesOfFreedom1
{ {
@ -121,7 +121,7 @@ namespace MathNet.Numerics.Distributions
} }
/// <summary> /// <summary>
/// Gets or sets the second parameter - degree of freedom. /// Gets or sets the second degree of freedom (d2) of the distribution. Range: d2 > 0.
/// </summary> /// </summary>
public double DegreesOfFreedom2 public double DegreesOfFreedom2
{ {
@ -276,8 +276,8 @@ namespace MathNet.Numerics.Distributions
/// Generates one sample from the <c>FisherSnedecor</c> distribution without parameter checking. /// Generates one sample from the <c>FisherSnedecor</c> distribution without parameter checking.
/// </summary> /// </summary>
/// <param name="rnd">The random number generator to use.</param> /// <param name="rnd">The random number generator to use.</param>
/// <param name="d1">The first degree of freedom (d1) of the distribution.</param> /// <param name="d1">The first degree of freedom (d1) of the distribution. Range: d1 > 0.</param>
/// <param name="d2">The second degree of freedom (d2) of the distribution.</param> /// <param name="d2">The second degree of freedom (d2) of the distribution. Range: d2 > 0.</param>
/// <returns>a <c>FisherSnedecor</c> distributed random number.</returns> /// <returns>a <c>FisherSnedecor</c> distributed random number.</returns>
static double SampleUnchecked(System.Random rnd, double d1, double d2) static double SampleUnchecked(System.Random rnd, double d1, double d2)
{ {
@ -309,8 +309,8 @@ namespace MathNet.Numerics.Distributions
/// Generates a sample from the distribution. /// Generates a sample from the distribution.
/// </summary> /// </summary>
/// <param name="rnd">The random number generator to use.</param> /// <param name="rnd">The random number generator to use.</param>
/// <param name="d1">The first degree of freedom (d1) of the distribution.</param> /// <param name="d1">The first degree of freedom (d1) of the distribution. Range: d1 > 0.</param>
/// <param name="d2">The second degree of freedom (d2) of the distribution.</param> /// <param name="d2">The second degree of freedom (d2) of the distribution. Range: d2 > 0.</param>
/// <returns>a sample from the distribution.</returns> /// <returns>a sample from the distribution.</returns>
public static double Sample(System.Random rnd, double d1, double d2) public static double Sample(System.Random rnd, double d1, double d2)
{ {
@ -326,8 +326,8 @@ namespace MathNet.Numerics.Distributions
/// Generates a sequence of samples from the distribution. /// Generates a sequence of samples from the distribution.
/// </summary> /// </summary>
/// <param name="rnd">The random number generator to use.</param> /// <param name="rnd">The random number generator to use.</param>
/// <param name="d1">The first degree of freedom (d1) of the distribution.</param> /// <param name="d1">The first degree of freedom (d1) of the distribution. Range: d1 > 0.</param>
/// <param name="d2">The second degree of freedom (d2) of the distribution.</param> /// <param name="d2">The second degree of freedom (d2) of the distribution. Range: d2 > 0.</param>
/// <returns>a sequence of samples from the distribution.</returns> /// <returns>a sequence of samples from the distribution.</returns>
public static IEnumerable<double> Samples(System.Random rnd, double d1, double d2) public static IEnumerable<double> Samples(System.Random rnd, double d1, double d2)
{ {

40
src/Numerics/Distributions/Gamma.cs

@ -62,8 +62,8 @@ namespace MathNet.Numerics.Distributions
/// <summary> /// <summary>
/// Initializes a new instance of the Gamma class. /// Initializes a new instance of the Gamma class.
/// </summary> /// </summary>
/// <param name="shape">The shape (k, α) of the Gamma distribution.</param> /// <param name="shape">The shape (k, α) of the Gamma distribution. Range: α ≥ 0.</param>
/// <param name="rate">The rate or inverse scale (β) of the Gamma distribution.</param> /// <param name="rate">The rate or inverse scale (β) of the Gamma distribution. Range: β ≥ 0.</param>
public Gamma(double shape, double rate) public Gamma(double shape, double rate)
{ {
_random = new System.Random(); _random = new System.Random();
@ -73,8 +73,8 @@ namespace MathNet.Numerics.Distributions
/// <summary> /// <summary>
/// Initializes a new instance of the Gamma class. /// Initializes a new instance of the Gamma class.
/// </summary> /// </summary>
/// <param name="shape">The shape (k, α) of the Gamma distribution.</param> /// <param name="shape">The shape (k, α) of the Gamma distribution. Range: α ≥ 0.</param>
/// <param name="rate">The rate or inverse scale (β) of the Gamma distribution.</param> /// <param name="rate">The rate or inverse scale (β) of the Gamma distribution. Range: β ≥ 0.</param>
/// <param name="randomSource">The random number generator which is used to draw random samples.</param> /// <param name="randomSource">The random number generator which is used to draw random samples.</param>
public Gamma(double shape, double rate, System.Random randomSource) public Gamma(double shape, double rate, System.Random randomSource)
{ {
@ -86,8 +86,8 @@ namespace MathNet.Numerics.Distributions
/// Constructs a Gamma distribution from a shape and scale parameter. The distribution will /// Constructs a Gamma distribution from a shape and scale parameter. The distribution will
/// be initialized with the default <seealso cref="System.Random"/> random number generator. /// be initialized with the default <seealso cref="System.Random"/> random number generator.
/// </summary> /// </summary>
/// <param name="shape">The shape (k) of the Gamma distribution.</param> /// <param name="shape">The shape (k) of the Gamma distribution. Range: k ≥ 0.</param>
/// <param name="scale">The scale (θ) of the Gamma distribution.</param> /// <param name="scale">The scale (θ) of the Gamma distribution. Range: θ ≥ 0</param>
public static Gamma WithShapeScale(double shape, double scale) public static Gamma WithShapeScale(double shape, double scale)
{ {
return new Gamma(shape, 1.0/scale); return new Gamma(shape, 1.0/scale);
@ -97,8 +97,8 @@ namespace MathNet.Numerics.Distributions
/// Constructs a Gamma distribution from a shape and inverse scale parameter. The distribution will /// Constructs a Gamma distribution from a shape and inverse scale parameter. The distribution will
/// be initialized with the default <seealso cref="System.Random"/> random number generator. /// be initialized with the default <seealso cref="System.Random"/> random number generator.
/// </summary> /// </summary>
/// <param name="shape">The shape (α) of the Gamma distribution.</param> /// <param name="shape">The shape (k, α) of the Gamma distribution. Range: α ≥ 0.</param>
/// <param name="rate">The rate or inverse scale (β) of the Gamma distribution.</param> /// <param name="rate">The rate or inverse scale (β) of the Gamma distribution. Range: β ≥ 0.</param>
public static Gamma WithShapeRate(double shape, double rate) public static Gamma WithShapeRate(double shape, double rate)
{ {
return new Gamma(shape, rate); return new Gamma(shape, rate);
@ -116,8 +116,8 @@ namespace MathNet.Numerics.Distributions
/// <summary> /// <summary>
/// Checks whether the parameters of the distribution are valid. /// Checks whether the parameters of the distribution are valid.
/// </summary> /// </summary>
/// <param name="shape">The shape (k, α) of the Gamma distribution.</param> /// <param name="shape">The shape (k, α) of the Gamma distribution. Range: α ≥ 0.</param>
/// <param name="rate">The rate or inverse scale (β) of the Gamma distribution.</param> /// <param name="rate">The rate or inverse scale (β) of the Gamma distribution. Range: β ≥ 0.</param>
/// <returns><c>true</c> when the parameters are valid, <c>false</c> otherwise.</returns> /// <returns><c>true</c> when the parameters are valid, <c>false</c> otherwise.</returns>
static bool IsValidParameterSet(double shape, double rate) static bool IsValidParameterSet(double shape, double rate)
{ {
@ -127,8 +127,8 @@ namespace MathNet.Numerics.Distributions
/// <summary> /// <summary>
/// Sets the parameters of the distribution after checking their validity. /// Sets the parameters of the distribution after checking their validity.
/// </summary> /// </summary>
/// <param name="shape">The shape (k, α) of the Gamma distribution.</param> /// <param name="shape">The shape (k, α) of the Gamma distribution. Range: α ≥ 0.</param>
/// <param name="rate">The rate or inverse scale (β) of the Gamma distribution.</param> /// <param name="rate">The rate or inverse scale (β) of the Gamma distribution. Range: β ≥ 0.</param>
/// <exception cref="ArgumentOutOfRangeException">When the parameters are out of range.</exception> /// <exception cref="ArgumentOutOfRangeException">When the parameters are out of range.</exception>
void SetParameters(double shape, double rate) void SetParameters(double shape, double rate)
{ {
@ -142,7 +142,7 @@ namespace MathNet.Numerics.Distributions
} }
/// <summary> /// <summary>
/// Gets or sets the shape (k, α) of the Gamma distribution. /// Gets or sets the shape (k, α) of the Gamma distribution. Range: α ≥ 0.
/// </summary> /// </summary>
public double Shape public double Shape
{ {
@ -151,7 +151,7 @@ namespace MathNet.Numerics.Distributions
} }
/// <summary> /// <summary>
/// Gets or sets the rate or inverse scale (β) of the Gamma distribution. /// Gets or sets the rate or inverse scale (β) of the Gamma distribution. Range: β ≥ 0.
/// </summary> /// </summary>
public double Rate public double Rate
{ {
@ -412,8 +412,8 @@ namespace MathNet.Numerics.Distributions
/// <para>This method performs no parameter checks.</para> /// <para>This method performs no parameter checks.</para>
/// </summary> /// </summary>
/// <param name="rnd">The random number generator to use.</param> /// <param name="rnd">The random number generator to use.</param>
/// <param name="shape">The shape (k, α) of the Gamma distribution.</param> /// <param name="shape">The shape (k, α) of the Gamma distribution. Range: α ≥ 0.</param>
/// <param name="rate">The rate or inverse scale (β) of the Gamma distribution.</param> /// <param name="rate">The rate or inverse scale (β) of the Gamma distribution. Range: β ≥ 0.</param>
/// <returns>A sample from a Gamma distributed random variable.</returns> /// <returns>A sample from a Gamma distributed random variable.</returns>
internal static double SampleUnchecked(System.Random rnd, double shape, double rate) internal static double SampleUnchecked(System.Random rnd, double shape, double rate)
{ {
@ -484,8 +484,8 @@ namespace MathNet.Numerics.Distributions
/// Generates a sample from the Gamma distribution. /// Generates a sample from the Gamma distribution.
/// </summary> /// </summary>
/// <param name="rnd">The random number generator to use.</param> /// <param name="rnd">The random number generator to use.</param>
/// <param name="shape">The shape (k, α) of the Gamma distribution.</param> /// <param name="shape">The shape (k, α) of the Gamma distribution. Range: α ≥ 0.</param>
/// <param name="rate">The rate or inverse scale (β) of the Gamma distribution.</param> /// <param name="rate">The rate or inverse scale (β) of the Gamma distribution. Range: β ≥ 0.</param>
/// <returns>a sample from the distribution.</returns> /// <returns>a sample from the distribution.</returns>
public static double Sample(System.Random rnd, double shape, double rate) public static double Sample(System.Random rnd, double shape, double rate)
{ {
@ -501,8 +501,8 @@ namespace MathNet.Numerics.Distributions
/// Generates a sequence of samples from the Gamma distribution. /// Generates a sequence of samples from the Gamma distribution.
/// </summary> /// </summary>
/// <param name="rnd">The random number generator to use.</param> /// <param name="rnd">The random number generator to use.</param>
/// <param name="shape">The shape (k, α) of the Gamma distribution.</param> /// <param name="shape">The shape (k, α) of the Gamma distribution. Range: α ≥ 0.</param>
/// <param name="rate">The rate or inverse scale (β) of the Gamma distribution.</param> /// <param name="rate">The rate or inverse scale (β) of the Gamma distribution. Range: β ≥ 0.</param>
/// <returns>a sequence of samples from the distribution.</returns> /// <returns>a sequence of samples from the distribution.</returns>
public static IEnumerable<double> Samples(System.Random rnd, double shape, double rate) public static IEnumerable<double> Samples(System.Random rnd, double shape, double rate)
{ {

30
src/Numerics/Distributions/Geometric.cs

@ -38,7 +38,7 @@ namespace MathNet.Numerics.Distributions
/// Discrete Univariate Geometric distribution. /// Discrete Univariate Geometric distribution.
/// The Geometric distribution is a distribution over positive integers parameterized by one positive real number. /// The Geometric distribution is a distribution over positive integers parameterized by one positive real number.
/// This implementation of the Geometric distribution will never generate 0's. /// This implementation of the Geometric distribution will never generate 0's.
/// <a href="http://en.wikipedia.org/wiki/geometric_distribution">Wikipedia - geometric distribution</a>. /// <a href="http://en.wikipedia.org/wiki/Geometric_distribution">Wikipedia - geometric distribution</a>.
/// </summary> /// </summary>
/// <remarks><para>The distribution will use the <see cref="System.Random"/> by default. /// <remarks><para>The distribution will use the <see cref="System.Random"/> by default.
/// Users can set the random number generator by using the <see cref="RandomSource"/> property.</para> /// Users can set the random number generator by using the <see cref="RandomSource"/> property.</para>
@ -54,8 +54,7 @@ namespace MathNet.Numerics.Distributions
/// <summary> /// <summary>
/// Initializes a new instance of the Geometric class. /// Initializes a new instance of the Geometric class.
/// </summary> /// </summary>
/// <param name="p">The probability of generating one.</param> /// <param name="p">The probability (p) of generating one. Range: 0 ≤ p ≤ 1.</param>
/// <exception cref="ArgumentOutOfRangeException">If the Geometric parameter is not in the range [0,1].</exception>
public Geometric(double p) public Geometric(double p)
{ {
_random = new System.Random(); _random = new System.Random();
@ -65,9 +64,8 @@ namespace MathNet.Numerics.Distributions
/// <summary> /// <summary>
/// Initializes a new instance of the Geometric class. /// Initializes a new instance of the Geometric class.
/// </summary> /// </summary>
/// <param name="p">The probability of generating one.</param> /// <param name="p">The probability (p) of generating one. Range: 0 ≤ p ≤ 1.</param>
/// <param name="randomSource">The random number generator which is used to draw random samples.</param> /// <param name="randomSource">The random number generator which is used to draw random samples.</param>
/// <exception cref="ArgumentOutOfRangeException">If the Geometric parameter is not in the range [0,1].</exception>
public Geometric(double p, System.Random randomSource) public Geometric(double p, System.Random randomSource)
{ {
_random = randomSource ?? new System.Random(); _random = randomSource ?? new System.Random();
@ -77,18 +75,16 @@ namespace MathNet.Numerics.Distributions
/// <summary> /// <summary>
/// Returns a <see cref="System.String"/> that represents this instance. /// Returns a <see cref="System.String"/> that represents this instance.
/// </summary> /// </summary>
/// <returns> /// <returns>A <see cref="System.String"/> that represents this instance.</returns>
/// A <see cref="System.String"/> that represents this instance.
/// </returns>
public override string ToString() public override string ToString()
{ {
return "Geometric(P = " + _p + ")"; return "Geometric(p = " + _p + ")";
} }
/// <summary> /// <summary>
/// Checks whether the parameters of the distribution are valid. /// Checks whether the parameters of the distribution are valid.
/// </summary> /// </summary>
/// <param name="p">The probability of generating a one.</param> /// <param name="p">The probability (p) of generating one. Range: 0 ≤ p ≤ 1.</param>
/// <returns><c>true</c> when the parameters are valid, <c>false</c> otherwise.</returns> /// <returns><c>true</c> when the parameters are valid, <c>false</c> otherwise.</returns>
static bool IsValidParameterSet(double p) static bool IsValidParameterSet(double p)
{ {
@ -98,7 +94,7 @@ namespace MathNet.Numerics.Distributions
/// <summary> /// <summary>
/// Sets the parameters of the distribution after checking their validity. /// Sets the parameters of the distribution after checking their validity.
/// </summary> /// </summary>
/// <param name="p">The probability of generating a one.</param> /// <param name="p">The probability (p) of generating one. Range: 0 ≤ p ≤ 1.</param>
/// <exception cref="ArgumentOutOfRangeException">When the parameters are out of range.</exception> /// <exception cref="ArgumentOutOfRangeException">When the parameters are out of range.</exception>
void SetParameters(double p) void SetParameters(double p)
{ {
@ -111,7 +107,7 @@ namespace MathNet.Numerics.Distributions
} }
/// <summary> /// <summary>
/// Gets or sets the probability of generating a one. /// Gets or sets the probability of generating a one. Range: 0 ≤ p ≤ 1.
/// </summary> /// </summary>
public double P public double P
{ {
@ -245,10 +241,8 @@ namespace MathNet.Numerics.Distributions
/// Returns one sample from the distribution. /// Returns one sample from the distribution.
/// </summary> /// </summary>
/// <param name="rnd">The random number generator to use.</param> /// <param name="rnd">The random number generator to use.</param>
/// <param name="p">The p parameter</param> /// <param name="p">The probability (p) of generating one. Range: 0 ≤ p ≤ 1.</param>
/// <returns> /// <returns>One sample from the distribution implied by <paramref name="p"/>.</returns>
/// One sample from the distribution implied by <paramref name="p"/>.
/// </returns>
static int SampleUnchecked(System.Random rnd, double p) static int SampleUnchecked(System.Random rnd, double p)
{ {
return p == 1.0 ? 1 : (int) Math.Ceiling(-Math.Log(1.0 - rnd.NextDouble(), 1.0 - p)); return p == 1.0 ? 1 : (int) Math.Ceiling(-Math.Log(1.0 - rnd.NextDouble(), 1.0 - p));
@ -279,7 +273,7 @@ namespace MathNet.Numerics.Distributions
/// Samples a random variable. /// Samples a random variable.
/// </summary> /// </summary>
/// <param name="rnd">The random number generator to use.</param> /// <param name="rnd">The random number generator to use.</param>
/// <param name="p">The p parameter</param> /// <param name="p">The probability (p) of generating one. Range: 0 ≤ p ≤ 1.</param>
public static int Sample(System.Random rnd, double p) public static int Sample(System.Random rnd, double p)
{ {
if (Control.CheckDistributionParameters && !IsValidParameterSet(p)) if (Control.CheckDistributionParameters && !IsValidParameterSet(p))
@ -294,7 +288,7 @@ namespace MathNet.Numerics.Distributions
/// Samples a sequence of this random variable. /// Samples a sequence of this random variable.
/// </summary> /// </summary>
/// <param name="rnd">The random number generator to use.</param> /// <param name="rnd">The random number generator to use.</param>
/// <param name="p">The p parameter</param> /// <param name="p">The probability (p) of generating one. Range: 0 ≤ p ≤ 1.</param>
public static IEnumerable<int> Samples(System.Random rnd, double p) public static IEnumerable<int> Samples(System.Random rnd, double p)
{ {
if (Control.CheckDistributionParameters && !IsValidParameterSet(p)) if (Control.CheckDistributionParameters && !IsValidParameterSet(p))

32
src/Numerics/Distributions/InverseGamma.cs

@ -55,8 +55,8 @@ namespace MathNet.Numerics.Distributions
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="InverseGamma"/> class. /// Initializes a new instance of the <see cref="InverseGamma"/> class.
/// </summary> /// </summary>
/// <param name="shape">The shape (α) of the inverse Gamma distribution.</param> /// <param name="shape">The shape (α) of the distribution. Range: α > 0.</param>
/// <param name="scale">The scale (β) of the inverse Gamma distribution.</param> /// <param name="scale">The scale (β) of the distribution. Range: β > 0.</param>
public InverseGamma(double shape, double scale) public InverseGamma(double shape, double scale)
{ {
_random = new System.Random(); _random = new System.Random();
@ -66,8 +66,8 @@ namespace MathNet.Numerics.Distributions
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="InverseGamma"/> class. /// Initializes a new instance of the <see cref="InverseGamma"/> class.
/// </summary> /// </summary>
/// <param name="shape">The shape (α) of the inverse Gamma distribution.</param> /// <param name="shape">The shape (α) of the distribution. Range: α > 0.</param>
/// <param name="scale">The scale (β) of the inverse Gamma distribution.</param> /// <param name="scale">The scale (β) of the distribution. Range: β > 0.</param>
/// <param name="randomSource">The random number generator which is used to draw random samples.</param> /// <param name="randomSource">The random number generator which is used to draw random samples.</param>
public InverseGamma(double shape, double scale, System.Random randomSource) public InverseGamma(double shape, double scale, System.Random randomSource)
{ {
@ -87,8 +87,8 @@ namespace MathNet.Numerics.Distributions
/// <summary> /// <summary>
/// Checks whether the parameters of the distribution are valid. /// Checks whether the parameters of the distribution are valid.
/// </summary> /// </summary>
/// <param name="shape">The shape (α) of the inverse Gamma distribution.</param> /// <param name="shape">The shape (α) of the distribution. Range: α > 0.</param>
/// <param name="scale">The scale (β) of the inverse Gamma distribution.</param> /// <param name="scale">The scale (β) of the distribution. Range: β > 0.</param>
/// <returns><c>true</c> when the parameters are valid, <c>false</c> otherwise.</returns> /// <returns><c>true</c> when the parameters are valid, <c>false</c> otherwise.</returns>
static bool IsValidParameterSet(double shape, double scale) static bool IsValidParameterSet(double shape, double scale)
{ {
@ -98,8 +98,8 @@ namespace MathNet.Numerics.Distributions
/// <summary> /// <summary>
/// Sets the parameters of the distribution after checking their validity. /// Sets the parameters of the distribution after checking their validity.
/// </summary> /// </summary>
/// <param name="shape">The shape (α) of the inverse Gamma distribution.</param> /// <param name="shape">The shape (α) of the distribution. Range: α > 0.</param>
/// <param name="scale">The scale (β) of the inverse Gamma distribution.</param> /// <param name="scale">The scale (β) of the distribution. Range: β > 0.</param>
/// <exception cref="ArgumentOutOfRangeException">When the parameters are out of range.</exception> /// <exception cref="ArgumentOutOfRangeException">When the parameters are out of range.</exception>
void SetParameters(double shape, double scale) void SetParameters(double shape, double scale)
{ {
@ -113,7 +113,7 @@ namespace MathNet.Numerics.Distributions
} }
/// <summary> /// <summary>
/// Gets or sets the shape (α) parameter. /// Gets or sets the shape (α) parameter. Range: α > 0.
/// </summary> /// </summary>
public double Shape public double Shape
{ {
@ -122,7 +122,7 @@ namespace MathNet.Numerics.Distributions
} }
/// <summary> /// <summary>
/// Gets or sets The scale (β) parameter. /// Gets or sets The scale (β) parameter. Range: β > 0.
/// </summary> /// </summary>
public double Scale public double Scale
{ {
@ -275,8 +275,8 @@ namespace MathNet.Numerics.Distributions
/// Samples the distribution. /// Samples the distribution.
/// </summary> /// </summary>
/// <param name="rnd">The random number generator to use.</param> /// <param name="rnd">The random number generator to use.</param>
/// <param name="shape">The shape (α) of the inverse Gamma distribution.</param> /// <param name="shape">The shape (α) of the distribution. Range: α > 0.</param>
/// <param name="scale">The scale (β) of the inverse Gamma distribution.</param> /// <param name="scale">The scale (β) of the distribution. Range: β > 0.</param>
/// <returns>a random number from the distribution.</returns> /// <returns>a random number from the distribution.</returns>
static double SampleUnchecked(System.Random rnd, double shape, double scale) static double SampleUnchecked(System.Random rnd, double shape, double scale)
{ {
@ -308,8 +308,8 @@ namespace MathNet.Numerics.Distributions
/// Generates a sample from the distribution. /// Generates a sample from the distribution.
/// </summary> /// </summary>
/// <param name="rnd">The random number generator to use.</param> /// <param name="rnd">The random number generator to use.</param>
/// <param name="shape">The shape (α) of the inverse Gamma distribution.</param> /// <param name="shape">The shape (α) of the distribution. Range: α > 0.</param>
/// <param name="scale">The scale (β) of the inverse Gamma distribution.</param> /// <param name="scale">The scale (β) of the distribution. Range: β > 0.</param>
/// <returns>a sample from the distribution.</returns> /// <returns>a sample from the distribution.</returns>
public static double Sample(System.Random rnd, double shape, double scale) public static double Sample(System.Random rnd, double shape, double scale)
{ {
@ -325,8 +325,8 @@ namespace MathNet.Numerics.Distributions
/// Generates a sequence of samples from the distribution. /// Generates a sequence of samples from the distribution.
/// </summary> /// </summary>
/// <param name="rnd">The random number generator to use.</param> /// <param name="rnd">The random number generator to use.</param>
/// <param name="shape">The shape (α) of the inverse Gamma distribution.</param> /// <param name="shape">The shape (α) of the distribution. Range: α > 0.</param>
/// <param name="scale">The scale (β) of the inverse Gamma distribution.</param> /// <param name="scale">The scale (β) of the distribution. Range: β > 0.</param>
/// <returns>a sequence of samples from the distribution.</returns> /// <returns>a sequence of samples from the distribution.</returns>
public static IEnumerable<double> Samples(System.Random rnd, double shape, double scale) public static IEnumerable<double> Samples(System.Random rnd, double shape, double scale)
{ {

30
src/Numerics/Distributions/Laplace.cs

@ -64,8 +64,8 @@ namespace MathNet.Numerics.Distributions
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="Laplace"/> class. /// Initializes a new instance of the <see cref="Laplace"/> class.
/// </summary> /// </summary>
/// <param name="location">The location for the Laplace distribution.</param> /// <param name="location">The location (μ) of the distribution.</param>
/// <param name="scale">The scale for the Laplace distribution.</param> /// <param name="scale">The scale (b) of the distribution. Range: b > 0.</param>
/// <exception cref="ArgumentException">If <paramref name="scale"/> is negative.</exception> /// <exception cref="ArgumentException">If <paramref name="scale"/> is negative.</exception>
public Laplace(double location, double scale) public Laplace(double location, double scale)
{ {
@ -76,8 +76,8 @@ namespace MathNet.Numerics.Distributions
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="Laplace"/> class. /// Initializes a new instance of the <see cref="Laplace"/> class.
/// </summary> /// </summary>
/// <param name="location">The location for the Laplace distribution.</param> /// <param name="location">The location (μ) of the distribution.</param>
/// <param name="scale">The scale for the Laplace distribution.</param> /// <param name="scale">The scale (b) of the distribution. Range: b > 0.</param>
/// <param name="randomSource">The random number generator which is used to draw random samples.</param> /// <param name="randomSource">The random number generator which is used to draw random samples.</param>
/// <exception cref="ArgumentException">If <paramref name="scale"/> is negative.</exception> /// <exception cref="ArgumentException">If <paramref name="scale"/> is negative.</exception>
public Laplace(double location, double scale, System.Random randomSource) public Laplace(double location, double scale, System.Random randomSource)
@ -98,8 +98,8 @@ namespace MathNet.Numerics.Distributions
/// <summary> /// <summary>
/// Checks whether the parameters of the distribution are valid. /// Checks whether the parameters of the distribution are valid.
/// </summary> /// </summary>
/// <param name="location">The location (μ) of the Laplace distribution.</param> /// <param name="location">The location (μ) of the distribution.</param>
/// <param name="scale">The scale (b) of the Laplace distribution.</param> /// <param name="scale">The scale (b) of the distribution. Range: b > 0.</param>
/// <returns><c>true</c> when the parameters are valid, <c>false</c> otherwise.</returns> /// <returns><c>true</c> when the parameters are valid, <c>false</c> otherwise.</returns>
static bool IsValidParameterSet(double location, double scale) static bool IsValidParameterSet(double location, double scale)
{ {
@ -109,8 +109,8 @@ namespace MathNet.Numerics.Distributions
/// <summary> /// <summary>
/// Sets the parameters of the distribution after checking their validity. /// Sets the parameters of the distribution after checking their validity.
/// </summary> /// </summary>
/// <param name="location">The location (μ) of the Laplace distribution.</param> /// <param name="location">The location (μ) of the distribution.</param>
/// <param name="scale">The scale (b) of the Laplace distribution.</param> /// <param name="scale">The scale (b) of the distribution. Range: b > 0.</param>
/// <exception cref="ArgumentOutOfRangeException">When the parameters are out of range.</exception> /// <exception cref="ArgumentOutOfRangeException">When the parameters are out of range.</exception>
void SetParameters(double location, double scale) void SetParameters(double location, double scale)
{ {
@ -133,7 +133,7 @@ namespace MathNet.Numerics.Distributions
} }
/// <summary> /// <summary>
/// Gets or sets the scale (b) of the Laplace distribution. /// Gets or sets the scale (b) of the Laplace distribution. Range: b > 0.
/// </summary> /// </summary>
public double Scale public double Scale
{ {
@ -256,8 +256,8 @@ namespace MathNet.Numerics.Distributions
/// Samples the distribution. /// Samples the distribution.
/// </summary> /// </summary>
/// <param name="rnd">The random number generator to use.</param> /// <param name="rnd">The random number generator to use.</param>
/// <param name="location">The location (μ) of the Laplace distribution.</param> /// <param name="location">The location (μ) of the distribution.</param>
/// <param name="scale">The scale (b) of the Laplace distribution.</param> /// <param name="scale">The scale (b) of the distribution. Range: b > 0.</param>
/// <returns>a random number from the distribution.</returns> /// <returns>a random number from the distribution.</returns>
static double SampleUnchecked(System.Random rnd, double location, double scale) static double SampleUnchecked(System.Random rnd, double location, double scale)
{ {
@ -290,8 +290,8 @@ namespace MathNet.Numerics.Distributions
/// Generates a sample from the distribution. /// Generates a sample from the distribution.
/// </summary> /// </summary>
/// <param name="rnd">The random number generator to use.</param> /// <param name="rnd">The random number generator to use.</param>
/// <param name="location">The location (μ) of the Laplace distribution.</param> /// <param name="location">The location (μ) of the distribution.</param>
/// <param name="scale">The scale (b) of the Laplace distribution.</param> /// <param name="scale">The scale (b) of the distribution. Range: b > 0.</param>
/// <returns>a sample from the distribution.</returns> /// <returns>a sample from the distribution.</returns>
public static double Sample(System.Random rnd, double location, double scale) public static double Sample(System.Random rnd, double location, double scale)
{ {
@ -307,8 +307,8 @@ namespace MathNet.Numerics.Distributions
/// Generates a sequence of samples from the distribution. /// Generates a sequence of samples from the distribution.
/// </summary> /// </summary>
/// <param name="rnd">The random number generator to use.</param> /// <param name="rnd">The random number generator to use.</param>
/// <param name="location">The location (μ) of the Laplace distribution.</param> /// <param name="location">The location (μ) of the distribution.</param>
/// <param name="scale">The scale (b) of the Laplace distribution.</param> /// <param name="scale">The scale (b) of the distribution. Range: b > 0.</param>
/// <returns>a sequence of samples from the distribution.</returns> /// <returns>a sequence of samples from the distribution.</returns>
public static IEnumerable<double> Samples(System.Random rnd, double location, double scale) public static IEnumerable<double> Samples(System.Random rnd, double location, double scale)
{ {

32
src/Numerics/Distributions/NegativeBinomial.cs

@ -56,8 +56,8 @@ namespace MathNet.Numerics.Distributions
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="NegativeBinomial"/> class. /// Initializes a new instance of the <see cref="NegativeBinomial"/> class.
/// </summary> /// </summary>
/// <param name="r">The number of failures until the experiment stopped.</param> /// <param name="r">The number of failures (r) until the experiment stopped. Range: r ≥ 0.</param>
/// <param name="p">The probability of a trial resulting in success.</param> /// <param name="p">The probability (p) of a trial resulting in success. Range: 0 ≤ p ≤ 1.</param>
public NegativeBinomial(double r, double p) public NegativeBinomial(double r, double p)
{ {
_random = new System.Random(); _random = new System.Random();
@ -67,8 +67,8 @@ namespace MathNet.Numerics.Distributions
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="NegativeBinomial"/> class. /// Initializes a new instance of the <see cref="NegativeBinomial"/> class.
/// </summary> /// </summary>
/// <param name="r">The number of failures until the experiment stopped.</param> /// <param name="r">The number of failures (r) until the experiment stopped. Range: r ≥ 0.</param>
/// <param name="p">The probability of a trial resulting in success.</param> /// <param name="p">The probability (p) of a trial resulting in success. Range: 0 ≤ p ≤ 1.</param>
/// <param name="randomSource">The random number generator which is used to draw random samples.</param> /// <param name="randomSource">The random number generator which is used to draw random samples.</param>
public NegativeBinomial(double r, double p, System.Random randomSource) public NegativeBinomial(double r, double p, System.Random randomSource)
{ {
@ -90,8 +90,8 @@ namespace MathNet.Numerics.Distributions
/// <summary> /// <summary>
/// Checks whether the parameters of the distribution are valid. /// Checks whether the parameters of the distribution are valid.
/// </summary> /// </summary>
/// <param name="r">The number of failures until the experiment stopped.</param> /// <param name="r">The number of failures (r) until the experiment stopped. Range: r ≥ 0.</param>
/// <param name="p">The probability of a trial resulting in success.</param> /// <param name="p">The probability (p) of a trial resulting in success. Range: 0 ≤ p ≤ 1.</param>
/// <returns><c>true</c> when the parameters are valid, <c>false</c> otherwise.</returns> /// <returns><c>true</c> when the parameters are valid, <c>false</c> otherwise.</returns>
static bool IsValidParameterSet(double r, double p) static bool IsValidParameterSet(double r, double p)
{ {
@ -101,8 +101,8 @@ namespace MathNet.Numerics.Distributions
/// <summary> /// <summary>
/// Sets the parameters of the distribution after checking their validity. /// Sets the parameters of the distribution after checking their validity.
/// </summary> /// </summary>
/// <param name="r">The number of failures until the experiment stopped.</param> /// <param name="r">The number of failures (r) until the experiment stopped. Range: r ≥ 0.</param>
/// <param name="p">The probability of a trial resulting in success.</param> /// <param name="p">The probability (p) of a trial resulting in success. Range: 0 ≤ p ≤ 1.</param>
/// <exception cref="ArgumentOutOfRangeException">When the parameters are out of range.</exception> /// <exception cref="ArgumentOutOfRangeException">When the parameters are out of range.</exception>
void SetParameters(double r, double p) void SetParameters(double r, double p)
{ {
@ -116,7 +116,7 @@ namespace MathNet.Numerics.Distributions
} }
/// <summary> /// <summary>
/// Gets or sets the number of trials. /// Gets or sets the number of trials. Range: r ≥ 0.
/// </summary> /// </summary>
public double R public double R
{ {
@ -125,7 +125,7 @@ namespace MathNet.Numerics.Distributions
} }
/// <summary> /// <summary>
/// Gets or sets the probability of success. /// Gets or sets the probability of success. Range: 0 ≤ p ≤ 1.
/// </summary> /// </summary>
public double P public double P
{ {
@ -257,8 +257,8 @@ namespace MathNet.Numerics.Distributions
/// Samples a negative binomial distributed random variable. /// Samples a negative binomial distributed random variable.
/// </summary> /// </summary>
/// <param name="rnd">The random number generator to use.</param> /// <param name="rnd">The random number generator to use.</param>
/// <param name="r">The number of failures until the experiment stopped.</param> /// <param name="r">The number of failures (r) until the experiment stopped. Range: r ≥ 0.</param>
/// <param name="p">The probability of a trial resulting in success.</param> /// <param name="p">The probability (p) of a trial resulting in success. Range: 0 ≤ p ≤ 1.</param>
/// <returns>a sample from the distribution.</returns> /// <returns>a sample from the distribution.</returns>
static int SampleUnchecked(System.Random rnd, double r, double p) static int SampleUnchecked(System.Random rnd, double r, double p)
{ {
@ -299,8 +299,8 @@ namespace MathNet.Numerics.Distributions
/// Samples a random variable. /// Samples a random variable.
/// </summary> /// </summary>
/// <param name="rnd">The random number generator to use.</param> /// <param name="rnd">The random number generator to use.</param>
/// <param name="r">The number of failures until the experiment stopped.</param> /// <param name="r">The number of failures (r) until the experiment stopped. Range: r ≥ 0.</param>
/// <param name="p">The probability of a trial resulting in success.</param> /// <param name="p">The probability (p) of a trial resulting in success. Range: 0 ≤ p ≤ 1.</param>
public static int Sample(System.Random rnd, double r, double p) public static int Sample(System.Random rnd, double r, double p)
{ {
if (Control.CheckDistributionParameters && !IsValidParameterSet(r, p)) if (Control.CheckDistributionParameters && !IsValidParameterSet(r, p))
@ -315,8 +315,8 @@ namespace MathNet.Numerics.Distributions
/// Samples a sequence of this random variable. /// Samples a sequence of this random variable.
/// </summary> /// </summary>
/// <param name="rnd">The random number generator to use.</param> /// <param name="rnd">The random number generator to use.</param>
/// <param name="r">The number of failures until the experiment stopped.</param> /// <param name="r">The number of failures (r) until the experiment stopped. Range: r ≥ 0.</param>
/// <param name="p">The probability of a trial resulting in success.</param> /// <param name="p">The probability (p) of a trial resulting in success. Range: 0 ≤ p ≤ 1.</param>
public static IEnumerable<int> Samples(System.Random rnd, double r, double p) public static IEnumerable<int> Samples(System.Random rnd, double r, double p)
{ {
if (Control.CheckDistributionParameters && !IsValidParameterSet(r, p)) if (Control.CheckDistributionParameters && !IsValidParameterSet(r, p))

32
src/Numerics/Distributions/Pareto.cs

@ -56,8 +56,8 @@ namespace MathNet.Numerics.Distributions
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="Pareto"/> class. /// Initializes a new instance of the <see cref="Pareto"/> class.
/// </summary> /// </summary>
/// <param name="scale">The scale (xm) of the distribution.</param> /// <param name="scale">The scale (xm) of the distribution. Range: xm > 0.</param>
/// <param name="shape">The shape (α) of the distribution.</param> /// <param name="shape">The shape (α) of the distribution. Range: α > 0.</param>
/// <exception cref="ArgumentException">If <paramref name="scale"/> or <paramref name="shape"/> are negative.</exception> /// <exception cref="ArgumentException">If <paramref name="scale"/> or <paramref name="shape"/> are negative.</exception>
public Pareto(double scale, double shape) public Pareto(double scale, double shape)
{ {
@ -68,8 +68,8 @@ namespace MathNet.Numerics.Distributions
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="Pareto"/> class. /// Initializes a new instance of the <see cref="Pareto"/> class.
/// </summary> /// </summary>
/// <param name="scale">The scale (xm) of the distribution.</param> /// <param name="scale">The scale (xm) of the distribution. Range: xm > 0.</param>
/// <param name="shape">The shape (α) of the distribution.</param> /// <param name="shape">The shape (α) of the distribution. Range: α > 0.</param>
/// <param name="randomSource">The random number generator which is used to draw random samples.</param> /// <param name="randomSource">The random number generator which is used to draw random samples.</param>
/// <exception cref="ArgumentException">If <paramref name="scale"/> or <paramref name="shape"/> are negative.</exception> /// <exception cref="ArgumentException">If <paramref name="scale"/> or <paramref name="shape"/> are negative.</exception>
public Pareto(double scale, double shape, System.Random randomSource) public Pareto(double scale, double shape, System.Random randomSource)
@ -90,8 +90,8 @@ namespace MathNet.Numerics.Distributions
/// <summary> /// <summary>
/// Checks whether the parameters of the distribution are valid. /// Checks whether the parameters of the distribution are valid.
/// </summary> /// </summary>
/// <param name="scale">The scale (xm) of the distribution.</param> /// <param name="scale">The scale (xm) of the distribution. Range: xm > 0.</param>
/// <param name="shape">The shape (α) of the distribution.</param> /// <param name="shape">The shape (α) of the distribution. Range: α > 0.</param>
/// <returns><c>true</c> when the parameters are valid, <c>false</c> otherwise.</returns> /// <returns><c>true</c> when the parameters are valid, <c>false</c> otherwise.</returns>
static bool IsValidParameterSet(double scale, double shape) static bool IsValidParameterSet(double scale, double shape)
{ {
@ -101,8 +101,8 @@ namespace MathNet.Numerics.Distributions
/// <summary> /// <summary>
/// Sets the parameters of the distribution after checking their validity. /// Sets the parameters of the distribution after checking their validity.
/// </summary> /// </summary>
/// <param name="scale">The scale (xm) of the distribution.</param> /// <param name="scale">The scale (xm) of the distribution. Range: xm > 0.</param>
/// <param name="shape">The shape (α) of the distribution.</param> /// <param name="shape">The shape (α) of the distribution. Range: α > 0.</param>
/// <exception cref="ArgumentOutOfRangeException">When the parameters are out of range.</exception> /// <exception cref="ArgumentOutOfRangeException">When the parameters are out of range.</exception>
void SetParameters(double scale, double shape) void SetParameters(double scale, double shape)
{ {
@ -116,7 +116,7 @@ namespace MathNet.Numerics.Distributions
} }
/// <summary> /// <summary>
/// Gets or sets the scale (xm) of the distribution. /// Gets or sets the scale (xm) of the distribution. Range: xm > 0.
/// </summary> /// </summary>
public double Scale public double Scale
{ {
@ -125,7 +125,7 @@ namespace MathNet.Numerics.Distributions
} }
/// <summary> /// <summary>
/// Gets or sets the shape (α) of the distribution. /// Gets or sets the shape (α) of the distribution. Range: α > 0.
/// </summary> /// </summary>
public double Shape public double Shape
{ {
@ -264,8 +264,8 @@ namespace MathNet.Numerics.Distributions
/// Generates a sample from the Pareto distribution without doing parameter checking. /// Generates a sample from the Pareto distribution without doing parameter checking.
/// </summary> /// </summary>
/// <param name="rnd">The random number generator to use.</param> /// <param name="rnd">The random number generator to use.</param>
/// <param name="scale">The scale (xm) of the distribution.</param> /// <param name="scale">The scale (xm) of the distribution. Range: xm > 0.</param>
/// <param name="shape">The shape (α) of the distribution.</param> /// <param name="shape">The shape (α) of the distribution. Range: α > 0.</param>
/// <returns>a random number from the Pareto distribution.</returns> /// <returns>a random number from the Pareto distribution.</returns>
static double SampleUnchecked(System.Random rnd, double scale, double shape) static double SampleUnchecked(System.Random rnd, double scale, double shape)
{ {
@ -297,8 +297,8 @@ namespace MathNet.Numerics.Distributions
/// Generates a sample from the distribution. /// Generates a sample from the distribution.
/// </summary> /// </summary>
/// <param name="rnd">The random number generator to use.</param> /// <param name="rnd">The random number generator to use.</param>
/// <param name="scale">The scale (xm) of the distribution.</param> /// <param name="scale">The scale (xm) of the distribution. Range: xm > 0.</param>
/// <param name="shape">The shape (α) of the distribution.</param> /// <param name="shape">The shape (α) of the distribution. Range: α > 0.</param>
/// <returns>a sample from the distribution.</returns> /// <returns>a sample from the distribution.</returns>
public static double Sample(System.Random rnd, double scale, double shape) public static double Sample(System.Random rnd, double scale, double shape)
{ {
@ -314,8 +314,8 @@ namespace MathNet.Numerics.Distributions
/// Generates a sequence of samples from the distribution. /// Generates a sequence of samples from the distribution.
/// </summary> /// </summary>
/// <param name="rnd">The random number generator to use.</param> /// <param name="rnd">The random number generator to use.</param>
/// <param name="scale">The scale (xm) of the distribution.</param> /// <param name="scale">The scale (xm) of the distribution. Range: xm > 0.</param>
/// <param name="shape">The shape (α) of the distribution.</param> /// <param name="shape">The shape (α) of the distribution. Range: α > 0.</param>
/// <returns>a sequence of samples from the distribution.</returns> /// <returns>a sequence of samples from the distribution.</returns>
public static IEnumerable<double> Samples(System.Random rnd, double scale, double shape) public static IEnumerable<double> Samples(System.Random rnd, double scale, double shape)
{ {

20
src/Numerics/Distributions/Poisson.cs

@ -51,7 +51,7 @@ namespace MathNet.Numerics.Distributions
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="Poisson"/> class. /// Initializes a new instance of the <see cref="Poisson"/> class.
/// </summary> /// </summary>
/// <param name="lambda">The Poisson distribution parameter λ.</param> /// <param name="lambda">The lambda (λ) parameter of the Poisson distribution. Range: λ > 0.</param>
/// <exception cref="System.ArgumentOutOfRangeException">If <paramref name="lambda"/> is equal or less then 0.0.</exception> /// <exception cref="System.ArgumentOutOfRangeException">If <paramref name="lambda"/> is equal or less then 0.0.</exception>
public Poisson(double lambda) public Poisson(double lambda)
{ {
@ -62,7 +62,7 @@ namespace MathNet.Numerics.Distributions
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="Poisson"/> class. /// Initializes a new instance of the <see cref="Poisson"/> class.
/// </summary> /// </summary>
/// <param name="lambda">The Poisson distribution parameter λ.</param> /// <param name="lambda">The lambda (λ) parameter of the Poisson distribution. Range: λ > 0.</param>
/// <param name="randomSource">The random number generator which is used to draw random samples.</param> /// <param name="randomSource">The random number generator which is used to draw random samples.</param>
/// <exception cref="System.ArgumentOutOfRangeException">If <paramref name="lambda"/> is equal or less then 0.0.</exception> /// <exception cref="System.ArgumentOutOfRangeException">If <paramref name="lambda"/> is equal or less then 0.0.</exception>
public Poisson(double lambda, System.Random randomSource) public Poisson(double lambda, System.Random randomSource)
@ -85,7 +85,7 @@ namespace MathNet.Numerics.Distributions
/// <summary> /// <summary>
/// Checks whether the parameters of the distribution are valid. /// Checks whether the parameters of the distribution are valid.
/// </summary> /// </summary>
/// <param name="lambda">The mean (λ) of the distribution.</param> /// <param name="lambda">The lambda (λ) parameter of the Poisson distribution. Range: λ > 0.</param>
/// <returns><c>true</c> when the parameters are valid, <c>false</c> otherwise.</returns> /// <returns><c>true</c> when the parameters are valid, <c>false</c> otherwise.</returns>
static bool IsValidParameterSet(double lambda) static bool IsValidParameterSet(double lambda)
{ {
@ -95,7 +95,7 @@ namespace MathNet.Numerics.Distributions
/// <summary> /// <summary>
/// Sets the parameters of the distribution after checking their validity. /// Sets the parameters of the distribution after checking their validity.
/// </summary> /// </summary>
/// <param name="lambda">The mean (λ) of the distribution.</param> /// <param name="lambda">The lambda (λ) parameter of the Poisson distribution. Range: λ > 0.</param>
/// <exception cref="ArgumentOutOfRangeException">When the parameters are out of range.</exception> /// <exception cref="ArgumentOutOfRangeException">When the parameters are out of range.</exception>
void SetParameters(double lambda) void SetParameters(double lambda)
{ {
@ -108,7 +108,7 @@ namespace MathNet.Numerics.Distributions
} }
/// <summary> /// <summary>
/// Gets or sets the Poisson distribution parameter λ. /// Gets or sets the Poisson distribution parameter λ. Range: λ > 0.
/// </summary> /// </summary>
public double Lambda public double Lambda
{ {
@ -233,7 +233,7 @@ namespace MathNet.Numerics.Distributions
/// Generates one sample from the Poisson distribution. /// Generates one sample from the Poisson distribution.
/// </summary> /// </summary>
/// <param name="rnd">The random source to use.</param> /// <param name="rnd">The random source to use.</param>
/// <param name="lambda">The Poisson distribution parameter λ.</param> /// <param name="lambda">The lambda (λ) parameter of the Poisson distribution. Range: λ > 0.</param>
/// <returns>A random sample from the Poisson distribution.</returns> /// <returns>A random sample from the Poisson distribution.</returns>
static int SampleUnchecked(System.Random rnd, double lambda) static int SampleUnchecked(System.Random rnd, double lambda)
{ {
@ -244,7 +244,7 @@ namespace MathNet.Numerics.Distributions
/// Generates one sample from the Poisson distribution by Knuth's method. /// Generates one sample from the Poisson distribution by Knuth's method.
/// </summary> /// </summary>
/// <param name="rnd">The random source to use.</param> /// <param name="rnd">The random source to use.</param>
/// <param name="lambda">The Poisson distribution parameter λ.</param> /// <param name="lambda">The lambda (λ) parameter of the Poisson distribution. Range: λ > 0.</param>
/// <returns>A random sample from the Poisson distribution.</returns> /// <returns>A random sample from the Poisson distribution.</returns>
static int DoSampleShort(System.Random rnd, double lambda) static int DoSampleShort(System.Random rnd, double lambda)
{ {
@ -262,7 +262,7 @@ namespace MathNet.Numerics.Distributions
/// Generates one sample from the Poisson distribution by "Rejection method PA". /// Generates one sample from the Poisson distribution by "Rejection method PA".
/// </summary> /// </summary>
/// <param name="rnd">The random source to use.</param> /// <param name="rnd">The random source to use.</param>
/// <param name="lambda">The Poisson distribution parameter λ.</param> /// <param name="lambda">The lambda (λ) parameter of the Poisson distribution. Range: λ > 0.</param>
/// <returns>A random sample from the Poisson distribution.</returns> /// <returns>A random sample from the Poisson distribution.</returns>
/// <remarks>"Rejection method PA" from "The Computer Generation of Poisson Random Variables" by A. C. Atkinson, /// <remarks>"Rejection method PA" from "The Computer Generation of Poisson Random Variables" by A. C. Atkinson,
/// Journal of the Royal Statistical Society Series C (Applied Statistics) Vol. 28, No. 1. (1979) /// Journal of the Royal Statistical Society Series C (Applied Statistics) Vol. 28, No. 1. (1979)
@ -321,7 +321,7 @@ namespace MathNet.Numerics.Distributions
/// Samples a Poisson distributed random variable. /// Samples a Poisson distributed random variable.
/// </summary> /// </summary>
/// <param name="rnd">The random number generator to use.</param> /// <param name="rnd">The random number generator to use.</param>
/// <param name="lambda">The Poisson distribution parameter λ.</param> /// <param name="lambda">The lambda (λ) parameter of the Poisson distribution. Range: λ > 0.</param>
/// <returns>A sample from the Poisson distribution.</returns> /// <returns>A sample from the Poisson distribution.</returns>
public static int Sample(System.Random rnd, double lambda) public static int Sample(System.Random rnd, double lambda)
{ {
@ -337,7 +337,7 @@ namespace MathNet.Numerics.Distributions
/// Samples a sequence of Poisson distributed random variables. /// Samples a sequence of Poisson distributed random variables.
/// </summary> /// </summary>
/// <param name="rnd">The random number generator to use.</param> /// <param name="rnd">The random number generator to use.</param>
/// <param name="lambda">The Poisson distribution parameter λ.</param> /// <param name="lambda">The lambda (λ) parameter of the Poisson distribution. Range: λ > 0.</param>
/// <returns>a sequence of samples from the distribution.</returns> /// <returns>a sequence of samples from the distribution.</returns>
public static IEnumerable<int> Samples(System.Random rnd, double lambda) public static IEnumerable<int> Samples(System.Random rnd, double lambda)
{ {

16
src/Numerics/Distributions/Rayleigh.cs

@ -56,7 +56,7 @@ namespace MathNet.Numerics.Distributions
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="Rayleigh"/> class. /// Initializes a new instance of the <see cref="Rayleigh"/> class.
/// </summary> /// </summary>
/// <param name="scale">The scale (σ) of the distribution.</param> /// <param name="scale">The scale (σ) of the distribution. Range: σ > 0.</param>
/// <exception cref="ArgumentException">If <paramref name="scale"/> is negative.</exception> /// <exception cref="ArgumentException">If <paramref name="scale"/> is negative.</exception>
public Rayleigh(double scale) public Rayleigh(double scale)
{ {
@ -67,7 +67,7 @@ namespace MathNet.Numerics.Distributions
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="Rayleigh"/> class. /// Initializes a new instance of the <see cref="Rayleigh"/> class.
/// </summary> /// </summary>
/// <param name="scale">The scale (σ) of the distribution.</param> /// <param name="scale">The scale (σ) of the distribution. Range: σ > 0.</param>
/// <param name="randomSource">The random number generator which is used to draw random samples.</param> /// <param name="randomSource">The random number generator which is used to draw random samples.</param>
/// <exception cref="ArgumentException">If <paramref name="scale"/> is negative.</exception> /// <exception cref="ArgumentException">If <paramref name="scale"/> is negative.</exception>
public Rayleigh(double scale, System.Random randomSource) public Rayleigh(double scale, System.Random randomSource)
@ -88,7 +88,7 @@ namespace MathNet.Numerics.Distributions
/// <summary> /// <summary>
/// Checks whether the parameters of the distribution are valid. /// Checks whether the parameters of the distribution are valid.
/// </summary> /// </summary>
/// <param name="scale">The scale (σ) of the distribution.</param> /// <param name="scale">The scale (σ) of the distribution. Range: σ > 0.</param>
/// <returns><c>true</c> when the parameters are valid, <c>false</c> otherwise.</returns> /// <returns><c>true</c> when the parameters are valid, <c>false</c> otherwise.</returns>
static bool IsValidParameterSet(double scale) static bool IsValidParameterSet(double scale)
{ {
@ -98,7 +98,7 @@ namespace MathNet.Numerics.Distributions
/// <summary> /// <summary>
/// Sets the parameters of the distribution after checking their validity. /// Sets the parameters of the distribution after checking their validity.
/// </summary> /// </summary>
/// <param name="scale">The scale (σ) of the distribution.</param> /// <param name="scale">The scale (σ) of the distribution. Range: σ > 0.</param>
/// <exception cref="ArgumentOutOfRangeException">When the parameters are out of range.</exception> /// <exception cref="ArgumentOutOfRangeException">When the parameters are out of range.</exception>
void SetParameters(double scale) void SetParameters(double scale)
{ {
@ -111,7 +111,7 @@ namespace MathNet.Numerics.Distributions
} }
/// <summary> /// <summary>
/// Gets or sets the scale (σ) of the distribution. /// Gets or sets the scale (σ) of the distribution. Range: σ > 0.
/// </summary> /// </summary>
public double Scale public double Scale
{ {
@ -234,7 +234,7 @@ namespace MathNet.Numerics.Distributions
/// Generates a sample from the Rayleigh distribution without doing parameter checking. /// Generates a sample from the Rayleigh distribution without doing parameter checking.
/// </summary> /// </summary>
/// <param name="rnd">The random number generator to use.</param> /// <param name="rnd">The random number generator to use.</param>
/// <param name="scale">The scale (σ) of the distribution.</param> /// <param name="scale">The scale (σ) of the distribution. Range: σ > 0.</param>
/// <returns>a random number from the Rayleigh distribution.</returns> /// <returns>a random number from the Rayleigh distribution.</returns>
static double SampleUnchecked(System.Random rnd, double scale) static double SampleUnchecked(System.Random rnd, double scale)
{ {
@ -266,7 +266,7 @@ namespace MathNet.Numerics.Distributions
/// Generates a sample from the distribution. /// Generates a sample from the distribution.
/// </summary> /// </summary>
/// <param name="rnd">The random number generator to use.</param> /// <param name="rnd">The random number generator to use.</param>
/// <param name="scale">The scale (σ) of the distribution.</param> /// <param name="scale">The scale (σ) of the distribution. Range: σ > 0.</param>
/// <returns>a sample from the distribution.</returns> /// <returns>a sample from the distribution.</returns>
public static double Sample(System.Random rnd, double scale) public static double Sample(System.Random rnd, double scale)
{ {
@ -282,7 +282,7 @@ namespace MathNet.Numerics.Distributions
/// Generates a sequence of samples from the distribution. /// Generates a sequence of samples from the distribution.
/// </summary> /// </summary>
/// <param name="rnd">The random number generator to use.</param> /// <param name="rnd">The random number generator to use.</param>
/// <param name="scale">The scale (σ) of the distribution.</param> /// <param name="scale">The scale (σ) of the distribution. Range: σ > 0.</param>
/// <returns>a sequence of samples from the distribution.</returns> /// <returns>a sequence of samples from the distribution.</returns>
public static IEnumerable<double> Samples(System.Random rnd, double scale) public static IEnumerable<double> Samples(System.Random rnd, double scale)
{ {

48
src/Numerics/Distributions/Stable.cs

@ -59,9 +59,9 @@ namespace MathNet.Numerics.Distributions
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="Stable"/> class. /// Initializes a new instance of the <see cref="Stable"/> class.
/// </summary> /// </summary>
/// <param name="alpha">The stability (α) of the distribution.</param> /// <param name="alpha">The stability (α) of the distribution. Range: 2 ≥ α > 0.</param>
/// <param name="beta">The skewness (β) of the distribution.</param> /// <param name="beta">The skewness (β) of the distribution. Range: 1 ≥ β ≥ -1.</param>
/// <param name="scale">The scale (c) of the distribution.</param> /// <param name="scale">The scale (c) of the distribution. Range: c > 0.</param>
/// <param name="location">The location (μ) of the distribution.</param> /// <param name="location">The location (μ) of the distribution.</param>
public Stable(double alpha, double beta, double scale, double location) public Stable(double alpha, double beta, double scale, double location)
{ {
@ -72,9 +72,9 @@ namespace MathNet.Numerics.Distributions
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="Stable"/> class. /// Initializes a new instance of the <see cref="Stable"/> class.
/// </summary> /// </summary>
/// <param name="alpha">The stability (α) of the distribution.</param> /// <param name="alpha">The stability (α) of the distribution. Range: 2 ≥ α > 0.</param>
/// <param name="beta">The skewness (β) of the distribution.</param> /// <param name="beta">The skewness (β) of the distribution. Range: 1 ≥ β ≥ -1.</param>
/// <param name="scale">The scale (c) of the distribution.</param> /// <param name="scale">The scale (c) of the distribution. Range: c > 0.</param>
/// <param name="location">The location (μ) of the distribution.</param> /// <param name="location">The location (μ) of the distribution.</param>
/// <param name="randomSource">The random number generator which is used to draw random samples.</param> /// <param name="randomSource">The random number generator which is used to draw random samples.</param>
public Stable(double alpha, double beta, double scale, double location, System.Random randomSource) public Stable(double alpha, double beta, double scale, double location, System.Random randomSource)
@ -95,9 +95,9 @@ namespace MathNet.Numerics.Distributions
/// <summary> /// <summary>
/// Checks whether the parameters of the distribution are valid. /// Checks whether the parameters of the distribution are valid.
/// </summary> /// </summary>
/// <param name="alpha">The stability (α) of the distribution.</param> /// <param name="alpha">The stability (α) of the distribution. Range: 2 ≥ α > 0.</param>
/// <param name="beta">The skewness (β) of the distribution.</param> /// <param name="beta">The skewness (β) of the distribution. Range: 1 ≥ β ≥ -1.</param>
/// <param name="scale">The scale (c) of the distribution.</param> /// <param name="scale">The scale (c) of the distribution. Range: c > 0.</param>
/// <param name="location">The location (μ) of the distribution.</param> /// <param name="location">The location (μ) of the distribution.</param>
/// <returns><c>true</c> when the parameters are valid, <c>false</c> otherwise.</returns> /// <returns><c>true</c> when the parameters are valid, <c>false</c> otherwise.</returns>
static bool IsValidParameterSet(double alpha, double beta, double scale, double location) static bool IsValidParameterSet(double alpha, double beta, double scale, double location)
@ -108,9 +108,9 @@ namespace MathNet.Numerics.Distributions
/// <summary> /// <summary>
/// Sets the parameters of the distribution after checking their validity. /// Sets the parameters of the distribution after checking their validity.
/// </summary> /// </summary>
/// <param name="alpha">The stability (α) of the distribution.</param> /// <param name="alpha">The stability (α) of the distribution. Range: 2 ≥ α > 0.</param>
/// <param name="beta">The skewness (β) of the distribution.</param> /// <param name="beta">The skewness (β) of the distribution. Range: 1 ≥ β ≥ -1.</param>
/// <param name="scale">The scale (c) of the distribution.</param> /// <param name="scale">The scale (c) of the distribution. Range: c > 0.</param>
/// <param name="location">The location (μ) of the distribution.</param> /// <param name="location">The location (μ) of the distribution.</param>
/// <exception cref="ArgumentOutOfRangeException">When the parameters are out of range.</exception> /// <exception cref="ArgumentOutOfRangeException">When the parameters are out of range.</exception>
void SetParameters(double alpha, double beta, double scale, double location) void SetParameters(double alpha, double beta, double scale, double location)
@ -127,7 +127,7 @@ namespace MathNet.Numerics.Distributions
} }
/// <summary> /// <summary>
/// Gets or sets the stability (α) of the distribution. /// Gets or sets the stability (α) of the distribution. Range: 2 ≥ α > 0.
/// </summary> /// </summary>
public double Alpha public double Alpha
{ {
@ -136,7 +136,7 @@ namespace MathNet.Numerics.Distributions
} }
/// <summary> /// <summary>
/// Gets or sets The skewness (β) of the distribution. /// Gets or sets The skewness (β) of the distribution. Range: 1 ≥ β ≥ -1.
/// </summary> /// </summary>
public double Beta public double Beta
{ {
@ -145,7 +145,7 @@ namespace MathNet.Numerics.Distributions
} }
/// <summary> /// <summary>
/// Gets or sets the scale (c) of the distribution. /// Gets or sets the scale (c) of the distribution. Range: c > 0.
/// </summary> /// </summary>
public double Scale public double Scale
{ {
@ -399,9 +399,9 @@ namespace MathNet.Numerics.Distributions
/// Samples the distribution. /// Samples the distribution.
/// </summary> /// </summary>
/// <param name="rnd">The random number generator to use.</param> /// <param name="rnd">The random number generator to use.</param>
/// <param name="alpha">The stability (α) of the distribution.</param> /// <param name="alpha">The stability (α) of the distribution. Range: 2 ≥ α > 0.</param>
/// <param name="beta">The skewness (β) of the distribution.</param> /// <param name="beta">The skewness (β) of the distribution. Range: 1 ≥ β ≥ -1.</param>
/// <param name="scale">The scale (c) of the distribution.</param> /// <param name="scale">The scale (c) of the distribution. Range: c > 0.</param>
/// <param name="location">The location (μ) of the distribution.</param> /// <param name="location">The location (μ) of the distribution.</param>
/// <returns>a random number from the distribution.</returns> /// <returns>a random number from the distribution.</returns>
static double SampleUnchecked(System.Random rnd, double alpha, double beta, double scale, double location) static double SampleUnchecked(System.Random rnd, double alpha, double beta, double scale, double location)
@ -457,9 +457,9 @@ namespace MathNet.Numerics.Distributions
/// Generates a sample from the distribution. /// Generates a sample from the distribution.
/// </summary> /// </summary>
/// <param name="rnd">The random number generator to use.</param> /// <param name="rnd">The random number generator to use.</param>
/// <param name="alpha">The stability (α) of the distribution.</param> /// <param name="alpha">The stability (α) of the distribution. Range: 2 ≥ α > 0.</param>
/// <param name="beta">The skewness (β) of the distribution.</param> /// <param name="beta">The skewness (β) of the distribution. Range: 1 ≥ β ≥ -1.</param>
/// <param name="scale">The scale (c) of the distribution.</param> /// <param name="scale">The scale (c) of the distribution. Range: c > 0.</param>
/// <param name="location">The location (μ) of the distribution.</param> /// <param name="location">The location (μ) of the distribution.</param>
/// <returns>a sample from the distribution.</returns> /// <returns>a sample from the distribution.</returns>
public static double Sample(System.Random rnd, double alpha, double beta, double scale, double location) public static double Sample(System.Random rnd, double alpha, double beta, double scale, double location)
@ -476,9 +476,9 @@ namespace MathNet.Numerics.Distributions
/// Generates a sequence of samples from the distribution. /// Generates a sequence of samples from the distribution.
/// </summary> /// </summary>
/// <param name="rnd">The random number generator to use.</param> /// <param name="rnd">The random number generator to use.</param>
/// <param name="alpha">The stability (α) of the distribution.</param> /// <param name="alpha">The stability (α) of the distribution. Range: 2 ≥ α > 0.</param>
/// <param name="beta">The skewness (β) of the distribution.</param> /// <param name="beta">The skewness (β) of the distribution. Range: 1 ≥ β ≥ -1.</param>
/// <param name="scale">The scale (c) of the distribution.</param> /// <param name="scale">The scale (c) of the distribution. Range: c > 0.</param>
/// <param name="location">The location (μ) of the distribution.</param> /// <param name="location">The location (μ) of the distribution.</param>
/// <returns>a sequence of samples from the distribution.</returns> /// <returns>a sequence of samples from the distribution.</returns>
public static IEnumerable<double> Samples(System.Random rnd, double alpha, double beta, double scale, double location) public static IEnumerable<double> Samples(System.Random rnd, double alpha, double beta, double scale, double location)

32
src/Numerics/Distributions/StudentT.cs

@ -79,8 +79,8 @@ namespace MathNet.Numerics.Distributions
/// be initialized with the default <seealso cref="System.Random"/> random number generator. /// be initialized with the default <seealso cref="System.Random"/> random number generator.
/// </summary> /// </summary>
/// <param name="location">The location (μ) of the distribution.</param> /// <param name="location">The location (μ) of the distribution.</param>
/// <param name="scale">The scale (σ) of the distribution.</param> /// <param name="scale">The scale (σ) of the distribution. Range: σ > 0.</param>
/// <param name="freedom">The degrees of freedom (ν) for the distribution.</param> /// <param name="freedom">The degrees of freedom (ν) for the distribution. Range: ν > 0.</param>
public StudentT(double location, double scale, double freedom) public StudentT(double location, double scale, double freedom)
{ {
_random = new System.Random(); _random = new System.Random();
@ -93,8 +93,8 @@ namespace MathNet.Numerics.Distributions
/// be initialized with the default <seealso cref="System.Random"/> random number generator. /// be initialized with the default <seealso cref="System.Random"/> random number generator.
/// </summary> /// </summary>
/// <param name="location">The location (μ) of the distribution.</param> /// <param name="location">The location (μ) of the distribution.</param>
/// <param name="scale">The scale (σ) of the distribution.</param> /// <param name="scale">The scale (σ) of the distribution. Range: σ > 0.</param>
/// <param name="freedom">The degrees of freedom (ν) for the distribution.</param> /// <param name="freedom">The degrees of freedom (ν) for the distribution. Range: ν > 0.</param>
/// <param name="randomSource">The random number generator which is used to draw random samples.</param> /// <param name="randomSource">The random number generator which is used to draw random samples.</param>
public StudentT(double location, double scale, double freedom, System.Random randomSource) public StudentT(double location, double scale, double freedom, System.Random randomSource)
{ {
@ -115,8 +115,8 @@ namespace MathNet.Numerics.Distributions
/// Checks whether the parameters of the distribution are valid. /// Checks whether the parameters of the distribution are valid.
/// </summary> /// </summary>
/// <param name="location">The location (μ) of the distribution.</param> /// <param name="location">The location (μ) of the distribution.</param>
/// <param name="scale">The scale (σ) of the distribution.</param> /// <param name="scale">The scale (σ) of the distribution. Range: σ > 0.</param>
/// <param name="freedom">The degrees of freedom (ν) for the distribution.</param> /// <param name="freedom">The degrees of freedom (ν) for the distribution. Range: ν > 0.</param>
/// <returns><c>true</c> when the parameters are valid, <c>false</c> otherwise.</returns> /// <returns><c>true</c> when the parameters are valid, <c>false</c> otherwise.</returns>
static bool IsValidParameterSet(double location, double scale, double freedom) static bool IsValidParameterSet(double location, double scale, double freedom)
{ {
@ -127,8 +127,8 @@ namespace MathNet.Numerics.Distributions
/// Sets the parameters of the distribution after checking their validity. /// Sets the parameters of the distribution after checking their validity.
/// </summary> /// </summary>
/// <param name="location">The location (μ) of the distribution.</param> /// <param name="location">The location (μ) of the distribution.</param>
/// <param name="scale">The scale (σ) of the distribution.</param> /// <param name="scale">The scale (σ) of the distribution. Range: σ > 0.</param>
/// <param name="freedom">The degrees of freedom (ν) for the distribution.</param> /// <param name="freedom">The degrees of freedom (ν) for the distribution. Range: ν > 0.</param>
/// <exception cref="ArgumentOutOfRangeException">When the parameters are out of range.</exception> /// <exception cref="ArgumentOutOfRangeException">When the parameters are out of range.</exception>
void SetParameters(double location, double scale, double freedom) void SetParameters(double location, double scale, double freedom)
{ {
@ -152,7 +152,7 @@ namespace MathNet.Numerics.Distributions
} }
/// <summary> /// <summary>
/// Gets or sets the scale (σ) of the Student t-distribution. /// Gets or sets the scale (σ) of the Student t-distribution. Range: σ > 0.
/// </summary> /// </summary>
public double Scale public double Scale
{ {
@ -161,7 +161,7 @@ namespace MathNet.Numerics.Distributions
} }
/// <summary> /// <summary>
/// Gets or sets the degrees of freedom (ν) of the Student t-distribution. /// Gets or sets the degrees of freedom (ν) of the Student t-distribution. Range: ν > 0.
/// </summary> /// </summary>
public double DegreesOfFreedom public double DegreesOfFreedom
{ {
@ -353,8 +353,8 @@ namespace MathNet.Numerics.Distributions
/// in L. Devroye's "Non-Uniform Random Variate Generation"</remarks> /// in L. Devroye's "Non-Uniform Random Variate Generation"</remarks>
/// <param name="rnd">The random number generator to use.</param> /// <param name="rnd">The random number generator to use.</param>
/// <param name="location">The location (μ) of the distribution.</param> /// <param name="location">The location (μ) of the distribution.</param>
/// <param name="scale">The scale (σ) of the distribution.</param> /// <param name="scale">The scale (σ) of the distribution. Range: σ > 0.</param>
/// <param name="freedom">The degrees of freedom (ν) for the distribution.</param> /// <param name="freedom">The degrees of freedom (ν) for the distribution. Range: ν > 0.</param>
/// <returns>a random number from the standard student-t distribution.</returns> /// <returns>a random number from the standard student-t distribution.</returns>
static double SampleUnchecked(System.Random rnd, double location, double scale, double freedom) static double SampleUnchecked(System.Random rnd, double location, double scale, double freedom)
{ {
@ -388,8 +388,8 @@ namespace MathNet.Numerics.Distributions
/// </summary> /// </summary>
/// <param name="rnd">The random number generator to use.</param> /// <param name="rnd">The random number generator to use.</param>
/// <param name="location">The location (μ) of the distribution.</param> /// <param name="location">The location (μ) of the distribution.</param>
/// <param name="scale">The scale (σ) of the distribution.</param> /// <param name="scale">The scale (σ) of the distribution. Range: σ > 0.</param>
/// <param name="freedom">The degrees of freedom (ν) for the distribution.</param> /// <param name="freedom">The degrees of freedom (ν) for the distribution. Range: ν > 0.</param>
/// <returns>a sample from the distribution.</returns> /// <returns>a sample from the distribution.</returns>
public static double Sample(System.Random rnd, double location, double scale, double freedom) public static double Sample(System.Random rnd, double location, double scale, double freedom)
{ {
@ -406,8 +406,8 @@ namespace MathNet.Numerics.Distributions
/// </summary> /// </summary>
/// <param name="rnd">The random number generator to use.</param> /// <param name="rnd">The random number generator to use.</param>
/// <param name="location">The location (μ) of the distribution.</param> /// <param name="location">The location (μ) of the distribution.</param>
/// <param name="scale">The scale (σ) of the distribution.</param> /// <param name="scale">The scale (σ) of the distribution. Range: σ > 0.</param>
/// <param name="freedom">The degrees of freedom (ν) for the distribution.</param> /// <param name="freedom">The degrees of freedom (ν) for the distribution. Range: ν > 0.</param>
/// <returns>a sequence of samples from the distribution.</returns> /// <returns>a sequence of samples from the distribution.</returns>
public static IEnumerable<double> Samples(System.Random rnd, double location, double scale, double freedom) public static IEnumerable<double> Samples(System.Random rnd, double location, double scale, double freedom)
{ {

32
src/Numerics/Distributions/Weibull.cs

@ -65,8 +65,8 @@ namespace MathNet.Numerics.Distributions
/// <summary> /// <summary>
/// Initializes a new instance of the Weibull class. /// Initializes a new instance of the Weibull class.
/// </summary> /// </summary>
/// <param name="shape">The shape (k) of the Weibull distribution.</param> /// <param name="shape">The shape (k) of the Weibull distribution. Range: k > 0.</param>
/// <param name="scale">The scale (λ) of the Weibull distribution.</param> /// <param name="scale">The scale (λ) of the Weibull distribution. Range: λ > 0.</param>
public Weibull(double shape, double scale) public Weibull(double shape, double scale)
{ {
_random = new System.Random(); _random = new System.Random();
@ -76,8 +76,8 @@ namespace MathNet.Numerics.Distributions
/// <summary> /// <summary>
/// Initializes a new instance of the Weibull class. /// Initializes a new instance of the Weibull class.
/// </summary> /// </summary>
/// <param name="shape">The shape (k) of the Weibull distribution.</param> /// <param name="shape">The shape (k) of the Weibull distribution. Range: k > 0.</param>
/// <param name="scale">The scale (λ) of the Weibull distribution.</param> /// <param name="scale">The scale (λ) of the Weibull distribution. Range: λ > 0.</param>
/// <param name="randomSource">The random number generator which is used to draw random samples.</param> /// <param name="randomSource">The random number generator which is used to draw random samples.</param>
public Weibull(double shape, double scale, System.Random randomSource) public Weibull(double shape, double scale, System.Random randomSource)
{ {
@ -97,8 +97,8 @@ namespace MathNet.Numerics.Distributions
/// <summary> /// <summary>
/// Checks whether the parameters of the distribution are valid. /// Checks whether the parameters of the distribution are valid.
/// </summary> /// </summary>
/// <param name="shape">The shape (k) of the Weibull distribution.</param> /// <param name="shape">The shape (k) of the Weibull distribution. Range: k > 0.</param>
/// <param name="scale">The scale (λ) of the Weibull distribution.</param> /// <param name="scale">The scale (λ) of the Weibull distribution. Range: λ > 0.</param>
/// <returns><c>true</c> when the parameters positive valid floating point numbers, <c>false</c> otherwise.</returns> /// <returns><c>true</c> when the parameters positive valid floating point numbers, <c>false</c> otherwise.</returns>
static bool IsValidParameterSet(double shape, double scale) static bool IsValidParameterSet(double shape, double scale)
{ {
@ -108,8 +108,8 @@ namespace MathNet.Numerics.Distributions
/// <summary> /// <summary>
/// Sets the parameters of the distribution after checking their validity. /// Sets the parameters of the distribution after checking their validity.
/// </summary> /// </summary>
/// <param name="shape">The shape (k) of the Weibull distribution.</param> /// <param name="shape">The shape (k) of the Weibull distribution. Range: k > 0.</param>
/// <param name="scale">The scale (λ) of the Weibull distribution.</param> /// <param name="scale">The scale (λ) of the Weibull distribution. Range: λ > 0.</param>
/// <exception cref="ArgumentOutOfRangeException">When the parameters are out of range.</exception> /// <exception cref="ArgumentOutOfRangeException">When the parameters are out of range.</exception>
void SetParameters(double shape, double scale) void SetParameters(double shape, double scale)
{ {
@ -124,7 +124,7 @@ namespace MathNet.Numerics.Distributions
} }
/// <summary> /// <summary>
/// Gets or sets the shape (k) of the Weibull distribution. /// Gets or sets the shape (k) of the Weibull distribution. Range: k > 0.
/// </summary> /// </summary>
public double Shape public double Shape
{ {
@ -133,7 +133,7 @@ namespace MathNet.Numerics.Distributions
} }
/// <summary> /// <summary>
/// Gets or sets the scale (λ) of the Weibull distribution. /// Gets or sets the scale (λ) of the Weibull distribution. Range: λ > 0.
/// </summary> /// </summary>
public double Scale public double Scale
{ {
@ -297,8 +297,8 @@ namespace MathNet.Numerics.Distributions
/// any parameter checks. /// any parameter checks.
/// </summary> /// </summary>
/// <param name="rnd">The random number generator to use.</param> /// <param name="rnd">The random number generator to use.</param>
/// <param name="shape">The shape (k) of the Weibull distribution.</param> /// <param name="shape">The shape (k) of the Weibull distribution. Range: k > 0.</param>
/// <param name="scale">The scale (λ) of the Weibull distribution.</param> /// <param name="scale">The scale (λ) of the Weibull distribution. Range: λ > 0.</param>
/// <returns>A sample from a Weibull distributed random variable.</returns> /// <returns>A sample from a Weibull distributed random variable.</returns>
static double SampleUnchecked(System.Random rnd, double shape, double scale) static double SampleUnchecked(System.Random rnd, double shape, double scale)
{ {
@ -331,8 +331,8 @@ namespace MathNet.Numerics.Distributions
/// Generates a sample from the Weibull distribution. /// Generates a sample from the Weibull distribution.
/// </summary> /// </summary>
/// <param name="rnd">The random number generator to use.</param> /// <param name="rnd">The random number generator to use.</param>
/// <param name="shape">The shape (k) of the Weibull distribution.</param> /// <param name="shape">The shape (k) of the Weibull distribution. Range: k > 0.</param>
/// <param name="scale">The scale (λ) of the Weibull distribution.</param> /// <param name="scale">The scale (λ) of the Weibull distribution. Range: λ > 0.</param>
/// <returns>a sample from the distribution.</returns> /// <returns>a sample from the distribution.</returns>
public static double Sample(System.Random rnd, double shape, double scale) public static double Sample(System.Random rnd, double shape, double scale)
{ {
@ -348,8 +348,8 @@ namespace MathNet.Numerics.Distributions
/// Generates a sequence of samples from the Weibull distribution. /// Generates a sequence of samples from the Weibull distribution.
/// </summary> /// </summary>
/// <param name="rnd">The random number generator to use.</param> /// <param name="rnd">The random number generator to use.</param>
/// <param name="shape">The shape (k) of the Weibull distribution.</param> /// <param name="shape">The shape (k) of the Weibull distribution. Range: k > 0.</param>
/// <param name="scale">The scale (λ) of the Weibull distribution.</param> /// <param name="scale">The scale (λ) of the Weibull distribution. Range: λ > 0.</param>
/// <returns>a sequence of samples from the distribution.</returns> /// <returns>a sequence of samples from the distribution.</returns>
public static IEnumerable<double> Samples(System.Random rnd, double shape, double scale) public static IEnumerable<double> Samples(System.Random rnd, double shape, double scale)
{ {

Loading…
Cancel
Save