Browse Source

Distributions: prototype for slightly modified api on normal, log-normal

pull/163/head
Christoph Ruegg 13 years ago
parent
commit
f1dbedd766
  1. 1
      .gitattributes
  2. 1
      MathNet.Numerics.sln.DotSettings
  3. 4
      src/Numerics/Distributions/Bernoulli.cs
  4. 8
      src/Numerics/Distributions/Beta.cs
  5. 2
      src/Numerics/Distributions/Binomial.cs
  6. 4
      src/Numerics/Distributions/Categorical.cs
  7. 8
      src/Numerics/Distributions/Cauchy.cs
  8. 8
      src/Numerics/Distributions/Chi.cs
  9. 8
      src/Numerics/Distributions/ChiSquared.cs
  10. 10
      src/Numerics/Distributions/ContinuousUniform.cs
  11. 4
      src/Numerics/Distributions/ConwayMaxwellPoisson.cs
  12. 2
      src/Numerics/Distributions/Dirichlet.cs
  13. 4
      src/Numerics/Distributions/DiscreteUniform.cs
  14. 7
      src/Numerics/Distributions/Erlang.cs
  15. 8
      src/Numerics/Distributions/Exponential.cs
  16. 7
      src/Numerics/Distributions/FisherSnedecor.cs
  17. 8
      src/Numerics/Distributions/Gamma.cs
  18. 4
      src/Numerics/Distributions/Geometric.cs
  19. 3
      src/Numerics/Distributions/Hypergeometric.cs
  20. 4
      src/Numerics/Distributions/IContinuousDistribution.cs
  21. 2
      src/Numerics/Distributions/IUnivariateDistribution.cs
  22. 8
      src/Numerics/Distributions/InverseGamma.cs
  23. 2
      src/Numerics/Distributions/InverseWishart.cs
  24. 8
      src/Numerics/Distributions/Laplace.cs
  25. 135
      src/Numerics/Distributions/LogNormal.cs
  26. 2
      src/Numerics/Distributions/MatrixNormal.cs
  27. 2
      src/Numerics/Distributions/Multinomial.cs
  28. 4
      src/Numerics/Distributions/NegativeBinomial.cs
  29. 242
      src/Numerics/Distributions/Normal.cs
  30. 2
      src/Numerics/Distributions/NormalGamma.cs
  31. 8
      src/Numerics/Distributions/Pareto.cs
  32. 4
      src/Numerics/Distributions/Poisson.cs
  33. 8
      src/Numerics/Distributions/Rayleigh.cs
  34. 7
      src/Numerics/Distributions/Stable.cs
  35. 16
      src/Numerics/Distributions/StudentT.cs
  36. 8
      src/Numerics/Distributions/Weibull.cs
  37. 2
      src/Numerics/Distributions/Wishart.cs
  38. 3
      src/Numerics/Distributions/Zipf.cs
  39. 3
      src/UnitTests/DistributionTests/Continuous/LogNormalTests.cs
  40. 4
      src/UnitTests/DistributionTests/Continuous/NormalTests.cs

1
.gitattributes

@ -7,6 +7,7 @@
*.xml text *.xml text
*.js text *.js text
*.ps1 text *.ps1 text
*.DotSettings text
*.csproj text merge=union *.csproj text merge=union
*.fsproj text merge=union *.fsproj text merge=union

1
MathNet.Numerics.sln.DotSettings

@ -54,6 +54,7 @@ OTHER DEALINGS IN THE SOFTWARE.
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=MC/@EntryIndexedValue">MC</s:String> <s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=MC/@EntryIndexedValue">MC</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=MCMC/@EntryIndexedValue">MCMC</s:String> <s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=MCMC/@EntryIndexedValue">MCMC</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=MSE/@EntryIndexedValue">MSE</s:String> <s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=MSE/@EntryIndexedValue">MSE</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=PDF/@EntryIndexedValue">PDF</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=QR/@EntryIndexedValue">QR</s:String> <s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=QR/@EntryIndexedValue">QR</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=SAD/@EntryIndexedValue">SAD</s:String> <s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=SAD/@EntryIndexedValue">SAD</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=SAS/@EntryIndexedValue">SAS</s:String> <s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=SAS/@EntryIndexedValue">SAS</s:String>

4
src/Numerics/Distributions/Bernoulli.cs

@ -97,7 +97,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="p">The probability of generating a one.</param> /// <param name="p">The probability of generating a one.</param>
/// <exception cref="ArgumentOutOfRangeException">When the parameters don't pass the <see cref="IsValidParameterSet"/> function.</exception> /// <exception cref="ArgumentOutOfRangeException">When the parameters are out of range.</exception>
void SetParameters(double p) void SetParameters(double p)
{ {
if (Control.CheckDistributionParameters && !IsValidParameterSet(p)) if (Control.CheckDistributionParameters && !IsValidParameterSet(p))
@ -234,7 +234,7 @@ namespace MathNet.Numerics.Distributions
} }
/// <summary> /// <summary>
/// Computes the cumulative distribution (CDF) of the distribution at x, i.e. P(X &lt;= x). /// Computes the cumulative distribution (CDF) of the distribution at x, i.e. P(X x).
/// </summary> /// </summary>
/// <param name="x">The location at which to compute the cumulative distribution function.</param> /// <param name="x">The location at which to compute the cumulative distribution function.</param>
/// <returns>the cumulative distribution at location <paramref name="x"/>.</returns> /// <returns>the cumulative distribution at location <paramref name="x"/>.</returns>

8
src/Numerics/Distributions/Beta.cs

@ -108,7 +108,7 @@ namespace MathNet.Numerics.Distributions
/// </summary> /// </summary>
/// <param name="a">The α shape parameter of the Beta distribution.</param> /// <param name="a">The α shape parameter of the Beta distribution.</param>
/// <param name="b">The β shape parameter of the Beta distribution.</param> /// <param name="b">The β shape parameter of the Beta distribution.</param>
/// <exception cref="ArgumentOutOfRangeException">When the parameters don't pass the <see cref="IsValidParameterSet"/> function.</exception> /// <exception cref="ArgumentOutOfRangeException">When the parameters are out of range.</exception>
void SetParameters(double a, double b) void SetParameters(double a, double b)
{ {
if (Control.CheckDistributionParameters && !IsValidParameterSet(a, b)) if (Control.CheckDistributionParameters && !IsValidParameterSet(a, b))
@ -346,7 +346,7 @@ namespace MathNet.Numerics.Distributions
} }
/// <summary> /// <summary>
/// Computes the probability density of the distribution (PDF) at x, i.e. dP(X &lt;= x)/dx. /// Computes the probability density of the distribution (PDF) at x, i.e. ∂P(X ≤ x)/∂x.
/// </summary> /// </summary>
/// <param name="x">The location at which to compute the density.</param> /// <param name="x">The location at which to compute the density.</param>
/// <returns>the density at <paramref name="x"/>.</returns> /// <returns>the density at <paramref name="x"/>.</returns>
@ -402,7 +402,7 @@ namespace MathNet.Numerics.Distributions
} }
/// <summary> /// <summary>
/// Computes the log probability density of the distribution (lnPDF) at x, i.e. ln(dP(X &lt;= x)/dx). /// Computes the log probability density of the distribution (lnPDF) at x, i.e. ln(∂P(X ≤ x)/∂x).
/// </summary> /// </summary>
/// <param name="x">The location at which to compute the log density.</param> /// <param name="x">The location at which to compute the log density.</param>
/// <returns>the log density at <paramref name="x"/>.</returns> /// <returns>the log density at <paramref name="x"/>.</returns>
@ -461,7 +461,7 @@ namespace MathNet.Numerics.Distributions
} }
/// <summary> /// <summary>
/// Computes the cumulative distribution (CDF) of the distribution at x, i.e. P(X &lt;= x). /// Computes the cumulative distribution (CDF) of the distribution at x, i.e. P(X x).
/// </summary> /// </summary>
/// <param name="x">The location at which to compute the cumulative distribution function.</param> /// <param name="x">The location at which to compute the cumulative distribution function.</param>
/// <returns>the cumulative distribution at location <paramref name="x"/>.</returns> /// <returns>the cumulative distribution at location <paramref name="x"/>.</returns>

2
src/Numerics/Distributions/Binomial.cs

@ -325,7 +325,7 @@ namespace MathNet.Numerics.Distributions
} }
/// <summary> /// <summary>
/// Computes the cumulative distribution (CDF) of the distribution at x, i.e. P(X &lt;= x). /// Computes the cumulative distribution (CDF) of the distribution at x, i.e. P(X x).
/// </summary> /// </summary>
/// <param name="x">The location at which to compute the cumulative distribution function.</param> /// <param name="x">The location at which to compute the cumulative distribution function.</param>
/// <returns>the cumulative distribution at location <paramref name="x"/>.</returns> /// <returns>the cumulative distribution at location <paramref name="x"/>.</returns>

4
src/Numerics/Distributions/Categorical.cs

@ -166,7 +166,7 @@ namespace MathNet.Numerics.Distributions
/// </summary> /// </summary>
/// <param name="p">An array of nonnegative ratios: this array does not need to be normalized /// <param name="p">An array of nonnegative ratios: this array does not need to be normalized
/// as this is often impossible using floating point arithmetic.</param> /// as this is often impossible using floating point arithmetic.</param>
/// <exception cref="ArgumentOutOfRangeException">When the parameters don't pass the <see cref="IsValidProbabilityMass"/> function.</exception> /// <exception cref="ArgumentOutOfRangeException">When the parameters are out of range.</exception>
void SetParameters(double[] p) void SetParameters(double[] p)
{ {
if (Control.CheckDistributionParameters && !IsValidProbabilityMass(p)) if (Control.CheckDistributionParameters && !IsValidProbabilityMass(p))
@ -325,7 +325,7 @@ namespace MathNet.Numerics.Distributions
} }
/// <summary> /// <summary>
/// Computes the cumulative distribution (CDF) of the distribution at x, i.e. P(X &lt;= x). /// Computes the cumulative distribution (CDF) of the distribution at x, i.e. P(X x).
/// </summary> /// </summary>
/// <param name="x">The location at which to compute the cumulative distribution function.</param> /// <param name="x">The location at which to compute the cumulative distribution function.</param>
/// <returns>the cumulative distribution at location <paramref name="x"/>.</returns> /// <returns>the cumulative distribution at location <paramref name="x"/>.</returns>

8
src/Numerics/Distributions/Cauchy.cs

@ -104,7 +104,7 @@ namespace MathNet.Numerics.Distributions
/// </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. Must be greater than 0.</param>
/// <exception cref="ArgumentOutOfRangeException">When the parameters don't pass the <see cref="IsValidParameterSet"/> function.</exception> /// <exception cref="ArgumentOutOfRangeException">When the parameters are out of range.</exception>
void SetParameters(double location, double scale) void SetParameters(double location, double scale)
{ {
if (Control.CheckDistributionParameters && !IsValidParameterSet(location, scale)) if (Control.CheckDistributionParameters && !IsValidParameterSet(location, scale))
@ -216,7 +216,7 @@ namespace MathNet.Numerics.Distributions
} }
/// <summary> /// <summary>
/// Computes the probability density of the distribution (PDF) at x, i.e. dP(X &lt;= x)/dx. /// Computes the probability density of the distribution (PDF) at x, i.e. ∂P(X ≤ x)/∂x.
/// </summary> /// </summary>
/// <param name="x">The location at which to compute the density.</param> /// <param name="x">The location at which to compute the density.</param>
/// <returns>the density at <paramref name="x"/>.</returns> /// <returns>the density at <paramref name="x"/>.</returns>
@ -226,7 +226,7 @@ namespace MathNet.Numerics.Distributions
} }
/// <summary> /// <summary>
/// Computes the log probability density of the distribution (lnPDF) at x, i.e. ln(dP(X &lt;= x)/dx). /// Computes the log probability density of the distribution (lnPDF) at x, i.e. ln(∂P(X ≤ x)/∂x).
/// </summary> /// </summary>
/// <param name="x">The location at which to compute the log density.</param> /// <param name="x">The location at which to compute the log density.</param>
/// <returns>the log density at <paramref name="x"/>.</returns> /// <returns>the log density at <paramref name="x"/>.</returns>
@ -236,7 +236,7 @@ namespace MathNet.Numerics.Distributions
} }
/// <summary> /// <summary>
/// Computes the cumulative distribution (CDF) of the distribution at x, i.e. P(X &lt;= x). /// Computes the cumulative distribution (CDF) of the distribution at x, i.e. P(X x).
/// </summary> /// </summary>
/// <param name="x">The location at which to compute the cumulative distribution function.</param> /// <param name="x">The location at which to compute the cumulative distribution function.</param>
/// <returns>the cumulative distribution at location <paramref name="x"/>.</returns> /// <returns>the cumulative distribution at location <paramref name="x"/>.</returns>

8
src/Numerics/Distributions/Chi.cs

