Browse Source

Distributions: more compact code style (no functional changes)

uap-experimental
Christoph Ruegg 7 years ago
parent
commit
e757e0f187
  1. 54
      src/Numerics/Distributions/Bernoulli.cs
  2. 39
      src/Numerics/Distributions/Beta.cs
  3. 49
      src/Numerics/Distributions/BetaScaled.cs
  4. 49
      src/Numerics/Distributions/Binomial.cs
  5. 62
      src/Numerics/Distributions/Burr.cs
  6. 39
      src/Numerics/Distributions/Categorical.cs
  7. 59
      src/Numerics/Distributions/Cauchy.cs
  8. 44
      src/Numerics/Distributions/Chi.cs
  9. 54
      src/Numerics/Distributions/ChiSquared.cs
  10. 59
      src/Numerics/Distributions/ContinuousUniform.cs
  11. 49
      src/Numerics/Distributions/ConwayMaxwellPoisson.cs
  12. 19
      src/Numerics/Distributions/Dirichlet.cs
  13. 59
      src/Numerics/Distributions/DiscreteUniform.cs
  14. 34
      src/Numerics/Distributions/Erlang.cs
  15. 54
      src/Numerics/Distributions/Exponential.cs
  16. 39
      src/Numerics/Distributions/FisherSnedecor.cs
  17. 34
      src/Numerics/Distributions/Gamma.cs
  18. 54
      src/Numerics/Distributions/Geometric.cs
  19. 64
      src/Numerics/Distributions/Hypergeometric.cs
  20. 44
      src/Numerics/Distributions/InverseGamma.cs
  21. 63
      src/Numerics/Distributions/InverseGaussian.cs
  22. 24
      src/Numerics/Distributions/InverseWishart.cs
  23. 59
      src/Numerics/Distributions/Laplace.cs
  24. 44
      src/Numerics/Distributions/LogNormal.cs
  25. 19
      src/Numerics/Distributions/MatrixNormal.cs
  26. 19
      src/Numerics/Distributions/Multinomial.cs
  27. 59
      src/Numerics/Distributions/NegativeBinomial.cs
  28. 54
      src/Numerics/Distributions/Normal.cs
  29. 60
      src/Numerics/Distributions/NormalGamma.cs
  30. 49
      src/Numerics/Distributions/Pareto.cs
  31. 54
      src/Numerics/Distributions/Poisson.cs
  32. 54
      src/Numerics/Distributions/Rayleigh.cs
  33. 34
      src/Numerics/Distributions/Stable.cs
  34. 44
      src/Numerics/Distributions/StudentT.cs
  35. 44
      src/Numerics/Distributions/Triangular.cs
  36. 56
      src/Numerics/Distributions/TruncatedPareto.cs
  37. 49
      src/Numerics/Distributions/Weibull.cs
  38. 24
      src/Numerics/Distributions/Wishart.cs
  39. 44
      src/Numerics/Distributions/Zipf.cs

54
src/Numerics/Distributions/Bernoulli.cs

@ -102,83 +102,56 @@ namespace MathNet.Numerics.Distributions
/// <summary>
/// Gets the probability of generating a one. Range: 0 ≤ p ≤ 1.
/// </summary>
public double P
{
get { return _p; }
}
public double P => _p;
/// <summary>
/// Gets or sets the random number generator which is used to draw random samples.
/// </summary>
public System.Random RandomSource
{
get { return _random; }
set { _random = value ?? SystemRandomSource.Default; }
get => _random;
set => _random = value ?? SystemRandomSource.Default;
}
/// <summary>
/// Gets the mean of the distribution.
/// </summary>
public double Mean
{
get { return _p; }
}
public double Mean => _p;
/// <summary>
/// Gets the standard deviation of the distribution.
/// </summary>
public double StdDev
{
get { return Math.Sqrt(_p*(1.0 - _p)); }
}
public double StdDev => Math.Sqrt(_p*(1.0 - _p));
/// <summary>
/// Gets the variance of the distribution.
/// </summary>
public double Variance
{
get { return _p*(1.0 - _p); }
}
public double Variance => _p*(1.0 - _p);
/// <summary>
/// Gets the entropy of the distribution.
/// </summary>
public double Entropy
{
get { return -(_p*Math.Log(_p)) - ((1.0 - _p)*Math.Log(1.0 - _p)); }
}
public double Entropy => -(_p*Math.Log(_p)) - ((1.0 - _p)*Math.Log(1.0 - _p));
/// <summary>
/// Gets the skewness of the distribution.
/// </summary>
public double Skewness
{
get { return (1.0 - (2.0*_p))/Math.Sqrt(_p*(1.0 - _p)); }
}
public double Skewness => (1.0 - (2.0*_p))/Math.Sqrt(_p*(1.0 - _p));
/// <summary>
/// Gets the smallest element in the domain of the distributions which can be represented by an integer.
/// </summary>
public int Minimum
{
get { return 0; }
}
public int Minimum => 0;
/// <summary>
/// Gets the largest element in the domain of the distributions which can be represented by an integer.
/// </summary>
public int Maximum
{
get { return 1; }
}
public int Maximum => 1;
/// <summary>
/// Gets the mode of the distribution.
/// </summary>
public int Mode
{
get { return _p > 0.5 ? 1 : 0; }
}
public int Mode => _p > 0.5 ? 1 : 0;
/// <summary>
/// Gets all modes of the distribution.
@ -191,10 +164,7 @@ namespace MathNet.Numerics.Distributions
/// <summary>
/// Gets the median of the distribution.
/// </summary>
public double Median
{
get { return _p < 0.5 ? 0.0 : _p > 0.5 ? 1.0 : 0.5; }
}
public double Median => _p < 0.5 ? 0.0 : _p > 0.5 ? 1.0 : 0.5;
/// <summary>
/// Computes the probability mass (PMF) at k, i.e. P(X = k).

39
src/Numerics/Distributions/Beta.cs

@ -113,26 +113,20 @@ namespace MathNet.Numerics.Distributions
/// <summary>
/// Gets the α shape parameter of the Beta distribution. Range: α ≥ 0.
/// </summary>
public double A
{
get { return _shapeA; }
}
public double A => _shapeA;
/// <summary>
/// Gets the β shape parameter of the Beta distribution. Range: β ≥ 0.
/// </summary>
public double B
{
get { return _shapeB; }
}
public double B => _shapeB;
/// <summary>
/// Gets or sets the random number generator which is used to draw random samples.
/// </summary>
public System.Random RandomSource
{
get { return _random; }
set { _random = value ?? SystemRandomSource.Default; }
get => _random;
set => _random = value ?? SystemRandomSource.Default;
}
/// <summary>
@ -179,18 +173,12 @@ namespace MathNet.Numerics.Distributions
/// <summary>
/// Gets the variance of the Beta distribution.
/// </summary>
public double Variance
{
get { return (_shapeA*_shapeB)/((_shapeA + _shapeB)*(_shapeA + _shapeB)*(_shapeA + _shapeB + 1.0)); }
}
public double Variance => (_shapeA*_shapeB)/((_shapeA + _shapeB)*(_shapeA + _shapeB)*(_shapeA + _shapeB + 1.0));
/// <summary>
/// Gets the standard deviation of the Beta distribution.
/// </summary>
public double StdDev
{
get { return Math.Sqrt((_shapeA*_shapeB)/((_shapeA + _shapeB)*(_shapeA + _shapeB)*(_shapeA + _shapeB + 1.0))); }
}
public double StdDev => Math.Sqrt((_shapeA*_shapeB)/((_shapeA + _shapeB)*(_shapeA + _shapeB)*(_shapeA + _shapeB + 1.0)));
/// <summary>
/// Gets the entropy of the Beta distribution.
@ -312,26 +300,17 @@ namespace MathNet.Numerics.Distributions
/// <summary>
/// Gets the median of the Beta distribution.
/// </summary>
public double Median
{
get { throw new NotSupportedException(); }
}
public double Median => throw new NotSupportedException();
/// <summary>
/// Gets the minimum of the Beta distribution.
/// </summary>
public double Minimum
{
get { return 0.0; }
}
public double Minimum => 0.0;
/// <summary>
/// Gets the maximum of the Beta distribution.
/// </summary>
public double Maximum
{
get { return 1.0; }
}
public double Maximum => 1.0;
/// <summary>
/// Computes the probability density of the distribution (PDF) at x, i.e. ∂P(X ≤ x)/∂x.

49
src/Numerics/Distributions/BetaScaled.cs

@ -154,42 +154,30 @@ namespace MathNet.Numerics.Distributions
/// <summary>
/// Gets the α shape parameter of the BetaScaled distribution. Range: α > 0.
/// </summary>
public double A
{
get { return _shapeA; }
}
public double A => _shapeA;
/// <summary>
/// Gets the β shape parameter of the BetaScaled distribution. Range: β > 0.
/// </summary>
public double B
{
get { return _shapeB; }
}
public double B => _shapeB;
/// <summary>
/// Gets the location (μ) of the BetaScaled distribution.
/// </summary>
public double Location
{
get { return _location; }
}
public double Location => _location;
/// <summary>
/// Gets the scale (σ) of the BetaScaled distribution. Range: σ > 0.
/// </summary>
public double Scale
{
get { return _scale; }
}
public double Scale => _scale;
/// <summary>
/// Gets or sets the random number generator which is used to draw random samples.
/// </summary>
public System.Random RandomSource
{
get { return _random; }
set { _random = value ?? SystemRandomSource.Default; }
get => _random;
set => _random = value ?? SystemRandomSource.Default;
}
/// <summary>
@ -233,18 +221,12 @@ namespace MathNet.Numerics.Distributions
/// <summary>
/// Gets the standard deviation of the BetaScaled distribution.
/// </summary>
public double StdDev
{
get { return Math.Sqrt(Variance); }
}
public double StdDev => Math.Sqrt(Variance);
/// <summary>
/// Gets the entropy of the BetaScaled distribution.
/// </summary>
public double Entropy
{
get { throw new NotSupportedException(); }
}
public double Entropy => throw new NotSupportedException();
/// <summary>
/// Gets the skewness of the BetaScaled distribution.
@ -308,26 +290,17 @@ namespace MathNet.Numerics.Distributions
/// <summary>
/// Gets the median of the BetaScaled distribution.
/// </summary>
public double Median
{
get { throw new NotSupportedException(); }
}
public double Median => throw new NotSupportedException();
/// <summary>
/// Gets the minimum of the BetaScaled distribution.
/// </summary>
public double Minimum
{
get { return _location; }
}
public double Minimum => _location;
/// <summary>
/// Gets the maximum of the BetaScaled distribution.
/// </summary>
public double Maximum
{
get { return _location + _scale; }
}
public double Maximum => _location + _scale;
/// <summary>
/// Computes the probability density of the distribution (PDF) at x, i.e. ∂P(X ≤ x)/∂x.

49
src/Numerics/Distributions/Binomial.cs

@ -111,51 +111,36 @@ namespace MathNet.Numerics.Distributions
/// <summary>
/// Gets the success probability in each trial. Range: 0 ≤ p ≤ 1.
/// </summary>
public double P
{
get { return _p; }
}
public double P => _p;
/// <summary>
/// Gets the number of trials. Range: n ≥ 0.
/// </summary>
public int N
{
get { return _trials; }
}
public int N => _trials;
/// <summary>
/// Gets or sets the random number generator which is used to draw random samples.
/// </summary>
public System.Random RandomSource
{
get { return _random; }
set { _random = value ?? SystemRandomSource.Default; }
get => _random;
set => _random = value ?? SystemRandomSource.Default;
}
/// <summary>
/// Gets the mean of the distribution.
/// </summary>
public double Mean
{
get { return _p*_trials; }
}
public double Mean => _p*_trials;
/// <summary>
/// Gets the standard deviation of the distribution.
/// </summary>
public double StdDev
{
get { return Math.Sqrt(_p*(1.0 - _p)*_trials); }
}
public double StdDev => Math.Sqrt(_p*(1.0 - _p)*_trials);
/// <summary>
/// Gets the variance of the distribution.
/// </summary>
public double Variance
{
get { return _p*(1.0 - _p)*_trials; }
}
public double Variance => _p*(1.0 - _p)*_trials;
/// <summary>
/// Gets the entropy of the distribution.
@ -183,26 +168,17 @@ namespace MathNet.Numerics.Distributions
/// <summary>
/// Gets the skewness of the distribution.
/// </summary>
public double Skewness
{
get { return (1.0 - (2.0*_p))/Math.Sqrt(_trials*_p*(1.0 - _p)); }
}
public double Skewness => (1.0 - (2.0*_p))/Math.Sqrt(_trials*_p*(1.0 - _p));
/// <summary>
/// Gets the smallest element in the domain of the distributions which can be represented by an integer.
/// </summary>
public int Minimum
{
get { return 0; }
}
public int Minimum => 0;
/// <summary>
/// Gets the largest element in the domain of the distributions which can be represented by an integer.
/// </summary>
public int Maximum
{
get { return _trials; }
}
public int Maximum => _trials;
/// <summary>
/// Gets the mode of the distribution.
@ -251,10 +227,7 @@ namespace MathNet.Numerics.Distributions
/// <summary>
/// Gets the median of the distribution.
/// </summary>
public double Median
{
get { return Math.Floor(_p*_trials); }
}
public double Median => Math.Floor(_p*_trials);
/// <summary>
/// Computes the probability mass (PMF) at k, i.e. P(X = k).

62
src/Numerics/Distributions/Burr.cs

@ -98,78 +98,46 @@ namespace MathNet.Numerics.Distributions
/// </summary>
public System.Random RandomSource
{
get { return _random; }
set { _random = value ?? SystemRandomSource.Default; }
get => _random;
set => _random = value ?? SystemRandomSource.Default;
}
/// <summary>
/// Gets the mean of the Burr distribution.
/// </summary>
public double Mean
{
get
{
return (1 / SpecialFunctions.Gamma(k)) * a * SpecialFunctions.Gamma(1 + 1 / c) * SpecialFunctions.Gamma(k - 1 / c);
}
}
public double Mean => (1 / SpecialFunctions.Gamma(k)) * a * SpecialFunctions.Gamma(1 + 1 / c) * SpecialFunctions.Gamma(k - 1 / c);
/// <summary>
/// Gets the variance of the Burr distribution.
/// </summary>
public double Variance
{
get
{
return (1 / SpecialFunctions.Gamma(k)) * Math.Pow(a, 2) * SpecialFunctions.Gamma(1 + 2 / c) * SpecialFunctions.Gamma(k - 2 / c)
- Math.Pow((1 / SpecialFunctions.Gamma(k)) * a * SpecialFunctions.Gamma(1 + 1 / c) * SpecialFunctions.Gamma(k - 1 / c), 2);
}
}
public double Variance =>
(1 / SpecialFunctions.Gamma(k)) * Math.Pow(a, 2) * SpecialFunctions.Gamma(1 + 2 / c) * SpecialFunctions.Gamma(k - 2 / c)
- Math.Pow((1 / SpecialFunctions.Gamma(k)) * a * SpecialFunctions.Gamma(1 + 1 / c) * SpecialFunctions.Gamma(k - 1 / c), 2);
/// <summary>
/// Gets the standard deviation of the Burr distribution.
/// </summary>
public double StdDev
{
get
{
return Math.Sqrt(Variance);
}
}
public double StdDev => Math.Sqrt(Variance);
/// <summary>
/// Gets the mode of the Burr distribution.
/// </summary>
public double Mode
{
get
{
return a * Math.Pow((c - 1) / (c * k + 1), 1 / c);
}
}
public double Mode => a * Math.Pow((c - 1) / (c * k + 1), 1 / c);
/// <summary>
/// Gets the minimum of the Burr distribution.
/// </summary>
public double Minimum
{
get { return 0.0; }
}
public double Minimum => 0.0;
/// <summary>
/// Gets the maximum of the Burr distribution.
/// </summary>
public double Maximum
{
get { return double.PositiveInfinity; }
}
public double Maximum => double.PositiveInfinity;
/// <summary>
/// Gets the entropy of the Burr distribution (currently not supported).
/// </summary>
public double Entropy
{
get { throw new NotSupportedException(); }
}
public double Entropy => throw new NotSupportedException();
/// <summary>
/// Gets the skewness of the Burr distribution.
@ -188,13 +156,7 @@ namespace MathNet.Numerics.Distributions
/// <summary>
/// Gets the median of the Burr distribution.
/// </summary>
public double Median
{
get
{
return a * Math.Pow(Math.Pow(2, 1 / k) - 1, 1 / c);
}
}
public double Median => a * Math.Pow(Math.Pow(2, 1 / k) - 1, 1 / c);
/// <summary>
/// Generates a sample from the Burr distribution.

39
src/Numerics/Distributions/Categorical.cs

@ -205,18 +205,15 @@ namespace MathNet.Numerics.Distributions
/// Gets the probability mass vector (non-negative ratios) of the multinomial.
/// </summary>
/// <remarks>Sometimes the normalized probability vector cannot be represented exactly in a floating point representation.</remarks>
public double[] P
{
get { return (double[])_pmfNormalized.Clone(); }
}
public double[] P => (double[])_pmfNormalized.Clone();
/// <summary>
/// Gets or sets the random number generator which is used to draw random samples.
/// </summary>
public System.Random RandomSource
{
get { return _random; }
set { _random = value ?? SystemRandomSource.Default; }
get => _random;
set => _random = value ?? SystemRandomSource.Default;
}
/// <summary>
@ -241,10 +238,7 @@ namespace MathNet.Numerics.Distributions
/// <summary>
/// Gets the standard deviation of the distribution.
/// </summary>
public double StdDev
{
get { return Math.Sqrt(Variance); }
}
public double StdDev => Math.Sqrt(Variance);
/// <summary>
/// Gets the variance of the distribution.
@ -278,43 +272,28 @@ namespace MathNet.Numerics.Distributions
/// Gets the skewness of the distribution.
/// </summary>
/// <remarks>Throws a <see cref="NotSupportedException"/>.</remarks>
public double Skewness
{
get { throw new NotSupportedException(); }
}
public double Skewness => throw new NotSupportedException();
/// <summary>
/// Gets the smallest element in the domain of the distributions which can be represented by an integer.
/// </summary>
public int Minimum
{
get { return 0; }
}
public int Minimum => 0;
/// <summary>
/// Gets the largest element in the domain of the distributions which can be represented by an integer.
/// </summary>
public int Maximum
{
get { return _pmfNormalized.Length - 1; }
}
public int Maximum => _pmfNormalized.Length - 1;
/// <summary>
/// Gets he mode of the distribution.
/// </summary>
/// <remarks>Throws a <see cref="NotSupportedException"/>.</remarks>
public int Mode
{
get { throw new NotSupportedException(); }
}
public int Mode => throw new NotSupportedException();
/// <summary>
/// Gets the median of the distribution.
/// </summary>
public double Median
{
get { return InverseCumulativeDistribution(0.5); }
}
public double Median => InverseCumulativeDistribution(0.5);
/// <summary>
/// Computes the probability mass (PMF) at k, i.e. P(X = k).

59
src/Numerics/Distributions/Cauchy.cs

@ -111,99 +111,66 @@ namespace MathNet.Numerics.Distributions
/// <summary>
/// Gets the location (x0) of the distribution.
/// </summary>
public double Location
{
get { return _location; }
}
public double Location => _location;
/// <summary>
/// Gets the scale (γ) of the distribution. Range: γ > 0.
/// </summary>
public double Scale
{
get { return _scale; }
}
public double Scale => _scale;
/// <summary>
/// Gets or sets the random number generator which is used to draw random samples.
/// </summary>
public System.Random RandomSource
{
get { return _random; }
set { _random = value ?? SystemRandomSource.Default; }
get => _random;
set => _random = value ?? SystemRandomSource.Default;
}
/// <summary>
/// Gets the mean of the distribution.
/// </summary>
public double Mean
{
get { throw new NotSupportedException(); }
}
public double Mean => throw new NotSupportedException();
/// <summary>
/// Gets the variance of the distribution.
/// </summary>
public double Variance
{
get { throw new NotSupportedException(); }
}
public double Variance => throw new NotSupportedException();
/// <summary>
/// Gets the standard deviation of the distribution.
/// </summary>
public double StdDev
{
get { throw new NotSupportedException(); }
}
public double StdDev => throw new NotSupportedException();
/// <summary>
/// Gets the entropy of the distribution.
/// </summary>
public double Entropy
{
get { return Math.Log(4.0*Constants.Pi*_scale); }
}
public double Entropy => Math.Log(4.0*Constants.Pi*_scale);
/// <summary>
/// Gets the skewness of the distribution.
/// </summary>
public double Skewness
{
get { throw new NotSupportedException(); }
}
public double Skewness => throw new NotSupportedException();
/// <summary>
/// Gets the mode of the distribution.
/// </summary>
public double Mode
{
get { return _location; }
}
public double Mode => _location;
/// <summary>
/// Gets the median of the distribution.
/// </summary>
public double Median
{
get { return _location; }
}
public double Median => _location;
/// <summary>
/// Gets the minimum of the distribution.
/// </summary>
public double Minimum
{
get { return double.NegativeInfinity; }
}
public double Minimum => double.NegativeInfinity;
/// <summary>
/// Gets the maximum of the distribution.
/// </summary>
public double Maximum
{
get { return double.PositiveInfinity; }
}
public double Maximum => double.PositiveInfinity;
/// <summary>
/// Computes the probability density of the distribution (PDF) at x, i.e. ∂P(X ≤ x)/∂x.

44
src/Numerics/Distributions/Chi.cs

@ -100,51 +100,36 @@ namespace MathNet.Numerics.Distributions
/// <summary>
/// Gets the degrees of freedom (k) of the Chi distribution. Range: k > 0.
/// </summary>
public double DegreesOfFreedom
{
get { return _freedom; }
}
public double DegreesOfFreedom => _freedom;
/// <summary>
/// Gets or sets the random number generator which is used to draw random samples.
/// </summary>
public System.Random RandomSource
{
get { return _random; }
set { _random = value ?? SystemRandomSource.Default; }
get => _random;
set => _random = value ?? SystemRandomSource.Default;
}
/// <summary>
/// Gets the mean of the distribution.
/// </summary>
public double Mean
{
get { return Constants.Sqrt2*(SpecialFunctions.Gamma((_freedom + 1.0)/2.0)/SpecialFunctions.Gamma(_freedom/2.0)); }
}
public double Mean => Constants.Sqrt2*(SpecialFunctions.Gamma((_freedom + 1.0)/2.0)/SpecialFunctions.Gamma(_freedom/2.0));
/// <summary>
/// Gets the variance of the distribution.
/// </summary>
public double Variance
{
get { return _freedom - (Mean*Mean); }
}
public double Variance => _freedom - (Mean*Mean);
/// <summary>
/// Gets the standard deviation of the distribution.
/// </summary>
public double StdDev
{
get { return Math.Sqrt(Variance); }
}
public double StdDev => Math.Sqrt(Variance);
/// <summary>
/// Gets the entropy of the distribution.
/// </summary>
public double Entropy
{
get { return SpecialFunctions.GammaLn(_freedom/2.0) + ((_freedom - Math.Log(2) - ((_freedom - 1.0)*SpecialFunctions.DiGamma(_freedom/2.0)))/2.0); }
}
public double Entropy => SpecialFunctions.GammaLn(_freedom/2.0) + ((_freedom - Math.Log(2) - ((_freedom - 1.0)*SpecialFunctions.DiGamma(_freedom/2.0)))/2.0);
/// <summary>
/// Gets the skewness of the distribution.
@ -177,26 +162,17 @@ namespace MathNet.Numerics.Distributions
/// <summary>
/// Gets the median of the distribution.
/// </summary>
public double Median
{
get { throw new NotSupportedException(); }
}
public double Median => throw new NotSupportedException();
/// <summary>
/// Gets the minimum of the distribution.
/// </summary>
public double Minimum
{
get { return 0.0; }
}
public double Minimum => 0.0;
/// <summary>
/// Gets the maximum of the distribution.
/// </summary>
public double Maximum
{
get { return double.PositiveInfinity; }
}
public double Maximum => double.PositiveInfinity;
/// <summary>
/// Computes the probability density of the distribution (PDF) at x, i.e. ∂P(X ≤ x)/∂x.

54
src/Numerics/Distributions/ChiSquared.cs