@ -96,7 +96,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="freedom">The degrees of freedom for the Chi distribution.</param> /// <param name="freedom">The degrees of freedom for the Chi distribution.</param>
/// <exception cref="ArgumentOutOfRangeException">When the parameters don't pass the <see cref="IsValidParameterSet"/> function.</exception> /// <exception cref="ArgumentOutOfRangeException">When the parameters are out of range.</exception>
void SetParameters(double freedom) void SetParameters(double freedom)
{ {
if (Control.CheckDistributionParameters && !IsValidParameterSet(freedom)) if (Control.CheckDistributionParameters && !IsValidParameterSet(freedom))
@ -210,7 +210,7 @@ namespace MathNet.Numerics.Distributions
} }
/// <summary> /// <summary>
/// Computes the probability density of the distribution (PDF) at x, i.e. dP(X &lt;= x)/dx. /// Computes the probability density of the distribution (PDF) at x, i.e. ∂P(X ≤ x)/∂x.
/// </summary> /// </summary>
/// <param name="x">The location at which to compute the density.</param> /// <param name="x">The location at which to compute the density.</param>
/// <returns>the density at <paramref name="x"/>.</returns> /// <returns>the density at <paramref name="x"/>.</returns>
@ -220,7 +220,7 @@ namespace MathNet.Numerics.Distributions
} }
/// <summary> /// <summary>
/// Computes the log probability density of the distribution (lnPDF) at x, i.e. ln(dP(X &lt;= x)/dx). /// Computes the log probability density of the distribution (lnPDF) at x, i.e. ln(∂P(X ≤ x)/∂x).
/// </summary> /// </summary>
/// <param name="x">The location at which to compute the log density.</param> /// <param name="x">The location at which to compute the log density.</param>
/// <returns>the log density at <paramref name="x"/>.</returns> /// <returns>the log density at <paramref name="x"/>.</returns>
@ -230,7 +230,7 @@ namespace MathNet.Numerics.Distributions
} }
/// <summary> /// <summary>
/// Computes the cumulative distribution (CDF) of the distribution at x, i.e. P(X &lt;= x). /// Computes the cumulative distribution (CDF) of the distribution at x, i.e. P(X x).
/// </summary> /// </summary>
/// <param name="x">The location at which to compute the cumulative distribution function.</param> /// <param name="x">The location at which to compute the cumulative distribution function.</param>
/// <returns>the cumulative distribution at location <paramref name="x"/>.</returns> /// <returns>the cumulative distribution at location <paramref name="x"/>.</returns>

8
src/Numerics/Distributions/ChiSquared.cs

@ -94,7 +94,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="freedom">The degrees of freedom (k) of the distribution.</param> /// <param name="freedom">The degrees of freedom (k) of the distribution.</param>
/// <exception cref="ArgumentOutOfRangeException">When the parameters don't pass the <see cref="IsValidParameterSet"/> function.</exception> /// <exception cref="ArgumentOutOfRangeException">When the parameters are out of range.</exception>
void SetParameters(double freedom) void SetParameters(double freedom)
{ {
if (Control.CheckDistributionParameters && !IsValidParameterSet(freedom)) if (Control.CheckDistributionParameters && !IsValidParameterSet(freedom))
@ -196,7 +196,7 @@ namespace MathNet.Numerics.Distributions
} }
/// <summary> /// <summary>
/// Computes the probability density of the distribution (PDF) at x, i.e. dP(X &lt;= x)/dx. /// Computes the probability density of the distribution (PDF) at x, i.e. ∂P(X ≤ x)/∂x.
/// </summary> /// </summary>
/// <param name="x">The location at which to compute the density.</param> /// <param name="x">The location at which to compute the density.</param>
/// <returns>the density at <paramref name="x"/>.</returns> /// <returns>the density at <paramref name="x"/>.</returns>
@ -206,7 +206,7 @@ namespace MathNet.Numerics.Distributions
} }
/// <summary> /// <summary>
/// Computes the log probability density of the distribution (lnPDF) at x, i.e. ln(dP(X &lt;= x)/dx). /// Computes the log probability density of the distribution (lnPDF) at x, i.e. ln(∂P(X ≤ x)/∂x).
/// </summary> /// </summary>
/// <param name="x">The location at which to compute the log density.</param> /// <param name="x">The location at which to compute the log density.</param>
/// <returns>the log density at <paramref name="x"/>.</returns> /// <returns>the log density at <paramref name="x"/>.</returns>
@ -216,7 +216,7 @@ namespace MathNet.Numerics.Distributions
} }
/// <summary> /// <summary>
/// Computes the cumulative distribution (CDF) of the distribution at x, i.e. P(X &lt;= x). /// Computes the cumulative distribution (CDF) of the distribution at x, i.e. P(X x).
/// </summary> /// </summary>
/// <param name="x">The location at which to compute the cumulative distribution function.</param> /// <param name="x">The location at which to compute the cumulative distribution function.</param>
/// <returns>the cumulative distribution at location <paramref name="x"/>.</returns> /// <returns>the cumulative distribution at location <paramref name="x"/>.</returns>

10
src/Numerics/Distributions/ContinuousUniform.cs

@ -1,4 +1,4 @@
// <copyright file="ContinuousUniform.cs" company="Math.NET"> // <copyright file="ContinuousUniform.cs" company="Math.NET">
// Math.NET Numerics, part of the Math.NET Project // Math.NET Numerics, part of the Math.NET Project
// http://numerics.mathdotnet.com // http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics // http://github.com/mathnet/mathnet-numerics
@ -108,7 +108,7 @@ namespace MathNet.Numerics.Distributions
/// </summary> /// </summary>
/// <param name="lower">Lower bound.</param> /// <param name="lower">Lower bound.</param>
/// <param name="upper">Upper bound; must be at least as large as <paramref name="lower"/>.</param> /// <param name="upper">Upper bound; must be at least as large as <paramref name="lower"/>.</param>
/// <exception cref="ArgumentOutOfRangeException">When the parameters don't pass the <see cref="IsValidParameterSet"/> function.</exception> /// <exception cref="ArgumentOutOfRangeException">When the parameters are out of range.</exception>
void SetParameters(double lower, double upper) void SetParameters(double lower, double upper)
{ {
if (Control.CheckDistributionParameters && !IsValidParameterSet(lower, upper)) if (Control.CheckDistributionParameters && !IsValidParameterSet(lower, upper))
@ -223,7 +223,7 @@ namespace MathNet.Numerics.Distributions
} }
/// <summary> /// <summary>
/// Computes the probability density of the distribution (PDF) at x, i.e. dP(X &lt;= x)/dx. /// Computes the probability density of the distribution (PDF) at x, i.e. ∂P(X ≤ x)/∂x.
/// </summary> /// </summary>
/// <param name="x">The location at which to compute the density.</param> /// <param name="x">The location at which to compute the density.</param>
/// <returns>the density at <paramref name="x"/>.</returns> /// <returns>the density at <paramref name="x"/>.</returns>
@ -238,7 +238,7 @@ namespace MathNet.Numerics.Distributions
} }
/// <summary> /// <summary>
/// Computes the log probability density of the distribution (lnPDF) at x, i.e. ln(dP(X &lt;= x)/dx). /// Computes the log probability density of the distribution (lnPDF) at x, i.e. ln(∂P(X ≤ x)/∂x).
/// </summary> /// </summary>
/// <param name="x">The location at which to compute the log density.</param> /// <param name="x">The location at which to compute the log density.</param>
/// <returns>the log density at <paramref name="x"/>.</returns> /// <returns>the log density at <paramref name="x"/>.</returns>
@ -253,7 +253,7 @@ namespace MathNet.Numerics.Distributions
} }
/// <summary> /// <summary>
/// Computes the cumulative distribution (CDF) of the distribution at x, i.e. P(X &lt;= x). /// Computes the cumulative distribution (CDF) of the distribution at x, i.e. P(X x).
/// </summary> /// </summary>
/// <param name="x">The location at which to compute the cumulative distribution function.</param> /// <param name="x">The location at which to compute the cumulative distribution function.</param>
/// <returns>the cumulative distribution at location <paramref name="x"/>.</returns> /// <returns>the cumulative distribution at location <paramref name="x"/>.</returns>

4
src/Numerics/Distributions/ConwayMaxwellPoisson.cs

@ -127,7 +127,7 @@ namespace MathNet.Numerics.Distributions
/// </summary> /// </summary>
/// <param name="lambda">The lambda (λ) parameter.</param> /// <param name="lambda">The lambda (λ) parameter.</param>
/// <param name="nu">The rate of decay (ν) parameter.</param> /// <param name="nu">The rate of decay (ν) parameter.</param>
/// <exception cref="ArgumentOutOfRangeException">When the parameters don't pass the <see cref="IsValidParameterSet"/> function.</exception> /// <exception cref="ArgumentOutOfRangeException">When the parameters are out of range.</exception>
void SetParameters(double lambda, double nu) void SetParameters(double lambda, double nu)
{ {
if (Control.CheckDistributionParameters && !IsValidParameterSet(lambda, nu)) if (Control.CheckDistributionParameters && !IsValidParameterSet(lambda, nu))
@ -366,7 +366,7 @@ namespace MathNet.Numerics.Distributions
} }
/// <summary> /// <summary>
/// Computes the cumulative distribution (CDF) of the distribution at x, i.e. P(X &lt;= x). /// Computes the cumulative distribution (CDF) of the distribution at x, i.e. P(X x).
/// </summary> /// </summary>
/// <param name="x">The location at which to compute the cumulative distribution function.</param> /// <param name="x">The location at which to compute the cumulative distribution function.</param>
/// <returns>the cumulative distribution at location <paramref name="x"/>.</returns> /// <returns>the cumulative distribution at location <paramref name="x"/>.</returns>

2
src/Numerics/Distributions/Dirichlet.cs

@ -153,7 +153,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="alpha">The parameters of the Dirichlet distribution.</param> /// <param name="alpha">The parameters of the Dirichlet distribution.</param>
/// <exception cref="ArgumentOutOfRangeException">When the parameters don't pass the <see cref="IsValidParameterSet"/> function.</exception> /// <exception cref="ArgumentOutOfRangeException">When the parameters are out of range.</exception>
void SetParameters(double[] alpha) void SetParameters(double[] alpha)
{ {
if (Control.CheckDistributionParameters && !IsValidParameterSet(alpha)) if (Control.CheckDistributionParameters && !IsValidParameterSet(alpha))

4
src/Numerics/Distributions/DiscreteUniform.cs

@ -102,7 +102,7 @@ namespace MathNet.Numerics.Distributions
/// </summary> /// </summary>
/// <param name="lower">Lower bound.</param> /// <param name="lower">Lower bound.</param>
/// <param name="upper">Upper bound; must be at least as large as <paramref name="lower"/>.</param> /// <param name="upper">Upper bound; must be at least as large as <paramref name="lower"/>.</param>
/// <exception cref="ArgumentOutOfRangeException">When the parameters don't pass the <see cref="IsValidParameterSet"/> function.</exception> /// <exception cref="ArgumentOutOfRangeException">When the parameters are out of range.</exception>
void SetParameters(int lower, int upper) void SetParameters(int lower, int upper)
{ {
if (Control.CheckDistributionParameters && !IsValidParameterSet(lower, upper)) if (Control.CheckDistributionParameters && !IsValidParameterSet(lower, upper))
@ -244,7 +244,7 @@ namespace MathNet.Numerics.Distributions
} }
/// <summary> /// <summary>
/// Computes the cumulative distribution (CDF) of the distribution at x, i.e. P(X &lt;= x). /// Computes the cumulative distribution (CDF) of the distribution at x, i.e. P(X x).
/// </summary> /// </summary>
/// <param name="x">The location at which to compute the cumulative distribution function.</param> /// <param name="x">The location at which to compute the cumulative distribution function.</param>
/// <returns>the cumulative distribution at location <paramref name="x"/>.</returns> /// <returns>the cumulative distribution at location <paramref name="x"/>.</returns>

7
src/Numerics/Distributions/Erlang.cs

@ -124,6 +124,7 @@ namespace MathNet.Numerics.Distributions
/// </summary> /// </summary>
/// <param name="shape">The shape (k) of the Erlang distribution.</param> /// <param name="shape">The shape (k) of the Erlang distribution.</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.</param>
/// <exception cref="ArgumentOutOfRangeException">When the parameters are out of range.</exception>
void SetParameters(double shape, double rate) void SetParameters(double shape, double rate)
{ {
if (Control.CheckDistributionParameters && !IsValidParameterSet(shape, rate)) if (Control.CheckDistributionParameters && !IsValidParameterSet(shape, rate))
@ -335,7 +336,7 @@ namespace MathNet.Numerics.Distributions
} }
/// <summary> /// <summary>
/// Computes the probability density of the distribution (PDF) at x, i.e. dP(X &lt;= x)/dx. /// Computes the probability density of the distribution (PDF) at x, i.e. ∂P(X ≤ x)/∂x.
/// </summary> /// </summary>
/// <param name="x">The location at which to compute the density.</param> /// <param name="x">The location at which to compute the density.</param>
/// <returns>the density at <paramref name="x"/>.</returns> /// <returns>the density at <paramref name="x"/>.</returns>
@ -360,7 +361,7 @@ namespace MathNet.Numerics.Distributions
} }
/// <summary> /// <summary>
/// Computes the log probability density of the distribution (lnPDF) at x, i.e. ln(dP(X &lt;= x)/dx). /// Computes the log probability density of the distribution (lnPDF) at x, i.e. ln(∂P(X ≤ x)/∂x).
/// </summary> /// </summary>
/// <param name="x">The location at which to compute the log density.</param> /// <param name="x">The location at which to compute the log density.</param>
/// <returns>the log density at <paramref name="x"/>.</returns> /// <returns>the log density at <paramref name="x"/>.</returns>
@ -385,7 +386,7 @@ namespace MathNet.Numerics.Distributions
} }
/// <summary> /// <summary>
/// Computes the cumulative distribution (CDF) of the distribution at x, i.e. P(X &lt;= x). /// Computes the cumulative distribution (CDF) of the distribution at x, i.e. P(X x).
/// </summary> /// </summary>
/// <param name="x">The location at which to compute the cumulative distribution function.</param> /// <param name="x">The location at which to compute the cumulative distribution function.</param>
/// <returns>the cumulative distribution at location <paramref name="x"/>.</returns> /// <returns>the cumulative distribution at location <paramref name="x"/>.</returns>