@ -98,91 +98,61 @@ namespace MathNet.Numerics.Distributions
/// <summary>
/// Gets the degrees of freedom (k) of the Chi-Squared distribution. Range: k > 0.
/// </summary>
public double DegreesOfFreedom
{
get { return _freedom; }
}
public double DegreesOfFreedom => _freedom;
/// <summary>
/// Gets or sets the random number generator which is used to draw random samples.
/// </summary>
public System.Random RandomSource
{
get { return _random; }
set { _random = value ?? SystemRandomSource.Default; }
get => _random;
set => _random = value ?? SystemRandomSource.Default;
}
/// <summary>
/// Gets the mean of the distribution.
/// </summary>
public double Mean
{
get { return _freedom; }
}
public double Mean => _freedom;
/// <summary>
/// Gets the variance of the distribution.
/// </summary>
public double Variance
{
get { return 2.0*_freedom; }
}
public double Variance => 2.0*_freedom;
/// <summary>
/// Gets the standard deviation of the distribution.
/// </summary>
public double StdDev
{
get { return Math.Sqrt(2.0*_freedom); }
}
public double StdDev => Math.Sqrt(2.0*_freedom);
/// <summary>
/// Gets the entropy of the distribution.
/// </summary>
public double Entropy
{
get { return (_freedom/2.0) + Math.Log(2.0*SpecialFunctions.Gamma(_freedom/2.0)) + ((1.0 - (_freedom/2.0))*SpecialFunctions.DiGamma(_freedom/2.0)); }
}
public double Entropy => (_freedom/2.0) + Math.Log(2.0*SpecialFunctions.Gamma(_freedom/2.0)) + ((1.0 - (_freedom/2.0))*SpecialFunctions.DiGamma(_freedom/2.0));
/// <summary>
/// Gets the skewness of the distribution.
/// </summary>
public double Skewness
{
get { return Math.Sqrt(8.0/_freedom); }
}
public double Skewness => Math.Sqrt(8.0/_freedom);
/// <summary>
/// Gets the mode of the distribution.
/// </summary>
public double Mode
{
get { return _freedom - 2.0; }
}
public double Mode => _freedom - 2.0;
/// <summary>
/// Gets the median of the distribution.
/// </summary>
public double Median
{
get { return _freedom - (2.0/3.0); }
}
public double Median => _freedom - (2.0/3.0);
/// <summary>
/// Gets the minimum of the distribution.
/// </summary>
public double Minimum
{
get { return 0.0; }
}
public double Minimum => 0.0;
/// <summary>
/// Gets the maximum of the distribution.
/// </summary>
public double Maximum
{
get { return double.PositiveInfinity; }
}
public double Maximum => double.PositiveInfinity;
/// <summary>
/// Computes the probability density of the distribution (PDF) at x, i.e. ∂P(X ≤ x)/∂x.

59
src/Numerics/Distributions/ContinuousUniform.cs

@ -113,102 +113,69 @@ namespace MathNet.Numerics.Distributions
/// <summary>
/// Gets the lower bound of the distribution.
/// </summary>
public double LowerBound
{
get { return _lower; }
}
public double LowerBound => _lower;
/// <summary>
/// Gets the upper bound of the distribution.
/// </summary>
public double UpperBound
{
get { return _upper; }
}
public double UpperBound => _upper;
/// <summary>
/// Gets or sets the random number generator which is used to draw random samples.
/// </summary>
public System.Random RandomSource
{
get { return _random; }
set { _random = value ?? SystemRandomSource.Default; }
get => _random;
set => _random = value ?? SystemRandomSource.Default;
}
/// <summary>
/// Gets the mean of the distribution.
/// </summary>
public double Mean
{
get { return (_lower + _upper)/2.0; }
}
public double Mean => (_lower + _upper)/2.0;
/// <summary>
/// Gets the variance of the distribution.
/// </summary>
public double Variance
{
get { return (_upper - _lower)*(_upper - _lower)/12.0; }
}
public double Variance => (_upper - _lower)*(_upper - _lower)/12.0;
/// <summary>
/// Gets the standard deviation of the distribution.
/// </summary>
public double StdDev
{
get { return (_upper - _lower)/Math.Sqrt(12.0); }
}
public double StdDev => (_upper - _lower)/Math.Sqrt(12.0);
/// <summary>
/// Gets the entropy of the distribution.
/// </summary>
/// <value></value>
public double Entropy
{
get { return Math.Log(_upper - _lower); }
}
public double Entropy => Math.Log(_upper - _lower);
/// <summary>
/// Gets the skewness of the distribution.
/// </summary>
public double Skewness
{
get { return 0.0; }
}
public double Skewness => 0.0;
/// <summary>
/// Gets the mode of the distribution.
/// </summary>
/// <value></value>
public double Mode
{
get { return (_lower + _upper)/2.0; }
}
public double Mode => (_lower + _upper)/2.0;
/// <summary>
/// Gets the median of the distribution.
/// </summary>
/// <value></value>
public double Median
{
get { return (_lower + _upper)/2.0; }
}
public double Median => (_lower + _upper)/2.0;
/// <summary>
/// Gets the minimum of the distribution.
/// </summary>
public double Minimum
{
get { return _lower; }
}
public double Minimum => _lower;
/// <summary>
/// Gets the maximum of the distribution.
/// </summary>
public double Maximum
{
get { return _upper; }
}
public double Maximum => _upper;
/// <summary>
/// Computes the probability density of the distribution (PDF) at x, i.e. ∂P(X ≤ x)/∂x.

49
src/Numerics/Distributions/ConwayMaxwellPoisson.cs

@ -132,26 +132,20 @@ namespace MathNet.Numerics.Distributions
/// <summary>
/// Gets the lambda (λ) parameter. Range: λ > 0.
/// </summary>
public double Lambda
{
get { return _lambda; }
}
public double Lambda => _lambda;
/// <summary>
/// Gets the rate of decay (ν) parameter. Range: ν ≥ 0.
/// </summary>
public double Nu
{
get { return _nu; }
}
public double Nu => _nu;
/// <summary>
/// Gets or sets the random number generator which is used to draw random samples.
/// </summary>
public System.Random RandomSource
{
get { return _random; }
set { _random = value ?? SystemRandomSource.Default; }
get => _random;
set => _random = value ?? SystemRandomSource.Default;
}
/// <summary>
@ -280,58 +274,37 @@ namespace MathNet.Numerics.Distributions
/// <summary>
/// Gets the standard deviation of the distribution.
/// </summary>
public double StdDev
{
get { return Math.Sqrt(Variance); }
}
public double StdDev => Math.Sqrt(Variance);
/// <summary>
/// Gets the entropy of the distribution.
/// </summary>
public double Entropy
{
get { throw new NotSupportedException(); }
}
public double Entropy => throw new NotSupportedException();
/// <summary>
/// Gets the skewness of the distribution.
/// </summary>
public double Skewness
{
get { throw new NotSupportedException(); }
}
public double Skewness => throw new NotSupportedException();
/// <summary>
/// Gets the mode of the distribution
/// </summary>
public int Mode
{
get { throw new NotSupportedException(); }
}
public int Mode => throw new NotSupportedException();
/// <summary>
/// Gets the median of the distribution.
/// </summary>
public double Median
{
get { throw new NotSupportedException(); }
}
public double Median => throw new NotSupportedException();
/// <summary>
/// Gets the smallest element in the domain of the distributions which can be represented by an integer.
/// </summary>
public int Minimum
{
get { return 0; }
}
public int Minimum => 0;
/// <summary>
/// Gets the largest element in the domain of the distributions which can be represented by an integer.
/// </summary>
public int Maximum
{
get { throw new NotSupportedException(); }
}
public int Maximum => throw new NotSupportedException();
/// <summary>
/// Computes the probability mass (PMF) at k, i.e. P(X = k).

19
src/Numerics/Distributions/Dirichlet.cs

@ -164,35 +164,26 @@ namespace MathNet.Numerics.Distributions
/// <summary>
/// Gets or sets the parameters of the Dirichlet distribution.
/// </summary>
public double[] Alpha
{
get { return _alpha; }
}
public double[] Alpha => _alpha;
/// <summary>
/// Gets or sets the random number generator which is used to draw random samples.
/// </summary>
public System.Random RandomSource
{
get { return _random; }
set { _random = value ?? SystemRandomSource.Default; }
get => _random;
set => _random = value ?? SystemRandomSource.Default;
}
/// <summary>
/// Gets the dimension of the Dirichlet distribution.
/// </summary>
public int Dimension
{
get { return _alpha.Length; }
}
public int Dimension => _alpha.Length;
/// <summary>
/// Gets the sum of the Dirichlet parameters.
/// </summary>
double AlphaSum
{
get { return _alpha.Sum(); }
}
double AlphaSum => _alpha.Sum();
/// <summary>
/// Gets the mean of the Dirichlet distribution.

59
src/Numerics/Distributions/DiscreteUniform.cs

@ -106,99 +106,66 @@ namespace MathNet.Numerics.Distributions
/// <summary>
/// Gets the inclusive lower bound of the probability distribution.
/// </summary>
public int LowerBound
{
get { return _lower; }
}
public int LowerBound => _lower;
/// <summary>
/// Gets the inclusive upper bound of the probability distribution.
/// </summary>
public int UpperBound
{
get { return _upper; }
}
public int UpperBound => _upper;
/// <summary>
/// Gets or sets the random number generator which is used to draw random samples.
/// </summary>
public System.Random RandomSource
{
get { return _random; }
set { _random = value ?? SystemRandomSource.Default; }
get => _random;
set => _random = value ?? SystemRandomSource.Default;
}
/// <summary>
/// Gets the mean of the distribution.
/// </summary>
public double Mean
{
get { return (_lower + _upper)/2.0; }
}
public double Mean => (_lower + _upper)/2.0;
/// <summary>
/// Gets the standard deviation of the distribution.
/// </summary>
public double StdDev
{
get { return Math.Sqrt((((_upper - _lower + 1.0)*(_upper - _lower + 1.0)) - 1.0)/12.0); }
}
public double StdDev => Math.Sqrt((((_upper - _lower + 1.0)*(_upper - _lower + 1.0)) - 1.0)/12.0);
/// <summary>
/// Gets the variance of the distribution.
/// </summary>
public double Variance
{
get { return (((_upper - _lower + 1.0)*(_upper - _lower + 1.0)) - 1.0)/12.0; }
}
public double Variance => (((_upper - _lower + 1.0)*(_upper - _lower + 1.0)) - 1.0)/12.0;
/// <summary>
/// Gets the entropy of the distribution.
/// </summary>
public double Entropy
{
get { return Math.Log(_upper - _lower + 1.0); }
}
public double Entropy => Math.Log(_upper - _lower + 1.0);
/// <summary>
/// Gets the skewness of the distribution.
/// </summary>
public double Skewness
{
get { return 0.0; }
}
public double Skewness => 0.0;
/// <summary>
/// Gets the smallest element in the domain of the distributions which can be represented by an integer.
/// </summary>
public int Minimum
{
get { return _lower; }
}
public int Minimum => _lower;
/// <summary>
/// Gets the largest element in the domain of the distributions which can be represented by an integer.
/// </summary>
public int Maximum
{
get { return _upper; }
}
public int Maximum => _upper;
/// <summary>
/// Gets the mode of the distribution; since every element in the domain has the same probability this method returns the middle one.
/// </summary>
public int Mode
{
get { return (int)Math.Floor((_lower + _upper)/2.0); }
}
public int Mode => (int)Math.Floor((_lower + _upper)/2.0);
/// <summary>
/// Gets the median of the distribution.
/// </summary>
public double Median
{
get { return (_lower + _upper)/2.0; }
}
public double Median => (_lower + _upper)/2.0;
/// <summary>
/// Computes the probability mass (PMF) at k, i.e. P(X = k).

34
src/Numerics/Distributions/Erlang.cs

@ -128,34 +128,25 @@ namespace MathNet.Numerics.Distributions
/// <summary>
/// Gets the shape (k) of the Erlang distribution. Range: k ≥ 0.
/// </summary>
public int Shape
{
get { return _shape; }
}
public int Shape => _shape;
/// <summary>
/// Gets the rate or inverse scale (λ) of the Erlang distribution. Range: λ ≥ 0.
/// </summary>
public double Rate
{
get { return _rate; }
}
public double Rate => _rate;
/// <summary>
/// Gets the scale of the Erlang distribution.
/// </summary>
public double Scale
{
get { return 1.0/_rate; }
}
public double Scale => 1.0/_rate;
/// <summary>
/// Gets or sets the random number generator which is used to draw random samples.
/// </summary>
public System.Random RandomSource
{
get { return _random; }
set { _random = value ?? SystemRandomSource.Default; }
get => _random;
set => _random = value ?? SystemRandomSource.Default;
}
/// <summary>
@ -292,26 +283,17 @@ namespace MathNet.Numerics.Distributions
/// <summary>
/// Gets the median of the distribution.
/// </summary>
public double Median
{
get { throw new NotSupportedException(); }
}
public double Median => throw new NotSupportedException();
/// <summary>
/// Gets the minimum value.
/// </summary>
public double Minimum
{
get { return 0.0; }
}
public double Minimum => 0.0;
/// <summary>
/// Gets the Maximum value.
/// </summary>
public double Maximum
{
get { return double.PositiveInfinity; }
}
public double Maximum => double.PositiveInfinity;
/// <summary>
/// Computes the probability density of the distribution (PDF) at x, i.e. ∂P(X ≤ x)/∂x.

54
src/Numerics/Distributions/Exponential.cs

@ -99,91 +99,61 @@ namespace MathNet.Numerics.Distributions
/// <summary>
/// Gets the rate (λ) parameter of the distribution. Range: λ ≥ 0.
/// </summary>
public double Rate
{
get { return _rate; }
}
public double Rate => _rate;
/// <summary>
/// Gets or sets the random number generator which is used to draw random samples.
/// </summary>
public System.Random RandomSource
{
get { return _random; }
set { _random = value ?? SystemRandomSource.Default; }
get => _random;
set => _random = value ?? SystemRandomSource.Default;
}
/// <summary>
/// Gets the mean of the distribution.
/// </summary>
public double Mean
{
get { return 1.0/_rate; }
}
public double Mean => 1.0/_rate;
/// <summary>
/// Gets the variance of the distribution.
/// </summary>
public double Variance
{
get { return 1.0/(_rate*_rate); }
}
public double Variance => 1.0/(_rate*_rate);
/// <summary>
/// Gets the standard deviation of the distribution.
/// </summary>
public double StdDev
{
get { return 1.0/_rate; }
}
public double StdDev => 1.0/_rate;
/// <summary>
/// Gets the entropy of the distribution.
/// </summary>
public double Entropy
{
get { return 1.0 - Math.Log(_rate); }
}
public double Entropy => 1.0 - Math.Log(_rate);
/// <summary>
/// Gets the skewness of the distribution.
/// </summary>
public double Skewness
{
get { return 2.0; }
}
public double Skewness => 2.0;
/// <summary>
/// Gets the mode of the distribution.
/// </summary>
public double Mode
{
get { return 0.0; }
}
public double Mode => 0.0;
/// <summary>
/// Gets the median of the distribution.
/// </summary>
public double Median
{
get { return Math.Log(2.0)/_rate; }
}
public double Median => Math.Log(2.0)/_rate;
/// <summary>
/// Gets the minimum of the distribution.
/// </summary>
public double Minimum
{
get { return 0.0; }
}
public double Minimum => 0.0;
/// <summary>
/// Gets the maximum of the distribution.
/// </summary>
public double Maximum
{
get { return double.PositiveInfinity; }
}
public double Maximum => double.PositiveInfinity;
/// <summary>
/// Computes the probability density of the distribution (PDF) at x, i.e. ∂P(X ≤ x)/∂x.

39
src/Numerics/Distributions/FisherSnedecor.cs

@ -105,26 +105,20 @@ namespace MathNet.Numerics.Distributions
/// <summary>
/// Gets the first degree of freedom (d1) of the distribution. Range: d1 > 0.
/// </summary>
public double DegreesOfFreedom1
{
get { return _freedom1; }
}
public double DegreesOfFreedom1 => _freedom1;
/// <summary>
/// Gets the second degree of freedom (d2) of the distribution. Range: d2 > 0.
/// </summary>
public double DegreesOfFreedom2
{
get { return _freedom2; }
}
public double DegreesOfFreedom2 => _freedom2;
/// <summary>
/// Gets or sets the random number generator which is used to draw random samples.
/// </summary>
public System.Random RandomSource
{
get { return _random; }
set { _random = value ?? SystemRandomSource.Default; }
get => _random;
set => _random = value ?? SystemRandomSource.Default;
}
/// <summary>
@ -162,18 +156,12 @@ namespace MathNet.Numerics.Distributions
/// <summary>
/// Gets the standard deviation of the distribution.
/// </summary>
public double StdDev
{
get { return Math.Sqrt(Variance); }
}
public double StdDev => Math.Sqrt(Variance);
/// <summary>
/// Gets the entropy of the distribution.
/// </summary>
public double Entropy
{
get { throw new NotSupportedException(); }
}
public double Entropy => throw new NotSupportedException();
/// <summary>
/// Gets the skewness of the distribution.
@ -210,26 +198,17 @@ namespace MathNet.Numerics.Distributions
/// <summary>
/// Gets the median of the distribution.
/// </summary>
public double Median
{
get { throw new NotSupportedException(); }
}
public double Median => throw new NotSupportedException();
/// <summary>
/// Gets the minimum of the distribution.
/// </summary>
public double Minimum
{
get { return 0.0; }
}
public double Minimum => 0.0;
/// <summary>
/// Gets the maximum of the distribution.
/// </summary>
public double Maximum
{
get { return double.PositiveInfinity; }
}
public double Maximum => double.PositiveInfinity;
/// <summary>
/// Computes the probability density of the distribution (PDF) at x, i.e. ∂P(X ≤ x)/∂x.

34
src/Numerics/Distributions/Gamma.cs

@ -137,34 +137,25 @@ namespace MathNet.Numerics.Distributions
/// <summary>
/// Gets or sets the shape (k, α) of the Gamma distribution. Range: α ≥ 0.
/// </summary>
public double Shape
{
get { return _shape; }
}
public double Shape => _shape;
/// <summary>
/// Gets or sets the rate or inverse scale (β) of the Gamma distribution. Range: β ≥ 0.
/// </summary>
public double Rate
{
get { return _rate; }
}
public double Rate => _rate;
/// <summary>
/// Gets or sets the scale (θ) of the Gamma distribution.
/// </summary>
public double Scale
{
get { return 1.0/_rate; }
}
public double Scale => 1.0/_rate;
/// <summary>
/// Gets or sets the random number generator which is used to draw random samples.
/// </summary>
public System.Random RandomSource
{
get { return _random; }
set { _random = value ?? SystemRandomSource.Default; }
get => _random;
set => _random = value ?? SystemRandomSource.Default;
}
/// <summary>
@ -296,26 +287,17 @@ namespace MathNet.Numerics.Distributions
/// <summary>
/// Gets the median of the Gamma distribution.
/// </summary>
public double Median
{
get { throw new NotSupportedException(); }
}
public double Median => throw new NotSupportedException();
/// <summary>
/// Gets the minimum of the Gamma distribution.
/// </summary>
public double Minimum
{
get { return 0.0; }
}
public double Minimum => 0.0;
/// <summary>
/// Gets the maximum of the Gamma distribution.
/// </summary>
public double Maximum
{
get { return double.PositiveInfinity; }
}
public double Maximum => double.PositiveInfinity;
/// <summary>
/// Computes the probability density of the distribution (PDF) at x, i.e. ∂P(X ≤ x)/∂x.

54
src/Numerics/Distributions/Geometric.cs

@ -100,92 +100,62 @@ namespace MathNet.Numerics.Distributions
/// <summary>
/// Gets the probability of generating a one. Range: 0 ≤ p ≤ 1.
/// </summary>
public double P
{
get { return _p; }
}
public double P => _p;
/// <summary>
/// Gets or sets the random number generator which is used to draw random samples.
/// </summary>
public System.Random RandomSource
{
get { return _random; }
set { _random = value ?? SystemRandomSource.Default; }
get => _random;
set => _random = value ?? SystemRandomSource.Default;
}
/// <summary>
/// Gets the mean of the distribution.
/// </summary>
public double Mean
{
get { return 1.0/_p; }
}
public double Mean => 1.0/_p;
/// <summary>
/// Gets the variance of the distribution.
/// </summary>
public double Variance
{
get { return (1.0 - _p)/(_p*_p); }
}
public double Variance => (1.0 - _p)/(_p*_p);
/// <summary>
/// Gets the standard deviation of the distribution.
/// </summary>
public double StdDev
{
get { return Math.Sqrt(1.0 - _p)/_p; }
}
public double StdDev => Math.Sqrt(1.0 - _p)/_p;
/// <summary>
/// Gets the entropy of the distribution.
/// </summary>
public double Entropy
{
get { return ((-_p*Math.Log(_p, 2.0)) - ((1.0 - _p)*Math.Log(1.0 - _p, 2.0)))/_p; }
}
public double Entropy => ((-_p*Math.Log(_p, 2.0)) - ((1.0 - _p)*Math.Log(1.0 - _p, 2.0)))/_p;
/// <summary>
/// Gets the skewness of the distribution.
/// </summary>
/// <remarks>Throws a not supported exception.</remarks>
public double Skewness
{
get { return (2.0 - _p)/Math.Sqrt(1.0 - _p); }
}
public double Skewness => (2.0 - _p)/Math.Sqrt(1.0 - _p);
/// <summary>
/// Gets the mode of the distribution.
/// </summary>
public int Mode
{
get { return 1; }
}
public int Mode => 1;
/// <summary>
/// Gets the median of the distribution.
/// </summary>
public double Median
{
get { return _p == 0.0 ? double.PositiveInfinity : _p == 1.0 ? 1.0 : Math.Ceiling(-Constants.Ln2/Math.Log(1 - _p)); }
}
public double Median => _p == 0.0 ? double.PositiveInfinity : _p == 1.0 ? 1.0 : Math.Ceiling(-Constants.Ln2/Math.Log(1 - _p));
/// <summary>
/// Gets the smallest element in the domain of the distributions which can be represented by an integer.
/// </summary>
public int Minimum
{
get { return 1; }
}
public int Minimum => 1;
/// <summary>
/// Gets the largest element in the domain of the distributions which can be represented by an integer.
/// </summary>
public int Maximum
{
get { return int.MaxValue; }
}
public int Maximum => int.MaxValue;
/// <summary>
/// Computes the probability mass (PMF) at k, i.e. P(X = k).

64
src/Numerics/Distributions/Hypergeometric.cs

@ -115,105 +115,69 @@ namespace MathNet.Numerics.Distributions
/// </summary>
public System.Random RandomSource
{
get { return _random; }
set { _random = value ?? SystemRandomSource.Default; }
get => _random;
set => _random = value ?? SystemRandomSource.Default;
}
/// <summary>
/// Gets the size of the population (N).
/// </summary>
public int Population
{
get { return _population; }
}
public int Population => _population;
/// <summary>
/// Gets the number of draws without replacement (n).
/// </summary>
public int Draws
{
get { return _draws; }
}
public int Draws => _draws;
/// <summary>
/// Gets the number successes within the population (K, M).
/// </summary>
public int Success
{
get { return _success; }
}
public int Success => _success;
/// <summary>
/// Gets the mean of the distribution.
/// </summary>
public double Mean
{
get { return (double)_success*_draws/_population; }
}
public double Mean => (double)_success*_draws/_population;
/// <summary>
/// Gets the variance of the distribution.
/// </summary>
public double Variance
{
get { return _draws*_success*(_population - _draws)*(_population - _success)/(_population*_population*(_population - 1.0)); }
}
public double Variance => _draws*_success*(_population - _draws)*(_population - _success)/(_population*_population*(_population - 1.0));
/// <summary>
/// Gets the standard deviation of the distribution.
/// </summary>
public double StdDev
{
get { return Math.Sqrt(Variance); }
}
public double StdDev => Math.Sqrt(Variance);
/// <summary>
/// Gets the entropy of the distribution.
/// </summary>
public double Entropy
{
get { throw new NotSupportedException(); }
}
public double Entropy => throw new NotSupportedException();
/// <summary>
/// Gets the skewness of the distribution.
/// </summary>
public double Skewness
{
get { return (Math.Sqrt(_population - 1.0)*(_population - (2*_draws))*(_population - (2*_success)))/(Math.Sqrt(_draws*_success*(_population - _success)*(_population - _draws))*(_population - 2.0)); }
}
public double Skewness => (Math.Sqrt(_population - 1.0)*(_population - (2*_draws))*(_population - (2*_success)))/(Math.Sqrt(_draws*_success*(_population - _success)*(_population - _draws))*(_population - 2.0));
/// <summary>
/// Gets the mode of the distribution.
/// </summary>
public int Mode
{
get { return (_draws + 1)*(_success + 1)/(_population + 2); }
}
public int Mode => (_draws + 1)*(_success + 1)/(_population + 2);
/// <summary>
/// Gets the median of the distribution.
/// </summary>
public double Median
{
get { throw new NotSupportedException(); }
}
public double Median => throw new NotSupportedException();
/// <summary>
/// Gets the minimum of the distribution.
/// </summary>
public int Minimum
{
get { return Math.Max(0, _draws + _success - _population); }
}
public int Minimum => Math.Max(0, _draws + _success - _population);
/// <summary>
/// Gets the maximum of the distribution.
/// </summary>
public int Maximum
{
get { return Math.Min(_success, _draws); }
}
public int Maximum => Math.Min(_success, _draws);
/// <summary>
/// Computes the probability mass (PMF) at k, i.e. P(X = k).