8
src/Numerics/Distributions/Exponential.cs

@ -94,7 +94,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="rate">The rate (λ) parameter of the Exponential distribution.</param> /// <param name="rate">The rate (λ) parameter of the Exponential distribution.</param>
/// <exception cref="ArgumentOutOfRangeException">When the parameters don't pass the <see cref="IsValidParameterSet"/> function.</exception> /// <exception cref="ArgumentOutOfRangeException">When the parameters are out of range.</exception>
void SetParameters(double rate) void SetParameters(double rate)
{ {
if (Control.CheckDistributionParameters && !IsValidParameterSet(rate)) if (Control.CheckDistributionParameters && !IsValidParameterSet(rate))
@ -196,7 +196,7 @@ namespace MathNet.Numerics.Distributions
} }
/// <summary> /// <summary>
/// Computes the probability density of the distribution (PDF) at x, i.e. dP(X &lt;= x)/dx. /// Computes the probability density of the distribution (PDF) at x, i.e. ∂P(X ≤ x)/∂x.
/// </summary> /// </summary>
/// <param name="x">The location at which to compute the density.</param> /// <param name="x">The location at which to compute the density.</param>
/// <returns>the density at <paramref name="x"/>.</returns> /// <returns>the density at <paramref name="x"/>.</returns>
@ -211,7 +211,7 @@ namespace MathNet.Numerics.Distributions
} }
/// <summary> /// <summary>
/// Computes the log probability density of the distribution (lnPDF) at x, i.e. ln(dP(X &lt;= x)/dx). /// Computes the log probability density of the distribution (lnPDF) at x, i.e. ln(∂P(X ≤ x)/∂x).
/// </summary> /// </summary>
/// <param name="x">The location at which to compute the log density.</param> /// <param name="x">The location at which to compute the log density.</param>
/// <returns>the log density at <paramref name="x"/>.</returns> /// <returns>the log density at <paramref name="x"/>.</returns>
@ -221,7 +221,7 @@ namespace MathNet.Numerics.Distributions
} }
/// <summary> /// <summary>
/// Computes the cumulative distribution (CDF) of the distribution at x, i.e. P(X &lt;= x). /// Computes the cumulative distribution (CDF) of the distribution at x, i.e. P(X x).
/// </summary> /// </summary>
/// <param name="x">The location at which to compute the cumulative distribution function.</param> /// <param name="x">The location at which to compute the cumulative distribution function.</param>
/// <returns>the cumulative distribution at location <paramref name="x"/>.</returns> /// <returns>the cumulative distribution at location <paramref name="x"/>.</returns>

7
src/Numerics/Distributions/FisherSnedecor.cs

@ -99,6 +99,7 @@ namespace MathNet.Numerics.Distributions
/// </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.</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.</param>
/// <exception cref="ArgumentOutOfRangeException">When the parameters are out of range.</exception>
void SetParameters(double d1, double d2) void SetParameters(double d1, double d2)
{ {
if (Control.CheckDistributionParameters && !IsValidParameterSet(d1, d2)) if (Control.CheckDistributionParameters && !IsValidParameterSet(d1, d2))
@ -242,7 +243,7 @@ namespace MathNet.Numerics.Distributions
} }
/// <summary> /// <summary>
/// Computes the probability density of the distribution (PDF) at x, i.e. dP(X &lt;= x)/dx. /// Computes the probability density of the distribution (PDF) at x, i.e. ∂P(X ≤ x)/∂x.
/// </summary> /// </summary>
/// <param name="x">The location at which to compute the density.</param> /// <param name="x">The location at which to compute the density.</param>
/// <returns>the density at <paramref name="x"/>.</returns> /// <returns>the density at <paramref name="x"/>.</returns>
@ -252,7 +253,7 @@ namespace MathNet.Numerics.Distributions
} }
/// <summary> /// <summary>
/// Computes the log probability density of the distribution (lnPDF) at x, i.e. ln(dP(X &lt;= x)/dx). /// Computes the log probability density of the distribution (lnPDF) at x, i.e. ln(∂P(X ≤ x)/∂x).
/// </summary> /// </summary>
/// <param name="x">The location at which to compute the log density.</param> /// <param name="x">The location at which to compute the log density.</param>
/// <returns>the log density at <paramref name="x"/>.</returns> /// <returns>the log density at <paramref name="x"/>.</returns>
@ -262,7 +263,7 @@ namespace MathNet.Numerics.Distributions
} }
/// <summary> /// <summary>
/// Computes the cumulative distribution (CDF) of the distribution at x, i.e. P(X &lt;= x). /// Computes the cumulative distribution (CDF) of the distribution at x, i.e. P(X x).
/// </summary> /// </summary>
/// <param name="x">The location at which to compute the cumulative distribution function.</param> /// <param name="x">The location at which to compute the cumulative distribution function.</param>
/// <returns>the cumulative distribution at location <paramref name="x"/>.</returns> /// <returns>the cumulative distribution at location <paramref name="x"/>.</returns>

8
src/Numerics/Distributions/Gamma.cs

@ -129,7 +129,7 @@ namespace MathNet.Numerics.Distributions
/// </summary> /// </summary>
/// <param name="shape">The shape (k, α) of the Gamma distribution.</param> /// <param name="shape">The shape (k, α) of the Gamma distribution.</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.</param>
/// <exception cref="ArgumentOutOfRangeException">When the parameters don't pass the <see cref="IsValidParameterSet"/> function.</exception> /// <exception cref="ArgumentOutOfRangeException">When the parameters are out of range.</exception>
void SetParameters(double shape, double rate) void SetParameters(double shape, double rate)
{ {
if (Control.CheckDistributionParameters && !IsValidParameterSet(shape, rate)) if (Control.CheckDistributionParameters && !IsValidParameterSet(shape, rate))
@ -336,7 +336,7 @@ namespace MathNet.Numerics.Distributions
} }
/// <summary> /// <summary>
/// Computes the probability density of the distribution (PDF) at x, i.e. dP(X &lt;= x)/dx. /// Computes the probability density of the distribution (PDF) at x, i.e. ∂P(X ≤ x)/∂x.
/// </summary> /// </summary>
/// <param name="x">The location at which to compute the density.</param> /// <param name="x">The location at which to compute the density.</param>
/// <returns>the density at <paramref name="x"/>.</returns> /// <returns>the density at <paramref name="x"/>.</returns>
@ -361,7 +361,7 @@ namespace MathNet.Numerics.Distributions
} }
/// <summary> /// <summary>
/// Computes the log probability density of the distribution (lnPDF) at x, i.e. ln(dP(X &lt;= x)/dx). /// Computes the log probability density of the distribution (lnPDF) at x, i.e. ln(∂P(X ≤ x)/∂x).
/// </summary> /// </summary>
/// <param name="x">The location at which to compute the log density.</param> /// <param name="x">The location at which to compute the log density.</param>
/// <returns>the log density at <paramref name="x"/>.</returns> /// <returns>the log density at <paramref name="x"/>.</returns>
@ -386,7 +386,7 @@ namespace MathNet.Numerics.Distributions
} }
/// <summary> /// <summary>
/// Computes the cumulative distribution (CDF) of the distribution at x, i.e. P(X &lt;= x). /// Computes the cumulative distribution (CDF) of the distribution at x, i.e. P(X x).
/// </summary> /// </summary>
/// <param name="x">The location at which to compute the cumulative distribution function.</param> /// <param name="x">The location at which to compute the cumulative distribution function.</param>
/// <returns>the cumulative distribution at location <paramref name="x"/>.</returns> /// <returns>the cumulative distribution at location <paramref name="x"/>.</returns>

4
src/Numerics/Distributions/Geometric.cs

@ -99,7 +99,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="p">The probability of generating a one.</param> /// <param name="p">The probability of generating a one.</param>
/// <exception cref="ArgumentOutOfRangeException">When the parameters don't pass the <see cref="IsValidParameterSet"/> function.</exception> /// <exception cref="ArgumentOutOfRangeException">When the parameters are out of range.</exception>
void SetParameters(double p) void SetParameters(double p)
{ {
if (Control.CheckDistributionParameters && !IsValidParameterSet(p)) if (Control.CheckDistributionParameters && !IsValidParameterSet(p))
@ -232,7 +232,7 @@ namespace MathNet.Numerics.Distributions
} }
/// <summary> /// <summary>
/// Computes the cumulative distribution (CDF) of the distribution at x, i.e. P(X &lt;= x). /// Computes the cumulative distribution (CDF) of the distribution at x, i.e. P(X x).
/// </summary> /// </summary>
/// <param name="x">The location at which to compute the cumulative distribution function.</param> /// <param name="x">The location at which to compute the cumulative distribution function.</param>
/// <returns>the cumulative distribution at location <paramref name="x"/>.</returns> /// <returns>the cumulative distribution at location <paramref name="x"/>.</returns>

3
src/Numerics/Distributions/Hypergeometric.cs

@ -109,6 +109,7 @@ namespace MathNet.Numerics.Distributions
/// <param name="population">The size of the population (N).</param> /// <param name="population">The size of the population (N).</param>
/// <param name="success">The number successes within the population (K, M).</param> /// <param name="success">The number successes within the population (K, M).</param>
/// <param name="draws">The number of draws without replacement (n).</param> /// <param name="draws">The number of draws without replacement (n).</param>
/// <exception cref="ArgumentOutOfRangeException">When the parameters are out of range.</exception>
void SetParameters(int population, int success, int draws) void SetParameters(int population, int success, int draws)
{ {
if (Control.CheckDistributionParameters && !IsValidParameterSet(population, success, draws)) if (Control.CheckDistributionParameters && !IsValidParameterSet(population, success, draws))
@ -280,7 +281,7 @@ namespace MathNet.Numerics.Distributions
} }
/// <summary> /// <summary>
/// Computes the cumulative distribution (CDF) of the distribution at x, i.e. P(X &lt;= x). /// Computes the cumulative distribution (CDF) of the distribution at x, i.e. P(X x).
/// </summary> /// </summary>
/// <param name="x">The location at which to compute the cumulative distribution function.</param> /// <param name="x">The location at which to compute the cumulative distribution function.</param>
/// <returns>the cumulative distribution at location <paramref name="x"/>.</returns> /// <returns>the cumulative distribution at location <paramref name="x"/>.</returns>

4
src/Numerics/Distributions/IContinuousDistribution.cs

@ -59,14 +59,14 @@ namespace MathNet.Numerics.Distributions
double Maximum { get; } double Maximum { get; }
/// <summary> /// <summary>
/// Computes the probability density of the distribution (PDF) at x, i.e. dP(X &lt;= x)/dx. /// Computes the probability density of the distribution (PDF) at x, i.e. ∂P(X ≤ x)/∂x.
/// </summary> /// </summary>
/// <param name="x">The location at which to compute the density.</param> /// <param name="x">The location at which to compute the density.</param>
/// <returns>the density at <paramref name="x"/>.</returns> /// <returns>the density at <paramref name="x"/>.</returns>
double Density(double x); double Density(double x);
/// <summary> /// <summary>
/// Computes the log probability density of the distribution (lnPDF) at x, i.e. ln(dP(X &lt;= x)/dx). /// Computes the log probability density of the distribution (lnPDF) at x, i.e. ln(∂P(X ≤ x)/∂x).
/// </summary> /// </summary>
/// <param name="x">The location at which to compute the log density.</param> /// <param name="x">The location at which to compute the log density.</param>
/// <returns>the log density at <paramref name="x"/>.</returns> /// <returns>the log density at <paramref name="x"/>.</returns>

2
src/Numerics/Distributions/IUnivariateDistribution.cs

@ -63,7 +63,7 @@ namespace MathNet.Numerics.Distributions
double Skewness { get; } double Skewness { get; }
/// <summary> /// <summary>
/// Computes the cumulative distribution (CDF) of the distribution at x, i.e. P(X &lt;= x). /// Computes the cumulative distribution (CDF) of the distribution at x, i.e. P(X x).
/// </summary> /// </summary>
/// <param name="x">The location at which to compute the cumulative distribution function.</param> /// <param name="x">The location at which to compute the cumulative distribution function.</param>
/// <returns>the cumulative distribution at location <paramref name="x"/>.</returns> /// <returns>the cumulative distribution at location <paramref name="x"/>.</returns>

8
src/Numerics/Distributions/InverseGamma.cs