44
src/Numerics/Distributions/InverseGamma.cs

@ -106,26 +106,20 @@ namespace MathNet.Numerics.Distributions
/// <summary>
/// Gets or sets the shape (α) parameter. Range: α > 0.
/// </summary>
public double Shape
{
get { return _shape; }
}
public double Shape => _shape;
/// <summary>
/// Gets or sets The scale (β) parameter. Range: β > 0.
/// </summary>
public double Scale
{
get { return _scale; }
}
public double Scale => _scale;
/// <summary>
/// Gets or sets the random number generator which is used to draw random samples.
/// </summary>
public System.Random RandomSource
{
get { return _random; }
set { _random = value ?? SystemRandomSource.Default; }
get => _random;
set => _random = value ?? SystemRandomSource.Default;
}
/// <summary>
@ -163,18 +157,12 @@ namespace MathNet.Numerics.Distributions
/// <summary>
/// Gets the standard deviation of the distribution.
/// </summary>
public double StdDev
{
get { return _scale/(Math.Abs(_shape - 1.0)*Math.Sqrt(_shape - 2.0)); }
}
public double StdDev => _scale/(Math.Abs(_shape - 1.0)*Math.Sqrt(_shape - 2.0));
/// <summary>
/// Gets the entropy of the distribution.
/// </summary>
public double Entropy
{
get { return _shape + Math.Log(_scale) + SpecialFunctions.GammaLn(_shape) - ((1 + _shape)*SpecialFunctions.DiGamma(_shape)); }
}
public double Entropy => _shape + Math.Log(_scale) + SpecialFunctions.GammaLn(_shape) - ((1 + _shape)*SpecialFunctions.DiGamma(_shape));
/// <summary>
/// Gets the skewness of the distribution.
@ -195,35 +183,23 @@ namespace MathNet.Numerics.Distributions
/// <summary>
/// Gets the mode of the distribution.
/// </summary>
public double Mode
{
get { return _scale/(_shape + 1.0); }
}
public double Mode => _scale/(_shape + 1.0);
/// <summary>
/// Gets the median of the distribution.
/// </summary>
/// <remarks>Throws <see cref="NotSupportedException"/>.</remarks>
public double Median
{
get { throw new NotSupportedException(); }
}
public double Median => throw new NotSupportedException();
/// <summary>
/// Gets the minimum of the distribution.
/// </summary>
public double Minimum
{
get { return 0.0; }
}
public double Minimum => 0.0;
/// <summary>
/// Gets the maximum of the distribution.
/// </summary>
public double Maximum
{
get { return double.PositiveInfinity; }
}
public double Maximum => double.PositiveInfinity;
/// <summary>
/// Computes the probability density of the distribution (PDF) at x, i.e. ∂P(X ≤ x)/∂x.

63
src/Numerics/Distributions/InverseGaussian.cs

@ -92,99 +92,60 @@ namespace MathNet.Numerics.Distributions
/// </summary>
public System.Random RandomSource
{
get { return _random; }
set { _random = value ?? SystemRandomSource.Default; }
get => _random;
set => _random = value ?? SystemRandomSource.Default;
}
/// <summary>
/// Gets the mean of the Inverse Gaussian distribution.
/// </summary>
public double Mean
{
get
{
return Mu;
}
}
public double Mean => Mu;
/// <summary>
/// Gets the variance of the Inverse Gaussian distribution.
/// </summary>
public double Variance
{
get
{
return Math.Pow(Mu, 3) / Lambda;
}
}
public double Variance => Math.Pow(Mu, 3) / Lambda;
/// <summary>
/// Gets the standard deviation of the Inverse Gaussian distribution.
/// </summary>
public double StdDev
{
get
{
return Math.Sqrt(Variance);
}
}
public double StdDev => Math.Sqrt(Variance);
/// <summary>
/// Gets the median of the Inverse Gaussian distribution.
/// No closed form analytical expression exists, so this value is approximated numerically and can throw an exception.
/// </summary>
public double Median
{
get { return InvCDF(0.5); }
}
public double Median => InvCDF(0.5);
/// <summary>
/// Gets the minimum of the Inverse Gaussian distribution.
/// </summary>
public double Minimum
{
get { return 0.0; }
}
public double Minimum => 0.0;
/// <summary>
/// Gets the maximum of the Inverse Gaussian distribution.
/// </summary>
public double Maximum
{
get { return double.PositiveInfinity; }
}
public double Maximum => double.PositiveInfinity;
/// <summary>
/// Gets the skewness of the Inverse Gaussian distribution.
/// </summary>
public double Skewness
{
get { return 3 * Math.Sqrt(Mu / Lambda); }
}
public double Skewness => 3 * Math.Sqrt(Mu / Lambda);
/// <summary>
/// Gets the kurtosis of the Inverse Gaussian distribution.
/// </summary>
public double Kurtosis
{
get { return 15 * Mu / Lambda; }
}
public double Kurtosis => 15 * Mu / Lambda;
/// <summary>
/// Gets the mode of the Inverse Gaussian distribution.
/// </summary>
public double Mode
{
get { return Mu * (Math.Sqrt(1 + (9 * Mu * Mu) / (4 * Lambda * Lambda)) - (3 * Mu) / (2 * Lambda)); }
}
public double Mode => Mu * (Math.Sqrt(1 + (9 * Mu * Mu) / (4 * Lambda * Lambda)) - (3 * Mu) / (2 * Lambda));
/// <summary>
/// Gets the entropy of the Inverse Gaussian distribution (currently not supported).
/// </summary>
public double Entropy
{
get { throw new NotSupportedException(); }
}
public double Entropy => throw new NotSupportedException();
/// <summary>
/// Generates a sample from the inverse Gaussian distribution.

24
src/Numerics/Distributions/InverseWishart.cs

@ -125,46 +125,34 @@ namespace MathNet.Numerics.Distributions
/// <summary>
/// Gets or sets the degree of freedom (ν) for the inverse Wishart distribution.
/// </summary>
public double DegreesOfFreedom
{
get { return _freedom; }
}
public double DegreesOfFreedom => _freedom;
/// <summary>
/// Gets or sets the scale matrix (Ψ) for the inverse Wishart distribution.
/// </summary>
public Matrix<double> Scale
{
get { return _scale; }
}
public Matrix<double> Scale => _scale;
/// <summary>
/// Gets or sets the random number generator which is used to draw random samples.
/// </summary>
public System.Random RandomSource
{
get { return _random; }
set { _random = value ?? SystemRandomSource.Default; }
get => _random;
set => _random = value ?? SystemRandomSource.Default;
}
/// <summary>
/// Gets the mean.
/// </summary>
/// <value>The mean of the distribution.</value>
public Matrix<double> Mean
{
get { return _scale*(1.0/(_freedom - _scale.RowCount - 1.0)); }
}
public Matrix<double> Mean => _scale*(1.0/(_freedom - _scale.RowCount - 1.0));
/// <summary>
/// Gets the mode of the distribution.
/// </summary>
/// <value>The mode of the distribution.</value>
/// <remarks>A. O'Hagan, and J. J. Forster (2004). Kendall's Advanced Theory of Statistics: Bayesian Inference. 2B (2 ed.). Arnold. ISBN 0-340-80752-0.</remarks>
public Matrix<double> Mode
{
get { return _scale*(1.0/(_freedom + _scale.RowCount + 1.0)); }
}
public Matrix<double> Mode => _scale*(1.0/(_freedom + _scale.RowCount + 1.0));
/// <summary>
/// Gets the variance of the distribution.

59
src/Numerics/Distributions/Laplace.cs

@ -116,99 +116,66 @@ namespace MathNet.Numerics.Distributions
/// <summary>
/// Gets the location (μ) of the Laplace distribution.
/// </summary>
public double Location
{
get { return _location; }
}
public double Location => _location;
/// <summary>
/// Gets the scale (b) of the Laplace distribution. Range: b > 0.
/// </summary>
public double Scale
{
get { return _scale; }
}
public double Scale => _scale;
/// <summary>
/// Gets or sets the random number generator which is used to draw random samples.
/// </summary>
public System.Random RandomSource
{
get { return _random; }
set { _random = value ?? SystemRandomSource.Default; }
get => _random;
set => _random = value ?? SystemRandomSource.Default;
}
/// <summary>
/// Gets the mean of the distribution.
/// </summary>
public double Mean
{
get { return _location; }
}
public double Mean => _location;
/// <summary>
/// Gets the variance of the distribution.
/// </summary>
public double Variance
{
get { return 2.0*_scale*_scale; }
}
public double Variance => 2.0*_scale*_scale;
/// <summary>
/// Gets the standard deviation of the distribution.
/// </summary>
public double StdDev
{
get { return Constants.Sqrt2*_scale; }
}
public double StdDev => Constants.Sqrt2*_scale;
/// <summary>
/// Gets the entropy of the distribution.
/// </summary>
public double Entropy
{
get { return Math.Log(2.0*Constants.E*_scale); }
}
public double Entropy => Math.Log(2.0*Constants.E*_scale);
/// <summary>
/// Gets the skewness of the distribution.
/// </summary>
public double Skewness
{
get { return 0.0; }
}
public double Skewness => 0.0;
/// <summary>
/// Gets the mode of the distribution.
/// </summary>
public double Mode
{
get { return _location; }
}
public double Mode => _location;
/// <summary>
/// Gets the median of the distribution.
/// </summary>
public double Median
{
get { return _location; }
}
public double Median => _location;
/// <summary>
/// Gets the minimum of the distribution.
/// </summary>
public double Minimum
{
get { return double.NegativeInfinity; }
}
public double Minimum => double.NegativeInfinity;
/// <summary>
/// Gets the maximum of the distribution.
/// </summary>
public double Maximum
{
get { return double.PositiveInfinity; }
}
public double Maximum => double.PositiveInfinity;
/// <summary>
/// Computes the probability density of the distribution (PDF) at x, i.e. ∂P(X ≤ x)/∂x.

44
src/Numerics/Distributions/LogNormal.cs

@ -148,35 +148,26 @@ namespace MathNet.Numerics.Distributions
/// <summary>
/// Gets the log-scale (μ) (mean of the logarithm) of the distribution.
/// </summary>
public double Mu
{
get { return _mu; }
}
public double Mu => _mu;
/// <summary>
/// Gets the shape (σ) (standard deviation of the logarithm) of the distribution. Range: σ ≥ 0.
/// </summary>
public double Sigma
{
get { return _sigma; }
}
public double Sigma => _sigma;
/// <summary>
/// Gets or sets the random number generator which is used to draw random samples.
/// </summary>
public System.Random RandomSource
{
get { return _random; }
set { _random = value ?? SystemRandomSource.Default; }
get => _random;
set => _random = value ?? SystemRandomSource.Default;
}
/// <summary>
/// Gets the mu of the log-normal distribution.
/// </summary>
public double Mean
{
get { return Math.Exp(_mu + (_sigma*_sigma/2.0)); }
}
public double Mean => Math.Exp(_mu + (_sigma*_sigma/2.0));
/// <summary>
/// Gets the variance of the log-normal distribution.
@ -205,10 +196,7 @@ namespace MathNet.Numerics.Distributions
/// <summary>
/// Gets the entropy of the log-normal distribution.
/// </summary>
public double Entropy
{
get { return 0.5 + Math.Log(_sigma) + _mu + Constants.LogSqrt2Pi; }
}
public double Entropy => 0.5 + Math.Log(_sigma) + _mu + Constants.LogSqrt2Pi;
/// <summary>
/// Gets the skewness of the log-normal distribution.
@ -225,34 +213,22 @@ namespace MathNet.Numerics.Distributions
/// <summary>
/// Gets the mode of the log-normal distribution.
/// </summary>
public double Mode
{
get { return Math.Exp(_mu - (_sigma*_sigma)); }
}
public double Mode => Math.Exp(_mu - (_sigma*_sigma));
/// <summary>
/// Gets the median of the log-normal distribution.
/// </summary>
public double Median
{
get { return Math.Exp(_mu); }
}
public double Median => Math.Exp(_mu);
/// <summary>
/// Gets the minimum of the log-normal distribution.
/// </summary>
public double Minimum
{
get { return 0.0; }
}
public double Minimum => 0.0;
/// <summary>
/// Gets the maximum of the log-normal distribution.
/// </summary>
public double Maximum
{
get { return double.PositiveInfinity; }
}
public double Maximum => double.PositiveInfinity;
/// <summary>
/// Computes the probability density of the distribution (PDF) at x, i.e. ∂P(X ≤ x)/∂x.