@ -100,7 +100,7 @@ namespace MathNet.Numerics.Distributions
/// </summary> /// </summary>
/// <param name="shape">The shape (α) of the inverse Gamma distribution.</param> /// <param name="shape">The shape (α) of the inverse Gamma distribution.</param>
/// <param name="scale">The scale (β) of the inverse Gamma distribution.</param> /// <param name="scale">The scale (β) of the inverse Gamma distribution.</param>
/// <exception cref="ArgumentOutOfRangeException">When the parameters don't pass the <see cref="IsValidParameterSet"/> function.</exception> /// <exception cref="ArgumentOutOfRangeException">When the parameters are out of range.</exception>
void SetParameters(double shape, double scale) void SetParameters(double shape, double scale)
{ {
if (Control.CheckDistributionParameters && !IsValidParameterSet(shape, scale)) if (Control.CheckDistributionParameters && !IsValidParameterSet(shape, scale))
@ -237,7 +237,7 @@ namespace MathNet.Numerics.Distributions
} }
/// <summary> /// <summary>
/// Computes the probability density of the distribution (PDF) at x, i.e. dP(X &lt;= x)/dx. /// Computes the probability density of the distribution (PDF) at x, i.e. ∂P(X ≤ x)/∂x.
/// </summary> /// </summary>
/// <param name="x">The location at which to compute the density.</param> /// <param name="x">The location at which to compute the density.</param>
/// <returns>the density at <paramref name="x"/>.</returns> /// <returns>the density at <paramref name="x"/>.</returns>
@ -252,7 +252,7 @@ namespace MathNet.Numerics.Distributions
} }
/// <summary> /// <summary>
/// Computes the log probability density of the distribution (lnPDF) at x, i.e. ln(dP(X &lt;= x)/dx). /// Computes the log probability density of the distribution (lnPDF) at x, i.e. ln(∂P(X ≤ x)/∂x).
/// </summary> /// </summary>
/// <param name="x">The location at which to compute the log density.</param> /// <param name="x">The location at which to compute the log density.</param>
/// <returns>the log density at <paramref name="x"/>.</returns> /// <returns>the log density at <paramref name="x"/>.</returns>
@ -262,7 +262,7 @@ namespace MathNet.Numerics.Distributions
} }
/// <summary> /// <summary>
/// Computes the cumulative distribution (CDF) of the distribution at x, i.e. P(X &lt;= x). /// Computes the cumulative distribution (CDF) of the distribution at x, i.e. P(X x).
/// </summary> /// </summary>
/// <param name="x">The location at which to compute the cumulative distribution function.</param> /// <param name="x">The location at which to compute the cumulative distribution function.</param>
/// <returns>the cumulative distribution at location <paramref name="x"/>.</returns> /// <returns>the cumulative distribution at location <paramref name="x"/>.</returns>

2
src/Numerics/Distributions/InverseWishart.cs

@ -119,7 +119,7 @@ namespace MathNet.Numerics.Distributions
/// </summary> /// </summary>
/// <param name="degreesOfFreedom">The degree of freedom (ν) for the inverse Wishart distribution.</param> /// <param name="degreesOfFreedom">The degree of freedom (ν) for the inverse Wishart distribution.</param>
/// <param name="scale">The scale matrix (Ψ) for the inverse Wishart distribution.</param> /// <param name="scale">The scale matrix (Ψ) for the inverse Wishart distribution.</param>
/// <exception cref="ArgumentOutOfRangeException">When the parameters don't pass the <see cref="IsValidParameterSet"/> function.</exception> /// <exception cref="ArgumentOutOfRangeException">When the parameters are out of range.</exception>
void SetParameters(double degreesOfFreedom, Matrix<double> scale) void SetParameters(double degreesOfFreedom, Matrix<double> scale)
{ {
if (Control.CheckDistributionParameters && !IsValidParameterSet(degreesOfFreedom, scale)) if (Control.CheckDistributionParameters && !IsValidParameterSet(degreesOfFreedom, scale))

8
src/Numerics/Distributions/Laplace.cs

@ -111,7 +111,7 @@ namespace MathNet.Numerics.Distributions
/// </summary> /// </summary>
/// <param name="location">The location (μ) of the Laplace distribution.</param> /// <param name="location">The location (μ) of the Laplace distribution.</param>
/// <param name="scale">The scale (b) of the Laplace distribution.</param> /// <param name="scale">The scale (b) of the Laplace distribution.</param>
/// <exception cref="ArgumentOutOfRangeException">When the parameters don't pass the <see cref="IsValidParameterSet"/> function.</exception> /// <exception cref="ArgumentOutOfRangeException">When the parameters are out of range.</exception>
void SetParameters(double location, double scale) void SetParameters(double location, double scale)
{ {
if (Control.CheckDistributionParameters && !IsValidParameterSet(location, scale)) if (Control.CheckDistributionParameters && !IsValidParameterSet(location, scale))
@ -223,7 +223,7 @@ namespace MathNet.Numerics.Distributions
} }
/// <summary> /// <summary>
/// Computes the probability density of the distribution (PDF) at x, i.e. dP(X &lt;= x)/dx. /// Computes the probability density of the distribution (PDF) at x, i.e. ∂P(X ≤ x)/∂x.
/// </summary> /// </summary>
/// <param name="x">The location at which to compute the density.</param> /// <param name="x">The location at which to compute the density.</param>
/// <returns>the density at <paramref name="x"/>.</returns> /// <returns>the density at <paramref name="x"/>.</returns>
@ -233,7 +233,7 @@ namespace MathNet.Numerics.Distributions
} }
/// <summary> /// <summary>
/// Computes the log probability density of the distribution (lnPDF) at x, i.e. ln(dP(X &lt;= x)/dx). /// Computes the log probability density of the distribution (lnPDF) at x, i.e. ln(∂P(X ≤ x)/∂x).
/// </summary> /// </summary>
/// <param name="x">The location at which to compute the log density.</param> /// <param name="x">The location at which to compute the log density.</param>
/// <returns>the log density at <paramref name="x"/>.</returns> /// <returns>the log density at <paramref name="x"/>.</returns>
@ -243,7 +243,7 @@ namespace MathNet.Numerics.Distributions
} }
/// <summary> /// <summary>
/// Computes the cumulative distribution (CDF) of the distribution at x, i.e. P(X &lt;= x). /// Computes the cumulative distribution (CDF) of the distribution at x, i.e. P(X x).
/// </summary> /// </summary>
/// <param name="x">The location at which to compute the cumulative distribution function.</param> /// <param name="x">The location at which to compute the cumulative distribution function.</param>
/// <returns>the cumulative distribution at location <paramref name="x"/>.</returns> /// <returns>the cumulative distribution at location <paramref name="x"/>.</returns>

135
src/Numerics/Distributions/LogNormal.cs