19
src/Numerics/Distributions/MatrixNormal.cs

@ -155,36 +155,27 @@ namespace MathNet.Numerics.Distributions
/// Gets the mean. (M)
/// </summary>
/// <value>The mean of the distribution.</value>
public Matrix<double> Mean
{
get { return _m; }
}
public Matrix<double> Mean => _m;
/// <summary>
/// Gets the row covariance. (V)
/// </summary>
/// <value>The row covariance.</value>
public Matrix<double> RowCovariance
{
get { return _v; }
}
public Matrix<double> RowCovariance => _v;
/// <summary>
/// Gets the column covariance. (K)
/// </summary>
/// <value>The column covariance.</value>
public Matrix<double> ColumnCovariance
{
get { return _k; }
}
public Matrix<double> ColumnCovariance => _k;
/// <summary>
/// Gets or sets the random number generator which is used to draw random samples.
/// </summary>
public System.Random RandomSource
{
get { return _random; }
set { _random = value ?? SystemRandomSource.Default; }
get => _random;
set => _random = value ?? SystemRandomSource.Default;
}
/// <summary>

19
src/Numerics/Distributions/Multinomial.cs

@ -177,35 +177,26 @@ namespace MathNet.Numerics.Distributions
/// <summary>
/// Gets the proportion of ratios.
/// </summary>
public double[] P
{
get { return (double[])_p.Clone(); }
}
public double[] P => (double[])_p.Clone();
/// <summary>
/// Gets the number of trials.
/// </summary>
public int N
{
get { return _trials; }
}
public int N => _trials;
/// <summary>
/// Gets or sets the random number generator which is used to draw random samples.
/// </summary>
public System.Random RandomSource
{
get { return _random; }
set { _random = value ?? SystemRandomSource.Default; }
get => _random;
set => _random = value ?? SystemRandomSource.Default;
}
/// <summary>
/// Gets the mean of the distribution.
/// </summary>
public Vector<double> Mean
{
get { return _trials*(DenseVector)P; }
}
public Vector<double> Mean => _trials*(DenseVector)P;
/// <summary>
/// Gets the variance of the distribution.

59
src/Numerics/Distributions/NegativeBinomial.cs

@ -107,99 +107,66 @@ namespace MathNet.Numerics.Distributions
/// <summary>
/// Gets the number of successes. Range: r ≥ 0.
/// </summary>
public double R
{
get { return _r; }
}
public double R => _r;
/// <summary>
/// Gets the probability of success. Range: 0 ≤ p ≤ 1.
/// </summary>
public double P
{
get { return _p; }
}
public double P => _p;
/// <summary>
/// Gets or sets the random number generator which is used to draw random samples.
/// </summary>
public System.Random RandomSource
{
get { return _random; }
set { _random = value ?? SystemRandomSource.Default; }
get => _random;
set => _random = value ?? SystemRandomSource.Default;
}
/// <summary>
/// Gets the mean of the distribution.
/// </summary>
public double Mean
{
get { return _r*(1.0 - _p)/_p; }
}
public double Mean => _r*(1.0 - _p)/_p;
/// <summary>
/// Gets the variance of the distribution.
/// </summary>
public double Variance
{
get { return _r*(1.0 - _p)/(_p*_p); }
}
public double Variance => _r*(1.0 - _p)/(_p*_p);
/// <summary>
/// Gets the standard deviation of the distribution.
/// </summary>
public double StdDev
{
get { return Math.Sqrt(_r*(1.0 - _p))/_p; }
}
public double StdDev => Math.Sqrt(_r*(1.0 - _p))/_p;
/// <summary>
/// Gets the entropy of the distribution.
/// </summary>
public double Entropy
{
get { throw new NotSupportedException(); }
}
public double Entropy => throw new NotSupportedException();
/// <summary>
/// Gets the skewness of the distribution.
/// </summary>
public double Skewness
{
get { return (2.0 - _p)/Math.Sqrt(_r*(1.0 - _p)); }
}
public double Skewness => (2.0 - _p)/Math.Sqrt(_r*(1.0 - _p));
/// <summary>
/// Gets the mode of the distribution
/// </summary>
public int Mode
{
get { return _r > 1.0 ? (int)Math.Floor((_r - 1.0)*(1.0 - _p)/_p) : 0; }
}
public int Mode => _r > 1.0 ? (int)Math.Floor((_r - 1.0)*(1.0 - _p)/_p) : 0;
/// <summary>
/// Gets the median of the distribution.
/// </summary>
public double Median
{
get { throw new NotSupportedException(); }
}
public double Median => throw new NotSupportedException();
/// <summary>
/// Gets the smallest element in the domain of the distributions which can be represented by an integer.
/// </summary>
public int Minimum
{
get { return 0; }
}
public int Minimum => 0;
/// <summary>
/// Gets the largest element in the domain of the distributions which can be represented by an integer.
/// </summary>
public int Maximum
{
get { return int.MaxValue; }
}
public int Maximum => int.MaxValue;
/// <summary>
/// Computes the probability mass (PMF) at k, i.e. P(X = k).

54
src/Numerics/Distributions/Normal.cs

@ -176,91 +176,61 @@ namespace MathNet.Numerics.Distributions
/// <summary>
/// Gets the mean (μ) of the normal distribution.
/// </summary>
public double Mean
{
get { return _mean; }
}
public double Mean => _mean;
/// <summary>
/// Gets the standard deviation (σ) of the normal distribution. Range: σ ≥ 0.
/// </summary>
public double StdDev
{
get { return _stdDev; }
}
public double StdDev => _stdDev;
/// <summary>
/// Gets the variance of the normal distribution.
/// </summary>
public double Variance
{
get { return _stdDev*_stdDev; }
}
public double Variance => _stdDev*_stdDev;
/// <summary>
/// Gets the precision of the normal distribution.
/// </summary>
public double Precision
{
get { return 1.0/(_stdDev*_stdDev); }
}
public double Precision => 1.0/(_stdDev*_stdDev);
/// <summary>
/// Gets the random number generator which is used to draw random samples.
/// </summary>
public System.Random RandomSource
{
get { return _random; }
set { _random = value ?? SystemRandomSource.Default; }
get => _random;
set => _random = value ?? SystemRandomSource.Default;
}
/// <summary>
/// Gets the entropy of the normal distribution.
/// </summary>
public double Entropy
{
get { return Math.Log(_stdDev) + Constants.LogSqrt2PiE; }
}
public double Entropy => Math.Log(_stdDev) + Constants.LogSqrt2PiE;
/// <summary>
/// Gets the skewness of the normal distribution.
/// </summary>
public double Skewness
{
get { return 0.0; }
}
public double Skewness => 0.0;
/// <summary>
/// Gets the mode of the normal distribution.
/// </summary>
public double Mode
{
get { return _mean; }
}
public double Mode => _mean;
/// <summary>
/// Gets the median of the normal distribution.
/// </summary>
public double Median
{
get { return _mean; }
}
public double Median => _mean;
/// <summary>
/// Gets the minimum of the normal distribution.
/// </summary>
public double Minimum
{
get { return double.NegativeInfinity; }
}
public double Minimum => double.NegativeInfinity;
/// <summary>
/// Gets the maximum of the normal distribution.
/// </summary>
public double Maximum
{
get { return double.PositiveInfinity; }
}
public double Maximum => double.PositiveInfinity;
/// <summary>
/// Computes the probability density of the distribution (PDF) at x, i.e. ∂P(X ≤ x)/∂x.

60
src/Numerics/Distributions/NormalGamma.cs

@ -40,16 +40,6 @@ namespace MathNet.Numerics.Distributions
/// </summary>
public struct MeanPrecisionPair
{
/// <summary>
/// The mean value.
/// </summary>
double _mean;
/// <summary>
/// The precision value.
/// </summary>
double _precision;
/// <summary>
/// Initializes a new instance of the <see cref="MeanPrecisionPair"/> struct.
/// </summary>
@ -57,27 +47,19 @@ namespace MathNet.Numerics.Distributions
/// <param name="p">The precision of the pair.</param>
public MeanPrecisionPair(double m, double p)
{
_mean = m;
_precision = p;
Mean = m;
Precision = p;
}
/// <summary>
/// Gets or sets the mean of the pair.
/// </summary>
public double Mean
{
get { return _mean; }
set { _mean = value; }
}
public double Mean { get; set; }
/// <summary>
/// Gets or sets the precision of the pair.
/// </summary>
public double Precision
{
get { return _precision; }
set { _precision = value; }
}
public double Precision { get; set; }
}
/// <summary>
@ -170,42 +152,30 @@ namespace MathNet.Numerics.Distributions
/// <summary>
/// Gets the location of the mean.
/// </summary>
public double MeanLocation
{
get { return _meanLocation; }
}
public double MeanLocation => _meanLocation;
/// <summary>
/// Gets the scale of the mean.
/// </summary>
public double MeanScale
{
get { return _meanScale; }
}
public double MeanScale => _meanScale;
/// <summary>
/// Gets the shape of the precision.
/// </summary>
public double PrecisionShape
{
get { return _precisionShape; }
}
public double PrecisionShape => _precisionShape;
/// <summary>
/// Gets the inverse scale of the precision.
/// </summary>
public double PrecisionInverseScale
{
get { return _precisionInvScale; }
}
public double PrecisionInverseScale => _precisionInvScale;
/// <summary>
/// Gets or sets the random number generator which is used to draw random samples.
/// </summary>
public System.Random RandomSource
{
get { return _random; }
set { _random = value ?? SystemRandomSource.Default; }
get => _random;
set => _random = value ?? SystemRandomSource.Default;
}
/// <summary>
@ -235,19 +205,13 @@ namespace MathNet.Numerics.Distributions
/// Gets the mean of the distribution.
/// </summary>
/// <value>The mean of the distribution.</value>
public MeanPrecisionPair Mean
{
get { return double.IsPositiveInfinity(_precisionInvScale) ? new MeanPrecisionPair(_meanLocation, _precisionShape) : new MeanPrecisionPair(_meanLocation, _precisionShape/_precisionInvScale); }
}
public MeanPrecisionPair Mean => double.IsPositiveInfinity(_precisionInvScale) ? new MeanPrecisionPair(_meanLocation, _precisionShape) : new MeanPrecisionPair(_meanLocation, _precisionShape/_precisionInvScale);
/// <summary>
/// Gets the variance of the distribution.
/// </summary>
/// <value>The mean of the distribution.</value>
public MeanPrecisionPair Variance
{
get { return new MeanPrecisionPair(_precisionInvScale/(_meanScale*(_precisionShape - 1)), _precisionShape/Math.Sqrt(_precisionInvScale)); }
}
public MeanPrecisionPair Variance => new MeanPrecisionPair(_precisionInvScale/(_meanScale*(_precisionShape - 1)), _precisionShape/Math.Sqrt(_precisionInvScale));
/// <summary>
/// Evaluates the probability density function for a NormalGamma distribution.

49
src/Numerics/Distributions/Pareto.cs

@ -109,26 +109,20 @@ namespace MathNet.Numerics.Distributions
/// <summary>
/// Gets the scale (xm) of the distribution. Range: xm > 0.
/// </summary>
public double Scale
{
get { return _scale; }
}
public double Scale => _scale;
/// <summary>
/// Gets the shape (α) of the distribution. Range: α > 0.
/// </summary>
public double Shape
{
get { return _shape; }
}
public double Shape => _shape;
/// <summary>
/// Gets or sets the random number generator which is used to draw random samples.
/// </summary>
public System.Random RandomSource
{
get { return _random; }
set { _random = value ?? SystemRandomSource.Default; }
get => _random;
set => _random = value ?? SystemRandomSource.Default;
}
/// <summary>
@ -166,58 +160,37 @@ namespace MathNet.Numerics.Distributions
/// <summary>
/// Gets the standard deviation of the distribution.
/// </summary>
public double StdDev
{
get { return (_scale*Math.Sqrt(_shape))/(Math.Abs(_shape - 1.0)*Math.Sqrt(_shape - 2.0)); }
}
public double StdDev => (_scale*Math.Sqrt(_shape))/(Math.Abs(_shape - 1.0)*Math.Sqrt(_shape - 2.0));
/// <summary>
/// Gets the entropy of the distribution.
/// </summary>
public double Entropy
{
get { return Math.Log(_shape/_scale) - (1.0/_shape) - 1.0; }
}
public double Entropy => Math.Log(_shape/_scale) - (1.0/_shape) - 1.0;
/// <summary>
/// Gets the skewness of the distribution.
/// </summary>
public double Skewness
{
get { return (2.0*(_shape + 1.0)/(_shape - 3.0))*Math.Sqrt((_shape - 2.0)/_shape); }
}
public double Skewness => (2.0*(_shape + 1.0)/(_shape - 3.0))*Math.Sqrt((_shape - 2.0)/_shape);
/// <summary>
/// Gets the mode of the distribution.
/// </summary>
public double Mode
{
get { return _scale; }
}
public double Mode => _scale;
/// <summary>
/// Gets the median of the distribution.
/// </summary>
public double Median
{
get { return _scale*Math.Pow(2.0, 1.0/_shape); }
}
public double Median => _scale*Math.Pow(2.0, 1.0/_shape);
/// <summary>
/// Gets the minimum of the distribution.
/// </summary>
public double Minimum
{
get { return _scale; }
}
public double Minimum => _scale;
/// <summary>
/// Gets the maximum of the distribution.
/// </summary>
public double Maximum
{
get { return double.PositiveInfinity; }
}
public double Maximum => double.PositiveInfinity;
/// <summary>
/// Computes the probability density of the distribution (PDF) at x, i.e. ∂P(X ≤ x)/∂x.

54
src/Numerics/Distributions/Poisson.cs

@ -104,93 +104,63 @@ namespace MathNet.Numerics.Distributions
/// <summary>
/// Gets the Poisson distribution parameter λ. Range: λ > 0.
/// </summary>
public double Lambda
{
get { return _lambda; }
}
public double Lambda => _lambda;
/// <summary>
/// Gets the random number generator which is used to draw random samples.
/// </summary>
public System.Random RandomSource
{
get { return _random; }
set { _random = value ?? SystemRandomSource.Default; }
get => _random;
set => _random = value ?? SystemRandomSource.Default;
}
/// <summary>
/// Gets the mean of the distribution.
/// </summary>
public double Mean
{
get { return _lambda; }
}
public double Mean => _lambda;
/// <summary>
/// Gets the variance of the distribution.
/// </summary>
public double Variance
{
get { return _lambda; }
}
public double Variance => _lambda;
/// <summary>
/// Gets the standard deviation of the distribution.
/// </summary>
public double StdDev
{
get { return Math.Sqrt(_lambda); }
}
public double StdDev => Math.Sqrt(_lambda);
/// <summary>
/// Gets the entropy of the distribution.
/// </summary>
/// <remarks>Approximation, see Wikipedia <a href="http://en.wikipedia.org/wiki/Poisson_distribution">Poisson distribution</a></remarks>
public double Entropy
{
get { return (0.5*Math.Log(2*Constants.Pi*Constants.E*_lambda)) - (1.0/(12.0*_lambda)) - (1.0/(24.0*_lambda*_lambda)) - (19.0/(360.0*_lambda*_lambda*_lambda)); }
}
public double Entropy => (0.5*Math.Log(2*Constants.Pi*Constants.E*_lambda)) - (1.0/(12.0*_lambda)) - (1.0/(24.0*_lambda*_lambda)) - (19.0/(360.0*_lambda*_lambda*_lambda));
/// <summary>
/// Gets the skewness of the distribution.
/// </summary>
public double Skewness
{
get { return 1.0/Math.Sqrt(_lambda); }
}
public double Skewness => 1.0/Math.Sqrt(_lambda);
/// <summary>
/// Gets the smallest element in the domain of the distributions which can be represented by an integer.
/// </summary>
public int Minimum
{
get { return 0; }
}
public int Minimum => 0;
/// <summary>
/// Gets the largest element in the domain of the distributions which can be represented by an integer.
/// </summary>
public int Maximum
{
get { return int.MaxValue; }
}
public int Maximum => int.MaxValue;
/// <summary>
/// Gets the mode of the distribution.
/// </summary>
public int Mode
{
get { return (int)Math.Floor(_lambda); }
}
public int Mode => (int)Math.Floor(_lambda);
/// <summary>
/// Gets the median of the distribution.
/// </summary>
/// <remarks>Approximation, see Wikipedia <a href="http://en.wikipedia.org/wiki/Poisson_distribution">Poisson distribution</a></remarks>
public double Median
{
get { return Math.Floor(_lambda + (1.0/3.0) - (0.02/_lambda)); }
}
public double Median => Math.Floor(_lambda + (1.0/3.0) - (0.02/_lambda));
/// <summary>
/// Computes the probability mass (PMF) at k, i.e. P(X = k).

54
src/Numerics/Distributions/Rayleigh.cs

@ -104,91 +104,61 @@ namespace MathNet.Numerics.Distributions
/// <summary>
/// Gets the scale (σ) of the distribution. Range: σ > 0.
/// </summary>
public double Scale
{
get { return _scale; }
}
public double Scale => _scale;
/// <summary>
/// Gets or sets the random number generator which is used to draw random samples.
/// </summary>
public System.Random RandomSource
{
get { return _random; }
set { _random = value ?? SystemRandomSource.Default; }
get => _random;
set => _random = value ?? SystemRandomSource.Default;
}
/// <summary>
/// Gets the mean of the distribution.
/// </summary>
public double Mean
{
get { return _scale*Math.Sqrt(Constants.PiOver2); }
}
public double Mean => _scale*Math.Sqrt(Constants.PiOver2);
/// <summary>
/// Gets the variance of the distribution.
/// </summary>
public double Variance
{
get { return (2.0 - Constants.PiOver2)*_scale*_scale; }
}
public double Variance => (2.0 - Constants.PiOver2)*_scale*_scale;
/// <summary>
/// Gets the standard deviation of the distribution.
/// </summary>
public double StdDev
{
get { return Math.Sqrt(2.0 - Constants.PiOver2)*_scale; }
}
public double StdDev => Math.Sqrt(2.0 - Constants.PiOver2)*_scale;
/// <summary>
/// Gets the entropy of the distribution.
/// </summary>
public double Entropy
{
get { return 1.0 + Math.Log(_scale/Constants.Sqrt2) + (Constants.EulerMascheroni/2.0); }
}
public double Entropy => 1.0 + Math.Log(_scale/Constants.Sqrt2) + (Constants.EulerMascheroni/2.0);
/// <summary>
/// Gets the skewness of the distribution.
/// </summary>
public double Skewness
{
get { return (2.0*Math.Sqrt(Constants.Pi)*(Constants.Pi - 3.0))/Math.Pow(4.0 - Constants.Pi, 1.5); }
}
public double Skewness => (2.0*Math.Sqrt(Constants.Pi)*(Constants.Pi - 3.0))/Math.Pow(4.0 - Constants.Pi, 1.5);
/// <summary>
/// Gets the mode of the distribution.
/// </summary>
public double Mode
{
get { return _scale; }
}
public double Mode => _scale;
/// <summary>
/// Gets the median of the distribution.
/// </summary>
public double Median
{
get { return _scale*Math.Sqrt(Math.Log(4.0)); }
}
public double Median => _scale*Math.Sqrt(Math.Log(4.0));
/// <summary>
/// Gets the minimum of the distribution.
/// </summary>
public double Minimum
{
get { return 0.0; }
}
public double Minimum => 0.0;
/// <summary>
/// Gets the maximum of the distribution.
/// </summary>
public double Maximum
{
get { return double.PositiveInfinity; }
}
public double Maximum => double.PositiveInfinity;
/// <summary>
/// Computes the probability density of the distribution (PDF) at x, i.e. ∂P(X ≤ x)/∂x.

34
src/Numerics/Distributions/Stable.cs

@ -118,42 +118,30 @@ namespace MathNet.Numerics.Distributions
/// <summary>
/// Gets the stability (α) of the distribution. Range: 2 ≥ α > 0.
/// </summary>
public double Alpha
{
get { return _alpha; }
}
public double Alpha => _alpha;
/// <summary>
/// Gets The skewness (β) of the distribution. Range: 1 ≥ β ≥ -1.
/// </summary>
public double Beta
{
get { return _beta; }
}
public double Beta => _beta;
/// <summary>
/// Gets the scale (c) of the distribution. Range: c > 0.
/// </summary>
public double Scale
{
get { return _scale; }
}
public double Scale => _scale;
/// <summary>
/// Gets the location (μ) of the distribution.
/// </summary>
public double Location
{
get { return _location; }
}
public double Location => _location;
/// <summary>
/// Gets or sets the random number generator which is used to draw random samples.
/// </summary>
public System.Random RandomSource
{
get { return _random; }
set { _random = value ?? SystemRandomSource.Default; }
get => _random;
set => _random = value ?? SystemRandomSource.Default;
}
/// <summary>
@ -208,10 +196,7 @@ namespace MathNet.Numerics.Distributions
/// Gets he entropy of the distribution.
/// </summary>
/// <remarks>Always throws a not supported exception.</remarks>
public double Entropy
{
get { throw new NotSupportedException(); }
}
public double Entropy => throw new NotSupportedException();
/// <summary>
/// Gets the skewness of the distribution.
@ -283,10 +268,7 @@ namespace MathNet.Numerics.Distributions
/// <summary>
/// Gets the maximum of the distribution.
/// </summary>
public double Maximum
{
get { return double.PositiveInfinity; }
}
public double Maximum => double.PositiveInfinity;
/// <summary>
/// Computes the probability density of the distribution (PDF) at x, i.e. ∂P(X ≤ x)/∂x.

44
src/Numerics/Distributions/StudentT.cs

@ -140,43 +140,31 @@ namespace MathNet.Numerics.Distributions
/// <summary>
/// Gets the location (μ) of the Student t-distribution.
/// </summary>
public double Location
{
get { return _location; }
}
public double Location => _location;
/// <summary>
/// Gets the scale (σ) of the Student t-distribution. Range: σ > 0.
/// </summary>
public double Scale
{
get { return _scale; }
}
public double Scale => _scale;
/// <summary>
/// Gets the degrees of freedom (ν) of the Student t-distribution. Range: ν > 0.
/// </summary>
public double DegreesOfFreedom
{
get { return _freedom; }
}
public double DegreesOfFreedom => _freedom;
/// <summary>
/// Gets or sets the random number generator which is used to draw random samples.
/// </summary>
public System.Random RandomSource
{
get { return _random; }
set { _random = value ?? SystemRandomSource.Default; }
get => _random;
set => _random = value ?? SystemRandomSource.Default;
}
/// <summary>
/// Gets the mean of the Student t-distribution.
/// </summary>
public double Mean
{
get { return _freedom > 1.0 ? _location : double.NaN; }
}
public double Mean => _freedom > 1.0 ? _location : double.NaN;
/// <summary>
/// Gets the variance of the Student t-distribution.
@ -256,34 +244,22 @@ namespace MathNet.Numerics.Distributions
/// <summary>
/// Gets the mode of the Student t-distribution.
/// </summary>
public double Mode
{
get { return _location; }
}
public double Mode => _location;
/// <summary>
/// Gets the median of the Student t-distribution.
/// </summary>
public double Median
{
get { return _location; }
}
public double Median => _location;
/// <summary>
/// Gets the minimum of the Student t-distribution.
/// </summary>
public double Minimum
{
get { return double.NegativeInfinity; }
}
public double Minimum => double.NegativeInfinity;
/// <summary>
/// Gets the maximum of the Student t-distribution.
/// </summary>
public double Maximum
{
get { return double.PositiveInfinity; }
}
public double Maximum => double.PositiveInfinity;
/// <summary>
/// Computes the probability density of the distribution (PDF) at x, i.e. ∂P(X ≤ x)/∂x.