@ -59,7 +59,7 @@ namespace MathNet.Numerics.Distributions
/// random number generator. /// random number generator.
/// </summary> /// </summary>
/// <param name="mu">The log-scale (μ) of the logarithm of the distribution.</param> /// <param name="mu">The log-scale (μ) of the logarithm of the distribution.</param>
/// <param name="sigma">The shape (σ) of the logarithm of the distribution.</param> /// <param name="sigma">The shape (σ) of the logarithm of the distribution. Range: σ ≥ 0.</param>
public LogNormal(double mu, double sigma) public LogNormal(double mu, double sigma)
{ {
_random = new System.Random(); _random = new System.Random();
@ -72,7 +72,7 @@ namespace MathNet.Numerics.Distributions
/// random number generator. /// random number generator.
/// </summary> /// </summary>
/// <param name="mu">The log-scale (μ) of the distribution.</param> /// <param name="mu">The log-scale (μ) of the distribution.</param>
/// <param name="sigma">The shape (σ) of the distribution.</param> /// <param name="sigma">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>
public LogNormal(double mu, double sigma, System.Random randomSource) public LogNormal(double mu, double sigma, System.Random randomSource)
{ {
@ -81,25 +81,40 @@ namespace MathNet.Numerics.Distributions
} }
/// <summary> /// <summary>
/// Constructs a log-normal distribution with the desired mean and variance. The distribution will /// Constructs a log-normal distribution with the desired mu and sigma parameters.
/// be initialized with the default <seealso cref="System.Random"/> random number generator. /// </summary>
/// <param name="mu">The log-scale (μ) of the distribution.</param>
/// <param name="sigma">The shape (σ) of the distribution. Range: σ ≥ 0.</param>
/// <param name="randomSource">The random number generator which is used to draw random samples. Optional, can be null.</param>
/// <returns>A log-normal distribution.</returns>
public static LogNormal WithMuSigma(double mu, double sigma, System.Random randomSource = null)
{
return new LogNormal(mu, sigma, randomSource);
}
/// <summary>
/// Constructs a log-normal distribution with the desired mean and variance.
/// </summary> /// </summary>
/// <param name="mean">The mean of the log-normal distribution.</param> /// <param name="mean">The mean of the log-normal distribution.</param>
/// <param name="var">The variance of the log-normal distribution.</param> /// <param name="var">The variance of the log-normal distribution.</param>
/// <returns>a log-normal distribution.</returns> /// <param name="randomSource">The random number generator which is used to draw random samples. Optional, can be null.</param>
public static LogNormal WithMeanVariance(double mean, double var) /// <returns>A log-normal distribution.</returns>
public static LogNormal WithMeanVariance(double mean, double var, System.Random randomSource = null)
{ {
var sigma2 = Math.Log(var/(mean*mean) + 1.0); var sigma2 = Math.Log(var/(mean*mean) + 1.0);
return new LogNormal(Math.Log(mean) - sigma2/2.0, Math.Sqrt(sigma2)); return new LogNormal(Math.Log(mean) - sigma2 / 2.0, Math.Sqrt(sigma2), randomSource);
} }
/// <summary> /// <summary>
/// Estimates the log-normal distribution parameters from sample data with maximum-likelihood. /// Estimates the log-normal distribution parameters from sample data with maximum-likelihood.
/// </summary> /// </summary>
public static LogNormal Estimate(IEnumerable<double> samples) /// <param name="samples">The samples to estimate the distribution parameters from.</param>
/// <param name="randomSource">The random number generator which is used to draw random samples. Optional, can be null.</param>
/// <returns>A log-normal distribution.</returns>
public static LogNormal Estimate(IEnumerable<double> samples, System.Random randomSource = null)
{ {
var muSigma2 = samples.Select(s => Math.Log(s)).MeanVariance(); var muSigma2 = samples.Select(s => Math.Log(s)).MeanVariance();
return new LogNormal(muSigma2.Item1, Math.Sqrt(muSigma2.Item2)); return new LogNormal(muSigma2.Item1, Math.Sqrt(muSigma2.Item2), randomSource);
} }
/// <summary> /// <summary>
@ -111,26 +126,15 @@ namespace MathNet.Numerics.Distributions
return "LogNormal(μ = " + _mu + ", σ = " + _sigma + ")"; return "LogNormal(μ = " + _mu + ", σ = " + _sigma + ")";
} }
/// <summary>
/// Checks whether the parameters of the distribution are valid.
/// </summary>
/// <param name="mu">The log-scale (μ) of the distribution.</param>
/// <param name="sigma">The shape (σ) of the distribution.</param>
/// <returns><c>true</c> when the parameters are valid, <c>false</c> otherwise.</returns>
static bool IsValidParameterSet(double mu, double sigma)
{
return sigma >= 0.0 && !Double.IsNaN(mu);
}
/// <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="mu">The log-scale (μ) of the distribution.</param> /// <param name="mu">The log-scale (μ) of the distribution.</param>
/// <param name="sigma">The shape (σ) of the distribution.</param> /// <param name="sigma">The shape (σ) of the distribution. Range: σ ≥ 0.</param>
/// <exception cref="ArgumentOutOfRangeException">When the parameters don't pass the <see cref="IsValidParameterSet"/> function.</exception> /// <exception cref="ArgumentOutOfRangeException">When the parameters are out of range.</exception>
void SetParameters(double mu, double sigma) void SetParameters(double mu, double sigma)
{ {
if (Control.CheckDistributionParameters && !IsValidParameterSet(mu, sigma)) if (sigma < 0.0 || Double.IsNaN(mu) || Double.IsNaN(sigma))
{ {
throw new ArgumentOutOfRangeException(Resources.InvalidDistributionParameters); throw new ArgumentOutOfRangeException(Resources.InvalidDistributionParameters);
} }
@ -149,7 +153,7 @@ namespace MathNet.Numerics.Distributions
} }
/// <summary> /// <summary>
/// Gets or sets the shape (σ) (standard deviation of the logarithm) of the distribution. /// Gets or sets the shape (σ) (standard deviation of the logarithm) of the distribution. Range: σ ≥ 0.
/// </summary> /// </summary>
public double Sigma public double Sigma
{ {
@ -251,7 +255,7 @@ namespace MathNet.Numerics.Distributions
} }
/// <summary> /// <summary>
/// Computes the probability density of the distribution (PDF) at x, i.e. dP(X &lt;= x)/dx. /// Computes the probability density of the distribution (PDF) at x, i.e. ∂P(X ≤ x)/∂x.
/// </summary> /// </summary>
/// <param name="x">The location at which to compute the density.</param> /// <param name="x">The location at which to compute the density.</param>
/// <returns>the density at <paramref name="x"/>.</returns> /// <returns>the density at <paramref name="x"/>.</returns>
@ -262,12 +266,12 @@ namespace MathNet.Numerics.Distributions
return 0.0; return 0.0;
} }
var a = (Math.Log(x) - _mu)/_sigma; var a = (Math.Log(x) - _mu) / _sigma;
return Math.Exp(-0.5*a*a)/(x*_sigma*Constants.Sqrt2Pi); return Math.Exp(-0.5*a*a)/(x*_sigma*Constants.Sqrt2Pi);
} }
/// <summary> /// <summary>
/// Computes the log probability density of the distribution (lnPDF) at x, i.e. ln(dP(X &lt;= x)/dx). /// Computes the log probability density of the distribution (lnPDF) at x, i.e. ln(∂P(X ≤ x)/∂x).
/// </summary> /// </summary>
/// <param name="x">The location at which to compute the log density.</param> /// <param name="x">The location at which to compute the log density.</param>
/// <returns>the log density at <paramref name="x"/>.</returns> /// <returns>the log density at <paramref name="x"/>.</returns>
@ -278,23 +282,20 @@ namespace MathNet.Numerics.Distributions
return Double.NegativeInfinity; return Double.NegativeInfinity;
} }
var a = (Math.Log(x) - _mu)/_sigma; var a = (Math.Log(x) - _mu) / _sigma;
return (-0.5*a*a) - Math.Log(x*_sigma) - Constants.LogSqrt2Pi; return (-0.5*a*a) - Math.Log(x*_sigma) - Constants.LogSqrt2Pi;
} }
/// <summary> /// <summary>
/// Computes the cumulative distribution (CDF) of the distribution at x, i.e. P(X &lt;= x). /// Computes the cumulative distribution (CDF) of the distribution at x, i.e. P(X x).
/// </summary> /// </summary>
/// <param name="x">The location at which to compute the cumulative distribution function.</param> /// <param name="x">The location at which to compute the cumulative distribution function.</param>
/// <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) return x < 0.0
{ ? 0.0
return 0.0; : 0.5*(1.0 + SpecialFunctions.Erf((Math.Log(x) - _mu)/(_sigma*Constants.Sqrt2)));
}
return 0.5*(1.0 + SpecialFunctions.Erf((Math.Log(x) - _mu)/(_sigma*Constants.Sqrt2)));
} }
/// <summary> /// <summary>
@ -303,7 +304,7 @@ namespace MathNet.Numerics.Distributions
/// <returns>a sample from the distribution.</returns> /// <returns>a sample from the distribution.</returns>
public double Sample() public double Sample()
{ {
return Math.Exp(Normal.SampleUnchecked(_random, _mu, _sigma)); return Math.Exp(Normal.Sample(_random, _mu, _sigma));
} }
/// <summary> /// <summary>
@ -312,7 +313,63 @@ namespace MathNet.Numerics.Distributions
/// <returns>a sequence of samples from the distribution.</returns> /// <returns>a sequence of samples from the distribution.</returns>
public IEnumerable<double> Samples() public IEnumerable<double> Samples()
{ {
return Normal.SamplesUnchecked(_random, _mu, _sigma).Select(Math.Exp); return Normal.Samples(_random, _mu, _sigma).Select(Math.Exp);
}
/// <summary>
/// Computes the probability density of the distribution (PDF) at x, i.e. ∂P(X ≤ x)/∂x.
/// </summary>
/// <param name="x">The location at which to compute the density.</param>
/// <param name="mu">The log-scale (μ) of the distribution.</param>
/// <param name="sigma">The shape (σ) of the distribution. Range: σ ≥ 0.</param>
/// <returns>the density at <paramref name="x"/>.</returns>
public static double PDF(double mu, double sigma, double x)
{
if (sigma < 0.0) throw new ArgumentOutOfRangeException(Resources.InvalidDistributionParameters);
if (x < 0.0)
{
return 0.0;
}
var a = (Math.Log(x) - mu) / sigma;
return Math.Exp(-0.5*a*a)/(x*sigma*Constants.Sqrt2Pi);
}
/// <summary>
/// Computes the log probability density of the distribution (lnPDF) at x, i.e. ln(∂P(X ≤ x)/∂x).
/// </summary>
/// <param name="x">The location at which to compute the density.</param>
/// <param name="mu">The log-scale (μ) of the distribution.</param>
/// <param name="sigma">The shape (σ) of the distribution. Range: σ ≥ 0.</param>
/// <returns>the log density at <paramref name="x"/>.</returns>
public static double PDFLn(double mu, double sigma, double x)
{
if (sigma < 0.0) throw new ArgumentOutOfRangeException(Resources.InvalidDistributionParameters);
if (x < 0.0)
{
return Double.NegativeInfinity;
}
var a = (Math.Log(x) - mu) / sigma;
return (-0.5*a*a) - Math.Log(x*sigma) - Constants.LogSqrt2Pi;
}
/// <summary>
/// Computes the cumulative distribution (CDF) of the distribution at x, i.e. P(X ≤ x).
/// </summary>
/// <param name="x">The location at which to compute the cumulative distribution function.</param>
/// <param name="mu">The log-scale (μ) of the distribution.</param>
/// <param name="sigma">The shape (σ) of the distribution. Range: σ ≥ 0.</param>
/// <returns>the cumulative distribution at location <paramref name="x"/>.</returns>
public static double CDF(double mu, double sigma, double x)
{
if (sigma < 0.0) throw new ArgumentOutOfRangeException(Resources.InvalidDistributionParameters);
return x < 0.0
? 0.0
: 0.5*(1.0 + SpecialFunctions.Erf((Math.Log(x) - mu)/(sigma*Constants.Sqrt2)));
} }
/// <summary> /// <summary>
@ -320,7 +377,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="mu">The log-scale (μ) of the distribution.</param> /// <param name="mu">The log-scale (μ) of the distribution.</param>
/// <param name="sigma">The shape (σ) of the distribution.</param> /// <param name="sigma">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 mu, double sigma) public static double Sample(System.Random rnd, double mu, double sigma)
{ {
@ -332,7 +389,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="mu">The log-scale (μ) of the distribution.</param> /// <param name="mu">The log-scale (μ) of the distribution.</param>
/// <param name="sigma">The shape (σ) of the distribution.</param> /// <param name="sigma">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 mu, double sigma) public static IEnumerable<double> Samples(System.Random rnd, double mu, double sigma)
{ {

2
src/Numerics/Distributions/MatrixNormal.cs

@ -150,7 +150,7 @@ namespace MathNet.Numerics.Distributions
/// <param name="m">The mean of the matrix normal.</param> /// <param name="m">The mean of the matrix normal.</param>
/// <param name="v">The covariance matrix for the rows.</param> /// <param name="v">The covariance matrix for the rows.</param>
/// <param name="k">The covariance matrix for the columns.</param> /// <param name="k">The covariance matrix for the columns.</param>
/// <exception cref="ArgumentOutOfRangeException">When the parameters don't pass the <see cref="IsValidParameterSet"/> function.</exception> /// <exception cref="ArgumentOutOfRangeException">When the parameters are out of range.</exception>
void SetParameters(Matrix<double> m, Matrix<double> v, Matrix<double> k) void SetParameters(Matrix<double> m, Matrix<double> v, Matrix<double> k)
{ {
if (Control.CheckDistributionParameters && !IsValidParameterSet(m, v, k)) if (Control.CheckDistributionParameters && !IsValidParameterSet(m, v, k))

2
src/Numerics/Distributions/Multinomial.cs

@ -165,7 +165,7 @@ namespace MathNet.Numerics.Distributions
/// <param name="p">An array of nonnegative ratios: this array does not need to be normalized /// <param name="p">An array of nonnegative ratios: this array does not need to be normalized
/// as this is often impossible using floating point arithmetic.</param> /// as this is often impossible using floating point arithmetic.</param>
/// <param name="n">The number of trials.</param> /// <param name="n">The number of trials.</param>
/// <exception cref="ArgumentOutOfRangeException">When the parameters don't pass the <see cref="IsValidParameterSet"/> function.</exception> /// <exception cref="ArgumentOutOfRangeException">When the parameters are out of range.</exception>
void SetParameters(double[] p, int n) void SetParameters(double[] p, int n)
{ {
if (Control.CheckDistributionParameters && !IsValidParameterSet(p, n)) if (Control.CheckDistributionParameters && !IsValidParameterSet(p, n))

4
src/Numerics/Distributions/NegativeBinomial.cs

@ -103,7 +103,7 @@ namespace MathNet.Numerics.Distributions
/// </summary> /// </summary>
/// <param name="r">The number of failures until the experiment stopped.</param> /// <param name="r">The number of failures until the experiment stopped.</param>
/// <param name="p">The probability of a trial resulting in success.</param> /// <param name="p">The probability of a trial resulting in success.</param>
/// <exception cref="ArgumentOutOfRangeException">When the parameters don't pass the <see cref="IsValidParameterSet"/> function.</exception> /// <exception cref="ArgumentOutOfRangeException">When the parameters are out of range.</exception>
void SetParameters(double r, double p) void SetParameters(double r, double p)
{ {
if (Control.CheckDistributionParameters && !IsValidParameterSet(r, p)) if (Control.CheckDistributionParameters && !IsValidParameterSet(r, p))
@ -244,7 +244,7 @@ namespace MathNet.Numerics.Distributions
} }
/// <summary> /// <summary>
/// Computes the cumulative distribution (CDF) of the distribution at x, i.e. P(X &lt;= x). /// Computes the cumulative distribution (CDF) of the distribution at x, i.e. P(X x).
/// </summary> /// </summary>
/// <param name="x">The location at which to compute the cumulative distribution function.</param> /// <param name="x">The location at which to compute the cumulative distribution function.</param>
/// <returns>the cumulative distribution at location <paramref name="x"/>.</returns> /// <returns>the cumulative distribution at location <paramref name="x"/>.</returns>

242
src/Numerics/Distributions/Normal.cs

@ -78,7 +78,7 @@ 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="mean">The mean (μ) of the normal distribution.</param> /// <param name="mean">The mean (μ) of the normal distribution.</param>
/// <param name="stddev">The standard deviation (σ) of the normal distribution.</param> /// <param name="stddev">The standard deviation (σ) of the normal distribution. Range: σ ≥ 0.</param>
public Normal(double mean, double stddev) public Normal(double mean, double stddev)
{ {
_random = new System.Random(); _random = new System.Random();
@ -90,7 +90,7 @@ 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="mean">The mean (μ) of the normal distribution.</param> /// <param name="mean">The mean (μ) of the normal distribution.</param>
/// <param name="stddev">The standard deviation (σ) of the normal distribution.</param> /// <param name="stddev">The standard deviation (σ) of the normal 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 Normal(double mean, double stddev, System.Random randomSource) public Normal(double mean, double stddev, System.Random randomSource)
{ {
@ -99,48 +99,51 @@ namespace MathNet.Numerics.Distributions
} }
/// <summary> /// <summary>
/// Constructs a normal distribution from a mean and standard deviation. The distribution will /// Constructs a normal distribution from a mean and standard deviation.
/// be initialized with the default <seealso cref="System.Random"/> random number generator.
/// </summary> /// </summary>
/// <param name="mean">The mean (μ) of the normal distribution.</param> /// <param name="mean">The mean (μ) of the normal distribution.</param>
/// <param name="stddev">The standard deviation (σ) of the normal distribution.</param> /// <param name="stddev">The standard deviation (σ) of the normal distribution. Range: σ ≥ 0.</param>
/// <param name="randomSource">The random number generator which is used to draw random samples. Optional, can be null.</param>
/// <returns>a normal distribution.</returns> /// <returns>a normal distribution.</returns>
public static Normal WithMeanStdDev(double mean, double stddev) public static Normal WithMeanStdDev(double mean, double stddev, System.Random randomSource = null)
{ {
return new Normal(mean, stddev); return new Normal(mean, stddev, randomSource);
} }
/// <summary> /// <summary>
/// Constructs a normal distribution from a mean and variance. The distribution will /// Constructs a normal distribution from a mean and variance.
/// be initialized with the default <seealso cref="System.Random"/> random number generator.
/// </summary> /// </summary>
/// <param name="mean">The mean (μ) of the normal distribution.</param> /// <param name="mean">The mean (μ) of the normal distribution.</param>
/// <param name="var">The variance of the normal distribution.</param> /// <param name="var">The variance (σ^2) of the normal distribution.</param>
/// <returns>a normal distribution.</returns> /// <param name="randomSource">The random number generator which is used to draw random samples. Optional, can be null.</param>
public static Normal WithMeanVariance(double mean, double var) /// <returns>A normal distribution.</returns>
public static Normal WithMeanVariance(double mean, double var, System.Random randomSource = null)
{ {
return new Normal(mean, Math.Sqrt(var)); return new Normal(mean, Math.Sqrt(var), randomSource);
} }
/// <summary> /// <summary>
/// Constructs a normal distribution from a mean and precision. The distribution will /// Constructs a normal distribution from a mean and precision.
/// be initialized with the default <seealso cref="System.Random"/> random number generator.
/// </summary> /// </summary>
/// <param name="mean">The mean (μ) of the normal distribution.</param> /// <param name="mean">The mean (μ) of the normal distribution.</param>
/// <param name="precision">The precision of the normal distribution.</param> /// <param name="precision">The precision of the normal distribution.</param>
/// <returns>a normal distribution.</returns> /// <param name="randomSource">The random number generator which is used to draw random samples. Optional, can be null.</param>
public static Normal WithMeanPrecision(double mean, double precision) /// <returns>A normal distribution.</returns>
public static Normal WithMeanPrecision(double mean, double precision, System.Random randomSource = null)
{ {
return new Normal(mean, 1.0/Math.Sqrt(precision)); return new Normal(mean, 1.0/Math.Sqrt(precision), randomSource);
} }
/// <summary> /// <summary>
/// Estimates the normal distribution parameters from sample data with maximum-likelihood. /// Estimates the normal distribution parameters from sample data with maximum-likelihood.
/// </summary> /// </summary>
public static Normal Estimate(IEnumerable<double> samples) /// <param name="samples">The samples to estimate the distribution parameters from.</param>
/// <param name="randomSource">The random number generator which is used to draw random samples. Optional, can be null.</param>
/// <returns>A normal distribution.</returns>
public static Normal Estimate(IEnumerable<double> samples, System.Random randomSource = null)
{ {
var meanVariance = samples.MeanVariance(); var meanVariance = samples.MeanVariance();
return new Normal(meanVariance.Item1, Math.Sqrt(meanVariance.Item2)); return new Normal(meanVariance.Item1, Math.Sqrt(meanVariance.Item2), randomSource);
} }
/// <summary> /// <summary>
@ -152,26 +155,15 @@ namespace MathNet.Numerics.Distributions
return "Normal(μ = " + _mean + ", σ = " + _stdDev + ")"; return "Normal(μ = " + _mean + ", σ = " + _stdDev + ")";
} }
/// <summary>
/// Checks whether the parameters of the distribution are valid.
/// </summary>
/// <param name="mean">The mean (μ) of the normal distribution.</param>
/// <param name="stddev">The standard deviation (σ) of the normal distribution.</param>
/// <returns><c>true</c> when the parameters are valid, <c>false</c> otherwise.</returns>
static bool IsValidParameterSet(double mean, double stddev)
{
return stddev >= 0.0 && !Double.IsNaN(mean);
}
/// <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="mean">The mean (μ) of the normal distribution.</param> /// <param name="mean">The mean (μ) of the normal distribution.</param>
/// <param name="stddev">The standard deviation (σ) of the normal distribution.</param> /// <param name="stddev">The standard deviation (σ) of the normal distribution. Range: σ ≥ 0.</param>
/// <exception cref="ArgumentOutOfRangeException">When the parameters don't pass the <see cref="IsValidParameterSet"/> function.</exception> /// <exception cref="ArgumentOutOfRangeException">When the parameters are out of range.</exception>
void SetParameters(double mean, double stddev) void SetParameters(double mean, double stddev)
{ {
if (Control.CheckDistributionParameters && !IsValidParameterSet(mean, stddev)) if (stddev < 0.0 || Double.IsNaN(mean) || Double.IsNaN(stddev))
{ {
throw new ArgumentOutOfRangeException(Resources.InvalidDistributionParameters); throw new ArgumentOutOfRangeException(Resources.InvalidDistributionParameters);
} }
@ -190,7 +182,7 @@ namespace MathNet.Numerics.Distributions
} }
/// <summary> /// <summary>
/// Gets or sets the standard deviation (σ) of the normal distribution. /// Gets or sets the standard deviation (σ) of the normal distribution. Range: σ ≥ 0.
/// </summary> /// </summary>
public double StdDev public double StdDev
{ {
@ -203,7 +195,7 @@ namespace MathNet.Numerics.Distributions
/// </summary> /// </summary>
public double Variance public double Variance
{ {
get { return _stdDev * _stdDev; } get { return _stdDev*_stdDev; }
set { SetParameters(_mean, Math.Sqrt(value)); } set { SetParameters(_mean, Math.Sqrt(value)); }
} }
@ -212,10 +204,10 @@ namespace MathNet.Numerics.Distributions
/// </summary> /// </summary>
public double Precision public double Precision
{ {
get { return 1.0 / (_stdDev * _stdDev); } get { return 1.0/(_stdDev*_stdDev); }
set set
{ {
var sdev = 1.0 / Math.Sqrt(value); var sdev = 1.0/Math.Sqrt(value);
// Handle the case when the precision is -0. // Handle the case when the precision is -0.
if (Double.IsInfinity(sdev)) if (Double.IsInfinity(sdev))
{ {
@ -283,71 +275,35 @@ namespace MathNet.Numerics.Distributions
} }
/// <summary> /// <summary>
/// Computes the density of the normal distribution (PDF), i.e. dP(X &lt;= x)/dx. /// Computes the probability density of the distribution (PDF) at x, i.e. ∂P(X ≤ x)/∂x.
/// </summary>
/// <param name="mean">The mean (μ) of the normal distribution.</param>
/// <param name="stddev">The standard deviation (σ) of the normal distribution.</param>
/// <param name="x">The location at which to compute the density.</param>
/// <returns>the density at <paramref name="x"/>.</returns>
internal static double Density(double mean, double stddev, double x)
{
var d = (x - mean)/stddev;
return Math.Exp(-0.5*d*d)/(Constants.Sqrt2Pi*stddev);
}
/// <summary>
/// Computes the log density of the normal distribution (lnPDF), i.e. ln(dP(X &lt;= x)/dx).
/// </summary>
/// <param name="mean">The mean (μ) of the normal distribution.</param>
/// <param name="stddev">The standard deviation (σ) of the normal distribution.</param>
/// <param name="x">The location at which to compute the density.</param>
/// <returns>the log density at <paramref name="x"/>.</returns>
internal static double DensityLn(double mean, double stddev, double x)
{
var d = (x - mean)/stddev;
return (-0.5*d*d) - Math.Log(stddev) - Constants.LogSqrt2Pi;
}
/// <summary>
/// Computes the probability density of the distribution (PDF) at x, i.e. dP(X &lt;= x)/dx.
/// </summary> /// </summary>
/// <param name="x">The location at which to compute the density.</param> /// <param name="x">The location at which to compute the density.</param>
/// <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)
{ {
return Density(_mean, _stdDev, x); var d = (x - _mean)/_stdDev;
return Math.Exp(-0.5*d*d)/(Constants.Sqrt2Pi*_stdDev);
} }
/// <summary> /// <summary>
/// Computes the log probability density of the distribution (lnPDF) at x, i.e. ln(dP(X &lt;= x)/dx). /// Computes the log probability density of the distribution (lnPDF) at x, i.e. ln(∂P(X ≤ x)/∂x).
/// </summary> /// </summary>
/// <param name="x">The location at which to compute the log density.</param> /// <param name="x">The location at which to compute the log density.</param>
/// <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)
{ {
return DensityLn(_mean, _stdDev, x); var d = (x - _mean)/_stdDev;
return (-0.5*d*d) - Math.Log(_stdDev) - Constants.LogSqrt2Pi;
} }
/// <summary> /// <summary>
/// Computes the cumulative distribution function (CDF) of the normal distribution, i.e. P(X &lt;= x). /// Computes the cumulative distribution (CDF) of the distribution at x, i.e. P(X ≤ x).
/// </summary>
/// <param name="mean">The mean (μ) of the normal distribution.</param>
/// <param name="stddev">The standard deviation (σ) of the normal distribution.</param>
/// <param name="x">The location at which to compute the cumulative density.</param>
/// <returns>the cumulative density at <paramref name="x"/>.</returns>
internal static double CumulativeDistribution(double mean, double stddev, double x)
{
return 0.5*(1.0 + SpecialFunctions.Erf((x - mean)/(stddev*Constants.Sqrt2)));
}
/// <summary>
/// Computes the cumulative distribution (CDF) of the distribution at x, i.e. P(X &lt;= x).
/// </summary> /// </summary>
/// <param name="x">The location at which to compute the cumulative distribution function.</param> /// <param name="x">The location at which to compute the cumulative distribution function.</param>
/// <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)
{ {
return CumulativeDistribution(_mean, _stdDev, x); return 0.5*(1.0 + SpecialFunctions.Erf((x - _mean)/(_stdDev*Constants.Sqrt2)));
} }
/// <summary> /// <summary>
@ -361,6 +317,29 @@ namespace MathNet.Numerics.Distributions
return _mean - (_stdDev*Constants.Sqrt2*SpecialFunctions.ErfcInv(2.0*p)); return _mean - (_stdDev*Constants.Sqrt2*SpecialFunctions.ErfcInv(2.0*p));
} }
/// <summary>
/// Generates a sample from the normal distribution using the <i>Box-Muller</i> algorithm.
/// </summary>
/// <returns>a sample from the distribution.</returns>
public double Sample()
{
return _mean + (_stdDev*SampleStandardBoxMuller(_random).Item1);
}
/// <summary>
/// Generates a sequence of samples from the normal distribution using the <i>Box-Muller</i> algorithm.
/// </summary>
/// <returns>a sequence of samples from the distribution.</returns>
public IEnumerable<double> Samples()
{
while (true)
{
var sample = SampleStandardBoxMuller(_random);
yield return _mean + (_stdDev*sample.Item1);
yield return _mean + (_stdDev*sample.Item2);
}
}
/// <summary> /// <summary>
/// Samples a pair of standard normal distributed random variables using the <i>Box-Muller</i> algorithm. /// Samples a pair of standard normal distributed random variables using the <i>Box-Muller</i> algorithm.
/// </summary> /// </summary>
@ -368,65 +347,77 @@ namespace MathNet.Numerics.Distributions
/// <returns>a pair of random numbers from the standard normal distribution.</returns> /// <returns>a pair of random numbers from the standard normal distribution.</returns>
static Tuple<double, double> SampleStandardBoxMuller(System.Random rnd) static Tuple<double, double> SampleStandardBoxMuller(System.Random rnd)
{ {
var v1 = (2.0*rnd.NextDouble()) - 1.0; var v1 = (2.0 * rnd.NextDouble()) - 1.0;
var v2 = (2.0*rnd.NextDouble()) - 1.0; var v2 = (2.0 * rnd.NextDouble()) - 1.0;
var r = (v1*v1) + (v2*v2); var r = (v1 * v1) + (v2 * v2);
while (r >= 1.0 || r == 0.0) while (r >= 1.0 || r == 0.0)
{ {
v1 = (2.0*rnd.NextDouble()) - 1.0; v1 = (2.0 * rnd.NextDouble()) - 1.0;
v2 = (2.0*rnd.NextDouble()) - 1.0; v2 = (2.0 * rnd.NextDouble()) - 1.0;
r = (v1*v1) + (v2*v2); r = (v1 * v1) + (v2 * v2);
} }
var fac = Math.Sqrt(-2.0*Math.Log(r)/r); var fac = Math.Sqrt(-2.0 * Math.Log(r) / r);
return new Tuple<double, double>(v1*fac, v2*fac); return new Tuple<double, double>(v1 * fac, v2 * fac);
} }
/// <summary> /// <summary>
/// Samples the distribution. /// Computes the probability density of the distribution (PDF) at x, i.e. ∂P(X ≤ x)/∂x.
/// </summary> /// </summary>
/// <param name="rnd">The random number generator to use.</param>
/// <param name="mean">The mean (μ) of the normal distribution.</param> /// <param name="mean">The mean (μ) of the normal distribution.</param>
/// <param name="stddev">The standard deviation (σ) of the normal distribution.</param> /// <param name="stddev">The standard deviation (σ) of the normal distribution. Range: σ ≥ 0.</param>
/// <returns>a random number from the distribution.</returns> /// <param name="x">The location at which to compute the density.</param>
internal static double SampleUnchecked(System.Random rnd, double mean, double stddev) /// <returns>the density at <paramref name="x"/>.</returns>
public static double PDF(double mean, double stddev, double x)
{ {
return mean + (stddev*SampleStandardBoxMuller(rnd).Item1); if (stddev < 0.0) throw new ArgumentOutOfRangeException("stddev", Resources.InvalidDistributionParameters);
var d = (x - mean)/stddev;
return Math.Exp(-0.5*d*d)/(Constants.Sqrt2Pi*stddev);
} }
/// <summary> /// <summary>
/// Samples the distribution. /// Computes the log probability density of the distribution (lnPDF) at x, i.e. ln(∂P(X ≤ x)/∂x).
/// </summary> /// </summary>
/// <param name="rnd">The random number generator to use.</param>
/// <param name="mean">The mean (μ) of the normal distribution.</param> /// <param name="mean">The mean (μ) of the normal distribution.</param>
/// <param name="stddev">The standard deviation (σ) of the normal distribution.</param> /// <param name="stddev">The standard deviation (σ) of the normal distribution. Range: σ ≥ 0.</param>
/// <returns>a random number from the distribution.</returns> /// <param name="x">The location at which to compute the density.</param>
internal static IEnumerable<double> SamplesUnchecked(System.Random rnd, double mean, double stddev) /// <returns>the log density at <paramref name="x"/>.</returns>
public static double PDFLn(double mean, double stddev, double x)
{ {
while (true) if (stddev < 0.0) throw new ArgumentOutOfRangeException("stddev", Resources.InvalidDistributionParameters);
{
var sample = SampleStandardBoxMuller(rnd); var d = (x - mean)/stddev;
yield return mean + (stddev*sample.Item1); return (-0.5*d*d) - Math.Log(stddev) - Constants.LogSqrt2Pi;
yield return mean + (stddev*sample.Item2);
}
} }
/// <summary> /// <summary>
/// Generates a sample from the normal distribution using the <i>Box-Muller</i> algorithm. /// Computes the cumulative distribution (CDF) of the distribution at x, i.e. P(X ≤ x).
/// </summary> /// </summary>
/// <returns>a sample from the distribution.</returns> /// <param name="x">The location at which to compute the cumulative distribution function.</param>
public double Sample() /// <param name="mean">The mean (μ) of the normal distribution.</param>
/// <param name="stddev">The standard deviation (σ) of the normal distribution. Range: σ ≥ 0.</param>
/// <returns>the cumulative distribution at location <paramref name="x"/>.</returns>
public static double CDF(double mean, double stddev, double x)
{ {
return SampleUnchecked(_random, _mean, _stdDev); if (stddev < 0.0) throw new ArgumentOutOfRangeException("stddev", Resources.InvalidDistributionParameters);
return 0.5*(1.0 + SpecialFunctions.Erf((x - mean)/(stddev*Constants.Sqrt2)));
} }
/// <summary> /// <summary>
/// Generates a sequence of samples from the normal distribution using the <i>Box-Muller</i> algorithm. /// Computes the inverse of the cumulative distribution function (InvCDF) for the distribution
/// at the given probability.
/// </summary> /// </summary>
/// <returns>a sequence of samples from the distribution.</returns> /// <param name="p">The location at which to compute the inverse cumulative density.</param>
public IEnumerable<double> Samples() /// <param name="mean">The mean (μ) of the normal distribution.</param>
/// <param name="stddev">The standard deviation (σ) of the normal distribution. Range: σ ≥ 0.</param>
/// <returns>the inverse cumulative density at <paramref name="p"/>.</returns>
public static double InvCDF(double mean, double stddev, double p)
{ {
return SamplesUnchecked(_random, _mean, _stdDev); if (stddev < 0.0) throw new ArgumentOutOfRangeException("stddev", Resources.InvalidDistributionParameters);
return mean - (stddev*Constants.Sqrt2*SpecialFunctions.ErfcInv(2.0*p));
} }
/// <summary> /// <summary>
@ -434,16 +425,13 @@ 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="mean">The mean (μ) of the normal distribution.</param> /// <param name="mean">The mean (μ) of the normal distribution.</param>
/// <param name="stddev">The standard deviation (σ) of the normal distribution.</param> /// <param name="stddev">The standard deviation (σ) of the normal 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 mean, double stddev) public static double Sample(System.Random rnd, double mean, double stddev)
{ {
if (Control.CheckDistributionParameters && !IsValidParameterSet(mean, stddev)) if (stddev < 0.0) throw new ArgumentOutOfRangeException("stddev", Resources.InvalidDistributionParameters);
{
throw new ArgumentOutOfRangeException(Resources.InvalidDistributionParameters);
}
return SampleUnchecked(rnd, mean, stddev); return mean + (stddev*SampleStandardBoxMuller(rnd).Item1);
} }
/// <summary> /// <summary>
@ -451,16 +439,18 @@ 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="mean">The mean (μ) of the normal distribution.</param> /// <param name="mean">The mean (μ) of the normal distribution.</param>
/// <param name="stddev">The standard deviation (σ) of the normal distribution.</param> /// <param name="stddev">The standard deviation (σ) of the normal 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 mean, double stddev) public static IEnumerable<double> Samples(System.Random rnd, double mean, double stddev)
{ {
if (Control.CheckDistributionParameters && !IsValidParameterSet(mean, stddev)) if (stddev < 0.0) throw new ArgumentOutOfRangeException("stddev", Resources.InvalidDistributionParameters);
while (true)
{ {
throw new ArgumentOutOfRangeException(Resources.InvalidDistributionParameters); var sample = SampleStandardBoxMuller(rnd);
yield return mean + (stddev*sample.Item1);
yield return mean + (stddev*sample.Item2);
} }
return SamplesUnchecked(rnd, mean, stddev);
} }
} }
} }

2
src/Numerics/Distributions/NormalGamma.cs

@ -166,7 +166,7 @@ namespace MathNet.Numerics.Distributions
/// <param name="meanScale">The scale of the mean.</param> /// <param name="meanScale">The scale of the mean.</param>
/// <param name="precShape">The shape of the precision.</param> /// <param name="precShape">The shape of the precision.</param>
/// <param name="precInvScale">The inverse scale of the precision.</param> /// <param name="precInvScale">The inverse scale of the precision.</param>
/// <exception cref="ArgumentOutOfRangeException">When the parameters don't pass the <see cref="IsValidParameterSet"/> function.</exception> /// <exception cref="ArgumentOutOfRangeException">When the parameters are out of range.</exception>
void SetParameters(double meanLocation, double meanScale, double precShape, double precInvScale) void SetParameters(double meanLocation, double meanScale, double precShape, double precInvScale)
{ {
if (Control.CheckDistributionParameters && !IsValidParameterSet(meanLocation, meanScale, precShape, precInvScale)) if (Control.CheckDistributionParameters && !IsValidParameterSet(meanLocation, meanScale, precShape, precInvScale))

8
src/Numerics/Distributions/Pareto.cs

@ -103,7 +103,7 @@ namespace MathNet.Numerics.Distributions
/// </summary> /// </summary>
/// <param name="scale">The scale (xm) of the distribution.</param> /// <param name="scale">The scale (xm) of the distribution.</param>
/// <param name="shape">The shape (α) of the distribution.</param> /// <param name="shape">The shape (α) of the distribution.</param>
/// <exception cref="ArgumentOutOfRangeException">When the parameters don't pass the <see cref="IsValidParameterSet"/> function.</exception> /// <exception cref="ArgumentOutOfRangeException">When the parameters are out of range.</exception>
void SetParameters(double scale, double shape) void SetParameters(double scale, double shape)
{ {
if (Control.CheckDistributionParameters && !IsValidParameterSet(scale, shape)) if (Control.CheckDistributionParameters && !IsValidParameterSet(scale, shape))
@ -231,7 +231,7 @@ namespace MathNet.Numerics.Distributions
} }
/// <summary> /// <summary>
/// Computes the probability density of the distribution (PDF) at x, i.e. dP(X &lt;= x)/dx. /// Computes the probability density of the distribution (PDF) at x, i.e. ∂P(X ≤ x)/∂x.
/// </summary> /// </summary>
/// <param name="x">The location at which to compute the density.</param> /// <param name="x">The location at which to compute the density.</param>
/// <returns>the density at <paramref name="x"/>.</returns> /// <returns>the density at <paramref name="x"/>.</returns>
@ -241,7 +241,7 @@ namespace MathNet.Numerics.Distributions
} }
/// <summary> /// <summary>
/// Computes the log probability density of the distribution (lnPDF) at x, i.e. ln(dP(X &lt;= x)/dx). /// Computes the log probability density of the distribution (lnPDF) at x, i.e. ln(∂P(X ≤ x)/∂x).
/// </summary> /// </summary>
/// <param name="x">The location at which to compute the log density.</param> /// <param name="x">The location at which to compute the log density.</param>
/// <returns>the log density at <paramref name="x"/>.</returns> /// <returns>the log density at <paramref name="x"/>.</returns>
@ -251,7 +251,7 @@ namespace MathNet.Numerics.Distributions
} }
/// <summary> /// <summary>
/// Computes the cumulative distribution (CDF) of the distribution at x, i.e. P(X &lt;= x). /// Computes the cumulative distribution (CDF) of the distribution at x, i.e. P(X x).
/// </summary> /// </summary>
/// <param name="x">The location at which to compute the cumulative distribution function.</param> /// <param name="x">The location at which to compute the cumulative distribution function.</param>
/// <returns>the cumulative distribution at location <paramref name="x"/>.</returns> /// <returns>the cumulative distribution at location <paramref name="x"/>.</returns>

4
src/Numerics/Distributions/Poisson.cs

@ -96,7 +96,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="lambda">The mean (λ) of the distribution.</param> /// <param name="lambda">The mean (λ) of the distribution.</param>
/// <exception cref="System.ArgumentOutOfRangeException">When the parameters don't pass the <see cref="IsValidParameterSet"/> function.</exception> /// <exception cref="ArgumentOutOfRangeException">When the parameters are out of range.</exception>
void SetParameters(double lambda) void SetParameters(double lambda)
{ {
if (Control.CheckDistributionParameters && !IsValidParameterSet(lambda)) if (Control.CheckDistributionParameters && !IsValidParameterSet(lambda))
@ -220,7 +220,7 @@ namespace MathNet.Numerics.Distributions
} }
/// <summary> /// <summary>
/// Computes the cumulative distribution (CDF) of the distribution at x, i.e. P(X &lt;= x). /// Computes the cumulative distribution (CDF) of the distribution at x, i.e. P(X x).
/// </summary> /// </summary>
/// <param name="x">The location at which to compute the cumulative distribution function.</param> /// <param name="x">The location at which to compute the cumulative distribution function.</param>
/// <returns>the cumulative distribution at location <paramref name="x"/>.</returns> /// <returns>the cumulative distribution at location <paramref name="x"/>.</returns>

8
src/Numerics/Distributions/Rayleigh.cs

@ -99,7 +99,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="scale">The scale (σ) of the distribution.</param> /// <param name="scale">The scale (σ) of the distribution.</param>
/// <exception cref="ArgumentOutOfRangeException">When the parameters don't pass the <see cref="IsValidParameterSet"/> function.</exception> /// <exception cref="ArgumentOutOfRangeException">When the parameters are out of range.</exception>
void SetParameters(double scale) void SetParameters(double scale)
{ {
if (Control.CheckDistributionParameters && !IsValidParameterSet(scale)) if (Control.CheckDistributionParameters && !IsValidParameterSet(scale))
@ -201,7 +201,7 @@ namespace MathNet.Numerics.Distributions
} }
/// <summary> /// <summary>
/// Computes the probability density of the distribution (PDF) at x, i.e. dP(X &lt;= x)/dx. /// Computes the probability density of the distribution (PDF) at x, i.e. ∂P(X ≤ x)/∂x.
/// </summary> /// </summary>
/// <param name="x">The location at which to compute the density.</param> /// <param name="x">The location at which to compute the density.</param>
/// <returns>the density at <paramref name="x"/>.</returns> /// <returns>the density at <paramref name="x"/>.</returns>
@ -211,7 +211,7 @@ namespace MathNet.Numerics.Distributions
} }
/// <summary> /// <summary>
/// Computes the log probability density of the distribution (lnPDF) at x, i.e. ln(dP(X &lt;= x)/dx). /// Computes the log probability density of the distribution (lnPDF) at x, i.e. ln(∂P(X ≤ x)/∂x).
/// </summary> /// </summary>
/// <param name="x">The location at which to compute the log density.</param> /// <param name="x">The location at which to compute the log density.</param>
/// <returns>the log density at <paramref name="x"/>.</returns> /// <returns>the log density at <paramref name="x"/>.</returns>
@ -221,7 +221,7 @@ namespace MathNet.Numerics.Distributions
} }
/// <summary> /// <summary>
/// Computes the cumulative distribution (CDF) of the distribution at x, i.e. P(X &lt;= x). /// Computes the cumulative distribution (CDF) of the distribution at x, i.e. P(X x).
/// </summary> /// </summary>
/// <param name="x">The location at which to compute the cumulative distribution function.</param> /// <param name="x">The location at which to compute the cumulative distribution function.</param>
/// <returns>the cumulative distribution at location <paramref name="x"/>.</returns> /// <returns>the cumulative distribution at location <paramref name="x"/>.</returns>

7
src/Numerics/Distributions/Stable.cs

@ -112,6 +112,7 @@ namespace MathNet.Numerics.Distributions
/// <param name="beta">The skewness (β) of the distribution.</param> /// <param name="beta">The skewness (β) of the distribution.</param>
/// <param name="scale">The scale (c) of the distribution.</param> /// <param name="scale">The scale (c) of the distribution.</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>
void SetParameters(double alpha, double beta, double scale, double location) void SetParameters(double alpha, double beta, double scale, double location)
{ {
if (Control.CheckDistributionParameters && !IsValidParameterSet(alpha, beta, scale, location)) if (Control.CheckDistributionParameters && !IsValidParameterSet(alpha, beta, scale, location))
@ -303,7 +304,7 @@ namespace MathNet.Numerics.Distributions
} }
/// <summary> /// <summary>
/// Computes the probability density of the distribution (PDF) at x, i.e. dP(X &lt;= x)/dx. /// Computes the probability density of the distribution (PDF) at x, i.e. ∂P(X ≤ x)/∂x.
/// </summary> /// </summary>
/// <param name="x">The location at which to compute the density.</param> /// <param name="x">The location at which to compute the density.</param>
/// <returns>the density at <paramref name="x"/>.</returns> /// <returns>the density at <paramref name="x"/>.</returns>
@ -346,7 +347,7 @@ namespace MathNet.Numerics.Distributions
} }
/// <summary> /// <summary>
/// Computes the log probability density of the distribution (lnPDF) at x, i.e. ln(dP(X &lt;= x)/dx). /// Computes the log probability density of the distribution (lnPDF) at x, i.e. ln(∂P(X ≤ x)/∂x).
/// </summary> /// </summary>
/// <param name="x">The location at which to compute the log density.</param> /// <param name="x">The location at which to compute the log density.</param>
/// <returns>the log density at <paramref name="x"/>.</returns> /// <returns>the log density at <paramref name="x"/>.</returns>
@ -356,7 +357,7 @@ namespace MathNet.Numerics.Distributions
} }
/// <summary> /// <summary>
/// Computes the cumulative distribution (CDF) of the distribution at x, i.e. P(X &lt;= x). /// Computes the cumulative distribution (CDF) of the distribution at x, i.e. P(X x).
/// </summary> /// </summary>
/// <param name="x">The location at which to compute the cumulative distribution function.</param> /// <param name="x">The location at which to compute the cumulative distribution function.</param>
/// <returns>the cumulative distribution at location <paramref name="x"/>.</returns> /// <returns>the cumulative distribution at location <paramref name="x"/>.</returns>