44
src/Numerics/Distributions/Triangular.cs

@ -116,35 +116,26 @@ namespace MathNet.Numerics.Distributions
/// <summary>
/// Gets the lower bound of the distribution.
/// </summary>
public double LowerBound
{
get { return _lower; }
}
public double LowerBound => _lower;
/// <summary>
/// Gets the upper bound of the distribution.
/// </summary>
public double UpperBound
{
get { return _upper; }
}
public double UpperBound => _upper;
/// <summary>
/// Gets or sets the random number generator which is used to draw random samples.
/// </summary>
public System.Random RandomSource
{
get { return _random; }
set { _random = value ?? SystemRandomSource.Default; }
get => _random;
set => _random = value ?? SystemRandomSource.Default;
}
/// <summary>
/// Gets the mean of the distribution.
/// </summary>
public double Mean
{
get { return (_lower + _upper + _mode)/3.0; }
}
public double Mean => (_lower + _upper + _mode)/3.0;
/// <summary>
/// Gets the variance of the distribution.
@ -163,19 +154,13 @@ namespace MathNet.Numerics.Distributions
/// <summary>
/// Gets the standard deviation of the distribution.
/// </summary>
public double StdDev
{
get { return Math.Sqrt(Variance); }
}
public double StdDev => Math.Sqrt(Variance);
/// <summary>
/// Gets the entropy of the distribution.
/// </summary>
/// <value></value>
public double Entropy
{
get { return 0.5 + Math.Log((_upper - _lower)/2); }
}
public double Entropy => 0.5 + Math.Log((_upper - _lower)/2);
/// <summary>
/// Gets the skewness of the distribution.
@ -196,10 +181,7 @@ namespace MathNet.Numerics.Distributions
/// <summary>
/// Gets or sets the mode of the distribution.
/// </summary>
public double Mode
{
get { return _mode; }
}
public double Mode => _mode;
/// <summary>
/// Gets the median of the distribution.
@ -221,18 +203,12 @@ namespace MathNet.Numerics.Distributions
/// <summary>
/// Gets the minimum of the distribution.
/// </summary>
public double Minimum
{
get { return _lower; }
}
public double Minimum => _lower;
/// <summary>
/// Gets the maximum of the distribution.
/// </summary>
public double Maximum
{
get { return _upper; }
}
public double Maximum => _upper;
/// <summary>
/// Computes the probability density of the distribution (PDF) at x, i.e. ∂P(X ≤ x)/∂x.

56
src/Numerics/Distributions/TruncatedPareto.cs

@ -84,8 +84,8 @@ namespace MathNet.Numerics.Distributions
/// </summary>
public System.Random RandomSource
{
get { return _random; }
set { _random = value ?? SystemRandomSource.Default; }
get => _random;
set => _random = value ?? SystemRandomSource.Default;
}
/// <summary>
@ -126,67 +126,37 @@ namespace MathNet.Numerics.Distributions
/// <summary>
/// Gets the mean of the truncated Pareto distribution.
/// </summary>
public double Mean
{
get
{
return GetMoment(1);
}
}
public double Mean => GetMoment(1);
/// <summary>
/// Gets the variance of the truncated Pareto distribution.
/// </summary>
public double Variance
{
get
{
return GetMoment(2) - Math.Pow(GetMoment(1), 2);
}
}
public double Variance => GetMoment(2) - Math.Pow(GetMoment(1), 2);
/// <summary>
/// Gets the standard deviation of the truncated Pareto distribution.
/// </summary>
public double StdDev
{
get
{
return Math.Sqrt(Variance);
}
}
public double StdDev => Math.Sqrt(Variance);
/// <summary>
/// Gets the mode of the truncated Pareto distribution (not supported).
/// </summary>
public double Mode
{
get { throw new NotSupportedException(); }
}
public double Mode => throw new NotSupportedException();
/// <summary>
/// Gets the minimum of the truncated Pareto distribution.
/// </summary>
public double Minimum
{
get { return Scale; }
}
public double Minimum => Scale;
/// <summary>
/// Gets the maximum of the truncated Pareto distribution.
/// </summary>
public double Maximum
{
get { return Truncation; }
}
public double Maximum => Truncation;
/// <summary>
/// Gets the entropy of the truncated Pareto distribution (not supported).
/// </summary>
public double Entropy
{
get { throw new NotSupportedException(); }
}
public double Entropy => throw new NotSupportedException();
/// <summary>
/// Gets the skewness of the truncated Pareto distribution.
@ -205,13 +175,7 @@ namespace MathNet.Numerics.Distributions
/// <summary>
/// Gets the median of the truncated Pareto distribution.
/// </summary>
public double Median
{
get
{
return Scale * Math.Pow(1.0 - (1.0 / 2.0) * (1.0 - Math.Pow(Scale / Truncation, Shape)), -(1.0 / Shape));
}
}
public double Median => Scale * Math.Pow(1.0 - (1.0 / 2.0) * (1.0 - Math.Pow(Scale / Truncation, Shape)), -(1.0 / Shape));
/// <summary>
/// Generates a sample from the truncated Pareto distribution.

49
src/Numerics/Distributions/Weibull.cs

@ -119,59 +119,41 @@ namespace MathNet.Numerics.Distributions
/// <summary>
/// Gets the shape (k) of the Weibull distribution. Range: k > 0.
/// </summary>
public double Shape
{
get { return _shape; }
}
public double Shape => _shape;
/// <summary>
/// Gets the scale (λ) of the Weibull distribution. Range: λ > 0.
/// </summary>
public double Scale
{
get { return _scale; }
}
public double Scale => _scale;
/// <summary>
/// Gets or sets the random number generator which is used to draw random samples.
/// </summary>
public System.Random RandomSource
{
get { return _random; }
set { _random = value ?? SystemRandomSource.Default; }
get => _random;
set => _random = value ?? SystemRandomSource.Default;
}
/// <summary>
/// Gets the mean of the Weibull distribution.
/// </summary>
public double Mean
{
get { return _scale*SpecialFunctions.Gamma(1.0 + (1.0/_shape)); }
}
public double Mean => _scale*SpecialFunctions.Gamma(1.0 + (1.0/_shape));
/// <summary>
/// Gets the variance of the Weibull distribution.
/// </summary>
public double Variance
{
get { return (_scale*_scale*SpecialFunctions.Gamma(1.0 + (2.0/_shape))) - (Mean*Mean); }
}
public double Variance => (_scale*_scale*SpecialFunctions.Gamma(1.0 + (2.0/_shape))) - (Mean*Mean);
/// <summary>
/// Gets the standard deviation of the Weibull distribution.
/// </summary>
public double StdDev
{
get { return Math.Sqrt(Variance); }
}
public double StdDev => Math.Sqrt(Variance);
/// <summary>
/// Gets the entropy of the Weibull distribution.
/// </summary>
public double Entropy
{
get { return (Constants.EulerMascheroni*(1.0 - (1.0/_shape))) + Math.Log(_scale/_shape) + 1.0; }
}
public double Entropy => (Constants.EulerMascheroni*(1.0 - (1.0/_shape))) + Math.Log(_scale/_shape) + 1.0;
/// <summary>
/// Gets the skewness of the Weibull distribution.
@ -207,26 +189,17 @@ namespace MathNet.Numerics.Distributions
/// <summary>
/// Gets the median of the Weibull distribution.
/// </summary>
public double Median
{
get { return _scale*Math.Pow(Constants.Ln2, 1.0/_shape); }
}
public double Median => _scale*Math.Pow(Constants.Ln2, 1.0/_shape);
/// <summary>
/// Gets the minimum of the Weibull distribution.
/// </summary>
public double Minimum
{
get { return 0.0; }
}
public double Minimum => 0.0;
/// <summary>
/// Gets the maximum of the Weibull distribution.
/// </summary>
public double Maximum
{
get { return double.PositiveInfinity; }
}
public double Maximum => double.PositiveInfinity;
/// <summary>
/// Computes the probability density of the distribution (PDF) at x, i.e. ∂P(X ≤ x)/∂x.

24
src/Numerics/Distributions/Wishart.cs

@ -130,18 +130,12 @@ namespace MathNet.Numerics.Distributions
/// <summary>
/// Gets or sets the degrees of freedom (n) for the Wishart distribution.
/// </summary>
public double DegreesOfFreedom
{
get { return _degreesOfFreedom; }
}
public double DegreesOfFreedom => _degreesOfFreedom;
/// <summary>
/// Gets or sets the scale matrix (V) for the Wishart distribution.
/// </summary>
public Matrix<double> Scale
{
get { return _scale; }
}
public Matrix<double> Scale => _scale;
/// <summary>
/// A string representation of the distribution.
@ -157,27 +151,21 @@ namespace MathNet.Numerics.Distributions
/// </summary>
public System.Random RandomSource
{
get { return _random; }
set { _random = value ?? SystemRandomSource.Default; }
get => _random;
set => _random = value ?? SystemRandomSource.Default;
}
/// <summary>
/// Gets the mean of the distribution.
/// </summary>
/// <value>The mean of the distribution.</value>
public Matrix<double> Mean
{
get { return _degreesOfFreedom*_scale; }
}
public Matrix<double> Mean => _degreesOfFreedom*_scale;
/// <summary>
/// Gets the mode of the distribution.
/// </summary>
/// <value>The mode of the distribution.</value>
public Matrix<double> Mode
{
get { return (_degreesOfFreedom - _scale.RowCount - 1.0)*_scale; }
}
public Matrix<double> Mode => (_degreesOfFreedom - _scale.RowCount - 1.0)*_scale;
/// <summary>
/// Gets the variance of the distribution.

44
src/Numerics/Distributions/Zipf.cs

@ -113,35 +113,26 @@ namespace MathNet.Numerics.Distributions
/// <summary>
/// Gets or sets the s parameter of the distribution.
/// </summary>
public double S
{
get { return _s; }
}
public double S => _s;
/// <summary>
/// Gets or sets the n parameter of the distribution.
/// </summary>
public int N
{
get { return _n; }
}
public int N => _n;
/// <summary>
/// Gets or sets the random number generator which is used to draw random samples.
/// </summary>
public System.Random RandomSource
{
get { return _random; }
set { _random = value ?? SystemRandomSource.Default; }
get => _random;
set => _random = value ?? SystemRandomSource.Default;
}
/// <summary>
/// Gets the mean of the distribution.
/// </summary>
public double Mean
{
get { return SpecialFunctions.GeneralHarmonic(_n, _s - 1.0)/SpecialFunctions.GeneralHarmonic(_n, _s); }
}
public double Mean => SpecialFunctions.GeneralHarmonic(_n, _s - 1.0)/SpecialFunctions.GeneralHarmonic(_n, _s);
/// <summary>
/// Gets the variance of the distribution.
@ -164,10 +155,7 @@ namespace MathNet.Numerics.Distributions
/// <summary>
/// Gets the standard deviation of the distribution.
/// </summary>
public double StdDev
{
get { return Math.Sqrt(Variance); }
}
public double StdDev => Math.Sqrt(Variance);
/// <summary>
/// Gets the entropy of the distribution.
@ -205,34 +193,22 @@ namespace MathNet.Numerics.Distributions
/// <summary>
/// Gets the mode of the distribution.
/// </summary>
public int Mode
{
get { return 1; }
}
public int Mode => 1;
/// <summary>
/// Gets the median of the distribution.
/// </summary>
public double Median
{
get { throw new NotSupportedException(); }
}
public double Median => throw new NotSupportedException();
/// <summary>
/// Gets the smallest element in the domain of the distributions which can be represented by an integer.
/// </summary>
public int Minimum
{
get { return 1; }
}
public int Minimum => 1;
/// <summary>
/// Gets the largest element in the domain of the distributions which can be represented by an integer.
/// </summary>
public int Maximum
{
get { return _n; }
}
public int Maximum => _n;
/// <summary>
/// Computes the probability mass (PMF) at k, i.e. P(X = k).

Loading…
Cancel
Save