16
src/Numerics/Distributions/StudentT.cs

@ -129,7 +129,7 @@ namespace MathNet.Numerics.Distributions
/// <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.</param>
/// <param name="freedom">The degrees of freedom (ν) for the distribution.</param> /// <param name="freedom">The degrees of freedom (ν) for the distribution.</param>
/// <exception cref="ArgumentOutOfRangeException">When the parameters don't pass the <see cref="IsValidParameterSet"/> function.</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)
{ {
if (Control.CheckDistributionParameters && !IsValidParameterSet(location, scale, freedom)) if (Control.CheckDistributionParameters && !IsValidParameterSet(location, scale, freedom))
@ -288,7 +288,7 @@ namespace MathNet.Numerics.Distributions
} }
/// <summary> /// <summary>
/// Computes the probability density of the distribution (PDF) at x, i.e. dP(X &lt;= x)/dx. /// Computes the probability density of the distribution (PDF) at x, i.e. ∂P(X ≤ x)/∂x.
/// </summary> /// </summary>
/// <param name="x">The location at which to compute the density.</param> /// <param name="x">The location at which to compute the density.</param>
/// <returns>the density at <paramref name="x"/>.</returns> /// <returns>the density at <paramref name="x"/>.</returns>
@ -297,7 +297,7 @@ namespace MathNet.Numerics.Distributions
// TODO JVG we can probably do a better job for Cauchy special case // TODO JVG we can probably do a better job for Cauchy special case
if (_freedom >= 1e+8d) if (_freedom >= 1e+8d)
{ {
return Normal.Density(_location, _scale, x); return Normal.PDF(_location, _scale, x);
} }
var d = (x - _location)/_scale; var d = (x - _location)/_scale;
@ -308,7 +308,7 @@ namespace MathNet.Numerics.Distributions
} }
/// <summary> /// <summary>
/// Computes the log probability density of the distribution (lnPDF) at x, i.e. ln(dP(X &lt;= x)/dx). /// Computes the log probability density of the distribution (lnPDF) at x, i.e. ln(∂P(X ≤ x)/∂x).
/// </summary> /// </summary>
/// <param name="x">The location at which to compute the log density.</param> /// <param name="x">The location at which to compute the log density.</param>
/// <returns>the log density at <paramref name="x"/>.</returns> /// <returns>the log density at <paramref name="x"/>.</returns>
@ -317,7 +317,7 @@ namespace MathNet.Numerics.Distributions
// TODO JVG we can probably do a better job for Cauchy special case // TODO JVG we can probably do a better job for Cauchy special case
if (_freedom >= 1e+8d) if (_freedom >= 1e+8d)
{ {
return Normal.DensityLn(_location, _scale, x); return Normal.PDFLn(_location, _scale, x);
} }
var d = (x - _location)/_scale; var d = (x - _location)/_scale;
@ -328,7 +328,7 @@ namespace MathNet.Numerics.Distributions
} }
/// <summary> /// <summary>
/// Computes the cumulative distribution (CDF) of the distribution at x, i.e. P(X &lt;= x). /// Computes the cumulative distribution (CDF) of the distribution at x, i.e. P(X x).
/// </summary> /// </summary>
/// <param name="x">The location at which to compute the cumulative distribution function.</param> /// <param name="x">The location at which to compute the cumulative distribution function.</param>
/// <returns>the cumulative distribution at location <paramref name="x"/>.</returns> /// <returns>the cumulative distribution at location <paramref name="x"/>.</returns>
@ -337,7 +337,7 @@ namespace MathNet.Numerics.Distributions
// TODO JVG we can probably do a better job for Cauchy special case // TODO JVG we can probably do a better job for Cauchy special case
if (Double.IsPositiveInfinity(_freedom)) if (Double.IsPositiveInfinity(_freedom))
{ {
return Normal.CumulativeDistribution(_location, _scale, x); return Normal.CDF(_location, _scale, x);
} }
var k = (x - _location)/_scale; var k = (x - _location)/_scale;
@ -359,7 +359,7 @@ namespace MathNet.Numerics.Distributions
static double SampleUnchecked(System.Random rnd, double location, double scale, double freedom) static double SampleUnchecked(System.Random rnd, double location, double scale, double freedom)
{ {
var gamma = Gamma.SampleUnchecked(rnd, 0.5*freedom, 0.5); var gamma = Gamma.SampleUnchecked(rnd, 0.5*freedom, 0.5);
return Normal.SampleUnchecked(rnd, location, scale*Math.Sqrt(freedom/gamma)); return Normal.Sample(rnd, location, scale*Math.Sqrt(freedom/gamma));
} }
/// <summary> /// <summary>

8
src/Numerics/Distributions/Weibull.cs

@ -110,7 +110,7 @@ namespace MathNet.Numerics.Distributions
/// </summary> /// </summary>
/// <param name="shape">The shape (k) of the Weibull distribution.</param> /// <param name="shape">The shape (k) of the Weibull distribution.</param>
/// <param name="scale">The scale (λ) of the Weibull distribution.</param> /// <param name="scale">The scale (λ) of the Weibull distribution.</param>
/// <exception cref="ArgumentOutOfRangeException">When the parameters don't pass the <see cref="IsValidParameterSet"/> function.</exception> /// <exception cref="ArgumentOutOfRangeException">When the parameters are out of range.</exception>
void SetParameters(double shape, double scale) void SetParameters(double shape, double scale)
{ {
if (Control.CheckDistributionParameters && !IsValidParameterSet(shape, scale)) if (Control.CheckDistributionParameters && !IsValidParameterSet(shape, scale))
@ -238,7 +238,7 @@ namespace MathNet.Numerics.Distributions
} }
/// <summary> /// <summary>
/// Computes the probability density of the distribution (PDF) at x, i.e. dP(X &lt;= x)/dx. /// Computes the probability density of the distribution (PDF) at x, i.e. ∂P(X ≤ x)/∂x.
/// </summary> /// </summary>
/// <param name="x">The location at which to compute the density.</param> /// <param name="x">The location at which to compute the density.</param>
/// <returns>the density at <paramref name="x"/>.</returns> /// <returns>the density at <paramref name="x"/>.</returns>
@ -258,7 +258,7 @@ namespace MathNet.Numerics.Distributions
} }
/// <summary> /// <summary>
/// Computes the log probability density of the distribution (lnPDF) at x, i.e. ln(dP(X &lt;= x)/dx). /// Computes the log probability density of the distribution (lnPDF) at x, i.e. ln(∂P(X ≤ x)/∂x).
/// </summary> /// </summary>
/// <param name="x">The location at which to compute the log density.</param> /// <param name="x">The location at which to compute the log density.</param>
/// <returns>the log density at <paramref name="x"/>.</returns> /// <returns>the log density at <paramref name="x"/>.</returns>
@ -278,7 +278,7 @@ namespace MathNet.Numerics.Distributions
} }
/// <summary> /// <summary>
/// Computes the cumulative distribution (CDF) of the distribution at x, i.e. P(X &lt;= x). /// Computes the cumulative distribution (CDF) of the distribution at x, i.e. P(X x).
/// </summary> /// </summary>
/// <param name="x">The location at which to compute the cumulative distribution function.</param> /// <param name="x">The location at which to compute the cumulative distribution function.</param>
/// <returns>the cumulative distribution at location <paramref name="x"/>.</returns> /// <returns>the cumulative distribution at location <paramref name="x"/>.</returns>

2
src/Numerics/Distributions/Wishart.cs

@ -95,7 +95,7 @@ namespace MathNet.Numerics.Distributions
/// </summary> /// </summary>
/// <param name="degreesOfFreedom">The degrees of freedom (n) for the Wishart distribution.</param> /// <param name="degreesOfFreedom">The degrees of freedom (n) for the Wishart distribution.</param>
/// <param name="scale">The scale matrix (V) for the Wishart distribution.</param> /// <param name="scale">The scale matrix (V) for the Wishart distribution.</param>
/// <exception cref="ArgumentOutOfRangeException">When the parameters don't pass the <see cref="IsValidParameterSet"/> function.</exception> /// <exception cref="ArgumentOutOfRangeException">When the parameters are out of range.</exception>
void SetParameters(double degreesOfFreedom, Matrix<double> scale) void SetParameters(double degreesOfFreedom, Matrix<double> scale)
{ {
if (Control.CheckDistributionParameters && !IsValidParameterSet(degreesOfFreedom, scale)) if (Control.CheckDistributionParameters && !IsValidParameterSet(degreesOfFreedom, scale))

3
src/Numerics/Distributions/Zipf.cs

@ -109,6 +109,7 @@ namespace MathNet.Numerics.Distributions
/// </summary> /// </summary>
/// <param name="s">The s parameter of the distribution.</param> /// <param name="s">The s parameter of the distribution.</param>
/// <param name="n">The n parameter of the distribution.</param> /// <param name="n">The n parameter of the distribution.</param>
/// <exception cref="ArgumentOutOfRangeException">When the parameters are out of range.</exception>
void SetParameters(double s, int n) void SetParameters(double s, int n)
{ {
if (Control.CheckDistributionParameters && !IsValidParameterSet(s, n)) if (Control.CheckDistributionParameters && !IsValidParameterSet(s, n))
@ -267,7 +268,7 @@ namespace MathNet.Numerics.Distributions
} }
/// <summary> /// <summary>
/// Computes the cumulative distribution (CDF) of the distribution at x, i.e. P(X &lt;= x). /// Computes the cumulative distribution (CDF) of the distribution at x, i.e. P(X x).
/// </summary> /// </summary>
/// <param name="x">The location at which to compute the cumulative distribution function.</param> /// <param name="x">The location at which to compute the cumulative distribution function.</param>
/// <returns>the cumulative distribution at location <paramref name="x"/>.</returns> /// <returns>the cumulative distribution at location <paramref name="x"/>.</returns>

3
src/UnitTests/DistributionTests/Continuous/LogNormalTests.cs

@ -378,6 +378,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
{ {
var n = new LogNormal(mu, sigma); var n = new LogNormal(mu, sigma);
AssertHelpers.AlmostEqual(p, n.Density(x), 14); AssertHelpers.AlmostEqual(p, n.Density(x), 14);
AssertHelpers.AlmostEqual(p, LogNormal.PDF(mu, sigma, x), 14);
} }
/// <summary> /// <summary>
@ -419,6 +420,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
{ {
var n = new LogNormal(mu, sigma); var n = new LogNormal(mu, sigma);
AssertHelpers.AlmostEqual(p, n.DensityLn(x), 14); AssertHelpers.AlmostEqual(p, n.DensityLn(x), 14);
AssertHelpers.AlmostEqual(p, LogNormal.PDFLn(mu, sigma, x), 14);
} }
/// <summary> /// <summary>
@ -518,6 +520,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
{ {
var n = new LogNormal(mu, sigma); var n = new LogNormal(mu, sigma);
AssertHelpers.AlmostEqual(f, n.CumulativeDistribution(x), 8); AssertHelpers.AlmostEqual(f, n.CumulativeDistribution(x), 8);
AssertHelpers.AlmostEqual(f, LogNormal.CDF(mu, sigma, x), 8);
} }
/// <summary> /// <summary>

4
src/UnitTests/DistributionTests/Continuous/NormalTests.cs

@ -368,6 +368,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
var d = (mean - x) / sdev; var d = (mean - x) / sdev;
var pdf = Math.Exp(-0.5 * d * d) / (sdev * Constants.Sqrt2Pi); var pdf = Math.Exp(-0.5 * d * d) / (sdev * Constants.Sqrt2Pi);
Assert.AreEqual(pdf, n.Density(x)); Assert.AreEqual(pdf, n.Density(x));
Assert.AreEqual(pdf, Normal.PDF(mean, sdev, x));
} }
} }
@ -391,6 +392,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
var d = (mean - x) / sdev; var d = (mean - x) / sdev;
var pdfln = (-0.5 * (d * d)) - Math.Log(sdev) - Constants.LogSqrt2Pi; var pdfln = (-0.5 * (d * d)) - Math.Log(sdev) - Constants.LogSqrt2Pi;
Assert.AreEqual(pdfln, n.DensityLn(x)); Assert.AreEqual(pdfln, n.DensityLn(x));
Assert.AreEqual(pdfln, Normal.PDFLn(mean, sdev, x));
} }
} }
@ -471,6 +473,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
{ {
var n = Normal.WithMeanStdDev(5.0, 2.0); var n = Normal.WithMeanStdDev(5.0, 2.0);
AssertHelpers.AlmostEqual(f, n.CumulativeDistribution(x), 10); AssertHelpers.AlmostEqual(f, n.CumulativeDistribution(x), 10);
AssertHelpers.AlmostEqual(f, Normal.CDF(5.0, 2.0, x), 10);
} }
/// <summary> /// <summary>
@ -492,6 +495,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
{ {
var n = Normal.WithMeanStdDev(5.0, 2.0); var n = Normal.WithMeanStdDev(5.0, 2.0);
AssertHelpers.AlmostEqual(x, n.InverseCumulativeDistribution(f), 15); AssertHelpers.AlmostEqual(x, n.InverseCumulativeDistribution(f), 15);
AssertHelpers.AlmostEqual(x, Normal.InvCDF(5.0, 2.0, f), 15);
} }
/// <summary> /// <summary>

Loading…
Cancel
Save