From e757e0f1873797d84c387437593eff67efdd6591 Mon Sep 17 00:00:00 2001 From: Christoph Ruegg Date: Mon, 13 Apr 2020 15:02:46 +0200 Subject: [PATCH] Distributions: more compact code style (no functional changes) --- src/Numerics/Distributions/Bernoulli.cs | 54 ++++------------ src/Numerics/Distributions/Beta.cs | 39 +++-------- src/Numerics/Distributions/BetaScaled.cs | 49 ++++---------- src/Numerics/Distributions/Binomial.cs | 49 ++++---------- src/Numerics/Distributions/Burr.cs | 62 ++++-------------- src/Numerics/Distributions/Categorical.cs | 39 +++-------- src/Numerics/Distributions/Cauchy.cs | 59 ++++------------- src/Numerics/Distributions/Chi.cs | 44 +++---------- src/Numerics/Distributions/ChiSquared.cs | 54 ++++------------ .../Distributions/ContinuousUniform.cs | 59 ++++------------- .../Distributions/ConwayMaxwellPoisson.cs | 49 ++++---------- src/Numerics/Distributions/Dirichlet.cs | 19 ++---- src/Numerics/Distributions/DiscreteUniform.cs | 59 ++++------------- src/Numerics/Distributions/Erlang.cs | 34 +++------- src/Numerics/Distributions/Exponential.cs | 54 ++++------------ src/Numerics/Distributions/FisherSnedecor.cs | 39 +++-------- src/Numerics/Distributions/Gamma.cs | 34 +++------- src/Numerics/Distributions/Geometric.cs | 54 ++++------------ src/Numerics/Distributions/Hypergeometric.cs | 64 ++++--------------- src/Numerics/Distributions/InverseGamma.cs | 44 +++---------- src/Numerics/Distributions/InverseGaussian.cs | 63 ++++-------------- src/Numerics/Distributions/InverseWishart.cs | 24 ++----- src/Numerics/Distributions/Laplace.cs | 59 ++++------------- src/Numerics/Distributions/LogNormal.cs | 44 +++---------- src/Numerics/Distributions/MatrixNormal.cs | 19 ++---- src/Numerics/Distributions/Multinomial.cs | 19 ++---- .../Distributions/NegativeBinomial.cs | 59 ++++------------- src/Numerics/Distributions/Normal.cs | 54 ++++------------ src/Numerics/Distributions/NormalGamma.cs | 60 ++++------------- src/Numerics/Distributions/Pareto.cs | 49 ++++---------- src/Numerics/Distributions/Poisson.cs | 54 ++++------------ src/Numerics/Distributions/Rayleigh.cs | 54 ++++------------ src/Numerics/Distributions/Stable.cs | 34 +++------- src/Numerics/Distributions/StudentT.cs | 44 +++---------- src/Numerics/Distributions/Triangular.cs | 44 +++---------- src/Numerics/Distributions/TruncatedPareto.cs | 56 +++------------- src/Numerics/Distributions/Weibull.cs | 49 ++++---------- src/Numerics/Distributions/Wishart.cs | 24 ++----- src/Numerics/Distributions/Zipf.cs | 44 +++---------- 39 files changed, 402 insertions(+), 1409 deletions(-) diff --git a/src/Numerics/Distributions/Bernoulli.cs b/src/Numerics/Distributions/Bernoulli.cs index 2f62f0cf..a1707abd 100644 --- a/src/Numerics/Distributions/Bernoulli.cs +++ b/src/Numerics/Distributions/Bernoulli.cs @@ -102,83 +102,56 @@ namespace MathNet.Numerics.Distributions /// /// Gets the probability of generating a one. Range: 0 ≤ p ≤ 1. /// - public double P - { - get { return _p; } - } + public double P => _p; /// /// Gets or sets the random number generator which is used to draw random samples. /// public System.Random RandomSource { - get { return _random; } - set { _random = value ?? SystemRandomSource.Default; } + get => _random; + set => _random = value ?? SystemRandomSource.Default; } /// /// Gets the mean of the distribution. /// - public double Mean - { - get { return _p; } - } + public double Mean => _p; /// /// Gets the standard deviation of the distribution. /// - public double StdDev - { - get { return Math.Sqrt(_p*(1.0 - _p)); } - } + public double StdDev => Math.Sqrt(_p*(1.0 - _p)); /// /// Gets the variance of the distribution. /// - public double Variance - { - get { return _p*(1.0 - _p); } - } + public double Variance => _p*(1.0 - _p); /// /// Gets the entropy of the distribution. /// - 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)); /// /// Gets the skewness of the distribution. /// - 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)); /// /// Gets the smallest element in the domain of the distributions which can be represented by an integer. /// - public int Minimum - { - get { return 0; } - } + public int Minimum => 0; /// /// Gets the largest element in the domain of the distributions which can be represented by an integer. /// - public int Maximum - { - get { return 1; } - } + public int Maximum => 1; /// /// Gets the mode of the distribution. /// - public int Mode - { - get { return _p > 0.5 ? 1 : 0; } - } + public int Mode => _p > 0.5 ? 1 : 0; /// /// Gets all modes of the distribution. @@ -191,10 +164,7 @@ namespace MathNet.Numerics.Distributions /// /// Gets the median of the distribution. /// - 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; /// /// Computes the probability mass (PMF) at k, i.e. P(X = k). diff --git a/src/Numerics/Distributions/Beta.cs b/src/Numerics/Distributions/Beta.cs index e6ed1e98..2677901a 100644 --- a/src/Numerics/Distributions/Beta.cs +++ b/src/Numerics/Distributions/Beta.cs @@ -113,26 +113,20 @@ namespace MathNet.Numerics.Distributions /// /// Gets the α shape parameter of the Beta distribution. Range: α ≥ 0. /// - public double A - { - get { return _shapeA; } - } + public double A => _shapeA; /// /// Gets the β shape parameter of the Beta distribution. Range: β ≥ 0. /// - public double B - { - get { return _shapeB; } - } + public double B => _shapeB; /// /// Gets or sets the random number generator which is used to draw random samples. /// public System.Random RandomSource { - get { return _random; } - set { _random = value ?? SystemRandomSource.Default; } + get => _random; + set => _random = value ?? SystemRandomSource.Default; } /// @@ -179,18 +173,12 @@ namespace MathNet.Numerics.Distributions /// /// Gets the variance of the Beta distribution. /// - 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)); /// /// Gets the standard deviation of the Beta distribution. /// - 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))); /// /// Gets the entropy of the Beta distribution. @@ -312,26 +300,17 @@ namespace MathNet.Numerics.Distributions /// /// Gets the median of the Beta distribution. /// - public double Median - { - get { throw new NotSupportedException(); } - } + public double Median => throw new NotSupportedException(); /// /// Gets the minimum of the Beta distribution. /// - public double Minimum - { - get { return 0.0; } - } + public double Minimum => 0.0; /// /// Gets the maximum of the Beta distribution. /// - public double Maximum - { - get { return 1.0; } - } + public double Maximum => 1.0; /// /// Computes the probability density of the distribution (PDF) at x, i.e. ∂P(X ≤ x)/∂x. diff --git a/src/Numerics/Distributions/BetaScaled.cs b/src/Numerics/Distributions/BetaScaled.cs index 58eeaa3b..b0dfa2b0 100644 --- a/src/Numerics/Distributions/BetaScaled.cs +++ b/src/Numerics/Distributions/BetaScaled.cs @@ -154,42 +154,30 @@ namespace MathNet.Numerics.Distributions /// /// Gets the α shape parameter of the BetaScaled distribution. Range: α > 0. /// - public double A - { - get { return _shapeA; } - } + public double A => _shapeA; /// /// Gets the β shape parameter of the BetaScaled distribution. Range: β > 0. /// - public double B - { - get { return _shapeB; } - } + public double B => _shapeB; /// /// Gets the location (μ) of the BetaScaled distribution. /// - public double Location - { - get { return _location; } - } + public double Location => _location; /// /// Gets the scale (σ) of the BetaScaled distribution. Range: σ > 0. /// - public double Scale - { - get { return _scale; } - } + public double Scale => _scale; /// /// Gets or sets the random number generator which is used to draw random samples. /// public System.Random RandomSource { - get { return _random; } - set { _random = value ?? SystemRandomSource.Default; } + get => _random; + set => _random = value ?? SystemRandomSource.Default; } /// @@ -233,18 +221,12 @@ namespace MathNet.Numerics.Distributions /// /// Gets the standard deviation of the BetaScaled distribution. /// - public double StdDev - { - get { return Math.Sqrt(Variance); } - } + public double StdDev => Math.Sqrt(Variance); /// /// Gets the entropy of the BetaScaled distribution. /// - public double Entropy - { - get { throw new NotSupportedException(); } - } + public double Entropy => throw new NotSupportedException(); /// /// Gets the skewness of the BetaScaled distribution. @@ -308,26 +290,17 @@ namespace MathNet.Numerics.Distributions /// /// Gets the median of the BetaScaled distribution. /// - public double Median - { - get { throw new NotSupportedException(); } - } + public double Median => throw new NotSupportedException(); /// /// Gets the minimum of the BetaScaled distribution. /// - public double Minimum - { - get { return _location; } - } + public double Minimum => _location; /// /// Gets the maximum of the BetaScaled distribution. /// - public double Maximum - { - get { return _location + _scale; } - } + public double Maximum => _location + _scale; /// /// Computes the probability density of the distribution (PDF) at x, i.e. ∂P(X ≤ x)/∂x. diff --git a/src/Numerics/Distributions/Binomial.cs b/src/Numerics/Distributions/Binomial.cs index 6d076b3c..fc6a797b 100644 --- a/src/Numerics/Distributions/Binomial.cs +++ b/src/Numerics/Distributions/Binomial.cs @@ -111,51 +111,36 @@ namespace MathNet.Numerics.Distributions /// /// Gets the success probability in each trial. Range: 0 ≤ p ≤ 1. /// - public double P - { - get { return _p; } - } + public double P => _p; /// /// Gets the number of trials. Range: n ≥ 0. /// - public int N - { - get { return _trials; } - } + public int N => _trials; /// /// Gets or sets the random number generator which is used to draw random samples. /// public System.Random RandomSource { - get { return _random; } - set { _random = value ?? SystemRandomSource.Default; } + get => _random; + set => _random = value ?? SystemRandomSource.Default; } /// /// Gets the mean of the distribution. /// - public double Mean - { - get { return _p*_trials; } - } + public double Mean => _p*_trials; /// /// Gets the standard deviation of the distribution. /// - public double StdDev - { - get { return Math.Sqrt(_p*(1.0 - _p)*_trials); } - } + public double StdDev => Math.Sqrt(_p*(1.0 - _p)*_trials); /// /// Gets the variance of the distribution. /// - public double Variance - { - get { return _p*(1.0 - _p)*_trials; } - } + public double Variance => _p*(1.0 - _p)*_trials; /// /// Gets the entropy of the distribution. @@ -183,26 +168,17 @@ namespace MathNet.Numerics.Distributions /// /// Gets the skewness of the distribution. /// - 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)); /// /// Gets the smallest element in the domain of the distributions which can be represented by an integer. /// - public int Minimum - { - get { return 0; } - } + public int Minimum => 0; /// /// Gets the largest element in the domain of the distributions which can be represented by an integer. /// - public int Maximum - { - get { return _trials; } - } + public int Maximum => _trials; /// /// Gets the mode of the distribution. @@ -251,10 +227,7 @@ namespace MathNet.Numerics.Distributions /// /// Gets the median of the distribution. /// - public double Median - { - get { return Math.Floor(_p*_trials); } - } + public double Median => Math.Floor(_p*_trials); /// /// Computes the probability mass (PMF) at k, i.e. P(X = k). diff --git a/src/Numerics/Distributions/Burr.cs b/src/Numerics/Distributions/Burr.cs index 02162020..6d81b07a 100644 --- a/src/Numerics/Distributions/Burr.cs +++ b/src/Numerics/Distributions/Burr.cs @@ -98,78 +98,46 @@ namespace MathNet.Numerics.Distributions /// public System.Random RandomSource { - get { return _random; } - set { _random = value ?? SystemRandomSource.Default; } + get => _random; + set => _random = value ?? SystemRandomSource.Default; } /// /// Gets the mean of the Burr distribution. /// - 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); /// /// Gets the variance of the Burr distribution. /// - 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); /// /// Gets the standard deviation of the Burr distribution. /// - public double StdDev - { - get - { - return Math.Sqrt(Variance); - } - } + public double StdDev => Math.Sqrt(Variance); /// /// Gets the mode of the Burr distribution. /// - 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); /// /// Gets the minimum of the Burr distribution. /// - public double Minimum - { - get { return 0.0; } - } + public double Minimum => 0.0; /// /// Gets the maximum of the Burr distribution. /// - public double Maximum - { - get { return double.PositiveInfinity; } - } + public double Maximum => double.PositiveInfinity; /// /// Gets the entropy of the Burr distribution (currently not supported). /// - public double Entropy - { - get { throw new NotSupportedException(); } - } + public double Entropy => throw new NotSupportedException(); /// /// Gets the skewness of the Burr distribution. @@ -188,13 +156,7 @@ namespace MathNet.Numerics.Distributions /// /// Gets the median of the Burr distribution. /// - 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); /// /// Generates a sample from the Burr distribution. diff --git a/src/Numerics/Distributions/Categorical.cs b/src/Numerics/Distributions/Categorical.cs index 33f6651e..f686f0a9 100644 --- a/src/Numerics/Distributions/Categorical.cs +++ b/src/Numerics/Distributions/Categorical.cs @@ -205,18 +205,15 @@ namespace MathNet.Numerics.Distributions /// Gets the probability mass vector (non-negative ratios) of the multinomial. /// /// Sometimes the normalized probability vector cannot be represented exactly in a floating point representation. - public double[] P - { - get { return (double[])_pmfNormalized.Clone(); } - } + public double[] P => (double[])_pmfNormalized.Clone(); /// /// Gets or sets the random number generator which is used to draw random samples. /// public System.Random RandomSource { - get { return _random; } - set { _random = value ?? SystemRandomSource.Default; } + get => _random; + set => _random = value ?? SystemRandomSource.Default; } /// @@ -241,10 +238,7 @@ namespace MathNet.Numerics.Distributions /// /// Gets the standard deviation of the distribution. /// - public double StdDev - { - get { return Math.Sqrt(Variance); } - } + public double StdDev => Math.Sqrt(Variance); /// /// Gets the variance of the distribution. @@ -278,43 +272,28 @@ namespace MathNet.Numerics.Distributions /// Gets the skewness of the distribution. /// /// Throws a . - public double Skewness - { - get { throw new NotSupportedException(); } - } + public double Skewness => throw new NotSupportedException(); /// /// Gets the smallest element in the domain of the distributions which can be represented by an integer. /// - public int Minimum - { - get { return 0; } - } + public int Minimum => 0; /// /// Gets the largest element in the domain of the distributions which can be represented by an integer. /// - public int Maximum - { - get { return _pmfNormalized.Length - 1; } - } + public int Maximum => _pmfNormalized.Length - 1; /// /// Gets he mode of the distribution. /// /// Throws a . - public int Mode - { - get { throw new NotSupportedException(); } - } + public int Mode => throw new NotSupportedException(); /// /// Gets the median of the distribution. /// - public double Median - { - get { return InverseCumulativeDistribution(0.5); } - } + public double Median => InverseCumulativeDistribution(0.5); /// /// Computes the probability mass (PMF) at k, i.e. P(X = k). diff --git a/src/Numerics/Distributions/Cauchy.cs b/src/Numerics/Distributions/Cauchy.cs index 59f4f69d..490b66b6 100644 --- a/src/Numerics/Distributions/Cauchy.cs +++ b/src/Numerics/Distributions/Cauchy.cs @@ -111,99 +111,66 @@ namespace MathNet.Numerics.Distributions /// /// Gets the location (x0) of the distribution. /// - public double Location - { - get { return _location; } - } + public double Location => _location; /// /// Gets the scale (γ) of the distribution. Range: γ > 0. /// - public double Scale - { - get { return _scale; } - } + public double Scale => _scale; /// /// Gets or sets the random number generator which is used to draw random samples. /// public System.Random RandomSource { - get { return _random; } - set { _random = value ?? SystemRandomSource.Default; } + get => _random; + set => _random = value ?? SystemRandomSource.Default; } /// /// Gets the mean of the distribution. /// - public double Mean - { - get { throw new NotSupportedException(); } - } + public double Mean => throw new NotSupportedException(); /// /// Gets the variance of the distribution. /// - public double Variance - { - get { throw new NotSupportedException(); } - } + public double Variance => throw new NotSupportedException(); /// /// Gets the standard deviation of the distribution. /// - public double StdDev - { - get { throw new NotSupportedException(); } - } + public double StdDev => throw new NotSupportedException(); /// /// Gets the entropy of the distribution. /// - public double Entropy - { - get { return Math.Log(4.0*Constants.Pi*_scale); } - } + public double Entropy => Math.Log(4.0*Constants.Pi*_scale); /// /// Gets the skewness of the distribution. /// - public double Skewness - { - get { throw new NotSupportedException(); } - } + public double Skewness => throw new NotSupportedException(); /// /// Gets the mode of the distribution. /// - public double Mode - { - get { return _location; } - } + public double Mode => _location; /// /// Gets the median of the distribution. /// - public double Median - { - get { return _location; } - } + public double Median => _location; /// /// Gets the minimum of the distribution. /// - public double Minimum - { - get { return double.NegativeInfinity; } - } + public double Minimum => double.NegativeInfinity; /// /// Gets the maximum of the distribution. /// - public double Maximum - { - get { return double.PositiveInfinity; } - } + public double Maximum => double.PositiveInfinity; /// /// Computes the probability density of the distribution (PDF) at x, i.e. ∂P(X ≤ x)/∂x. diff --git a/src/Numerics/Distributions/Chi.cs b/src/Numerics/Distributions/Chi.cs index d8b0b5dd..f46e3087 100644 --- a/src/Numerics/Distributions/Chi.cs +++ b/src/Numerics/Distributions/Chi.cs @@ -100,51 +100,36 @@ namespace MathNet.Numerics.Distributions /// /// Gets the degrees of freedom (k) of the Chi distribution. Range: k > 0. /// - public double DegreesOfFreedom - { - get { return _freedom; } - } + public double DegreesOfFreedom => _freedom; /// /// Gets or sets the random number generator which is used to draw random samples. /// public System.Random RandomSource { - get { return _random; } - set { _random = value ?? SystemRandomSource.Default; } + get => _random; + set => _random = value ?? SystemRandomSource.Default; } /// /// Gets the mean of the distribution. /// - 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)); /// /// Gets the variance of the distribution. /// - public double Variance - { - get { return _freedom - (Mean*Mean); } - } + public double Variance => _freedom - (Mean*Mean); /// /// Gets the standard deviation of the distribution. /// - public double StdDev - { - get { return Math.Sqrt(Variance); } - } + public double StdDev => Math.Sqrt(Variance); /// /// Gets the entropy of the distribution. /// - 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); /// /// Gets the skewness of the distribution. @@ -177,26 +162,17 @@ namespace MathNet.Numerics.Distributions /// /// Gets the median of the distribution. /// - public double Median - { - get { throw new NotSupportedException(); } - } + public double Median => throw new NotSupportedException(); /// /// Gets the minimum of the distribution. /// - public double Minimum - { - get { return 0.0; } - } + public double Minimum => 0.0; /// /// Gets the maximum of the distribution. /// - public double Maximum - { - get { return double.PositiveInfinity; } - } + public double Maximum => double.PositiveInfinity; /// /// Computes the probability density of the distribution (PDF) at x, i.e. ∂P(X ≤ x)/∂x. diff --git a/src/Numerics/Distributions/ChiSquared.cs b/src/Numerics/Distributions/ChiSquared.cs index e2604449..c58ff529 100644 --- a/src/Numerics/Distributions/ChiSquared.cs +++ b/src/Numerics/Distributions/ChiSquared.cs @@ -98,91 +98,61 @@ namespace MathNet.Numerics.Distributions /// /// Gets the degrees of freedom (k) of the Chi-Squared distribution. Range: k > 0. /// - public double DegreesOfFreedom - { - get { return _freedom; } - } + public double DegreesOfFreedom => _freedom; /// /// Gets or sets the random number generator which is used to draw random samples. /// public System.Random RandomSource { - get { return _random; } - set { _random = value ?? SystemRandomSource.Default; } + get => _random; + set => _random = value ?? SystemRandomSource.Default; } /// /// Gets the mean of the distribution. /// - public double Mean - { - get { return _freedom; } - } + public double Mean => _freedom; /// /// Gets the variance of the distribution. /// - public double Variance - { - get { return 2.0*_freedom; } - } + public double Variance => 2.0*_freedom; /// /// Gets the standard deviation of the distribution. /// - public double StdDev - { - get { return Math.Sqrt(2.0*_freedom); } - } + public double StdDev => Math.Sqrt(2.0*_freedom); /// /// Gets the entropy of the distribution. /// - 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)); /// /// Gets the skewness of the distribution. /// - public double Skewness - { - get { return Math.Sqrt(8.0/_freedom); } - } + public double Skewness => Math.Sqrt(8.0/_freedom); /// /// Gets the mode of the distribution. /// - public double Mode - { - get { return _freedom - 2.0; } - } + public double Mode => _freedom - 2.0; /// /// Gets the median of the distribution. /// - public double Median - { - get { return _freedom - (2.0/3.0); } - } + public double Median => _freedom - (2.0/3.0); /// /// Gets the minimum of the distribution. /// - public double Minimum - { - get { return 0.0; } - } + public double Minimum => 0.0; /// /// Gets the maximum of the distribution. /// - public double Maximum - { - get { return double.PositiveInfinity; } - } + public double Maximum => double.PositiveInfinity; /// /// Computes the probability density of the distribution (PDF) at x, i.e. ∂P(X ≤ x)/∂x. diff --git a/src/Numerics/Distributions/ContinuousUniform.cs b/src/Numerics/Distributions/ContinuousUniform.cs index aab9f426..b9bdf416 100644 --- a/src/Numerics/Distributions/ContinuousUniform.cs +++ b/src/Numerics/Distributions/ContinuousUniform.cs @@ -113,102 +113,69 @@ namespace MathNet.Numerics.Distributions /// /// Gets the lower bound of the distribution. /// - public double LowerBound - { - get { return _lower; } - } + public double LowerBound => _lower; /// /// Gets the upper bound of the distribution. /// - public double UpperBound - { - get { return _upper; } - } + public double UpperBound => _upper; /// /// Gets or sets the random number generator which is used to draw random samples. /// public System.Random RandomSource { - get { return _random; } - set { _random = value ?? SystemRandomSource.Default; } + get => _random; + set => _random = value ?? SystemRandomSource.Default; } /// /// Gets the mean of the distribution. /// - public double Mean - { - get { return (_lower + _upper)/2.0; } - } + public double Mean => (_lower + _upper)/2.0; /// /// Gets the variance of the distribution. /// - public double Variance - { - get { return (_upper - _lower)*(_upper - _lower)/12.0; } - } + public double Variance => (_upper - _lower)*(_upper - _lower)/12.0; /// /// Gets the standard deviation of the distribution. /// - public double StdDev - { - get { return (_upper - _lower)/Math.Sqrt(12.0); } - } + public double StdDev => (_upper - _lower)/Math.Sqrt(12.0); /// /// Gets the entropy of the distribution. /// /// - public double Entropy - { - get { return Math.Log(_upper - _lower); } - } + public double Entropy => Math.Log(_upper - _lower); /// /// Gets the skewness of the distribution. /// - public double Skewness - { - get { return 0.0; } - } + public double Skewness => 0.0; /// /// Gets the mode of the distribution. /// /// - public double Mode - { - get { return (_lower + _upper)/2.0; } - } + public double Mode => (_lower + _upper)/2.0; /// /// Gets the median of the distribution. /// /// - public double Median - { - get { return (_lower + _upper)/2.0; } - } + public double Median => (_lower + _upper)/2.0; /// /// Gets the minimum of the distribution. /// - public double Minimum - { - get { return _lower; } - } + public double Minimum => _lower; /// /// Gets the maximum of the distribution. /// - public double Maximum - { - get { return _upper; } - } + public double Maximum => _upper; /// /// Computes the probability density of the distribution (PDF) at x, i.e. ∂P(X ≤ x)/∂x. diff --git a/src/Numerics/Distributions/ConwayMaxwellPoisson.cs b/src/Numerics/Distributions/ConwayMaxwellPoisson.cs index c7c24cf4..dc6c80a5 100644 --- a/src/Numerics/Distributions/ConwayMaxwellPoisson.cs +++ b/src/Numerics/Distributions/ConwayMaxwellPoisson.cs @@ -132,26 +132,20 @@ namespace MathNet.Numerics.Distributions /// /// Gets the lambda (λ) parameter. Range: λ > 0. /// - public double Lambda - { - get { return _lambda; } - } + public double Lambda => _lambda; /// /// Gets the rate of decay (ν) parameter. Range: ν ≥ 0. /// - public double Nu - { - get { return _nu; } - } + public double Nu => _nu; /// /// Gets or sets the random number generator which is used to draw random samples. /// public System.Random RandomSource { - get { return _random; } - set { _random = value ?? SystemRandomSource.Default; } + get => _random; + set => _random = value ?? SystemRandomSource.Default; } /// @@ -280,58 +274,37 @@ namespace MathNet.Numerics.Distributions /// /// Gets the standard deviation of the distribution. /// - public double StdDev - { - get { return Math.Sqrt(Variance); } - } + public double StdDev => Math.Sqrt(Variance); /// /// Gets the entropy of the distribution. /// - public double Entropy - { - get { throw new NotSupportedException(); } - } + public double Entropy => throw new NotSupportedException(); /// /// Gets the skewness of the distribution. /// - public double Skewness - { - get { throw new NotSupportedException(); } - } + public double Skewness => throw new NotSupportedException(); /// /// Gets the mode of the distribution /// - public int Mode - { - get { throw new NotSupportedException(); } - } + public int Mode => throw new NotSupportedException(); /// /// Gets the median of the distribution. /// - public double Median - { - get { throw new NotSupportedException(); } - } + public double Median => throw new NotSupportedException(); /// /// Gets the smallest element in the domain of the distributions which can be represented by an integer. /// - public int Minimum - { - get { return 0; } - } + public int Minimum => 0; /// /// Gets the largest element in the domain of the distributions which can be represented by an integer. /// - public int Maximum - { - get { throw new NotSupportedException(); } - } + public int Maximum => throw new NotSupportedException(); /// /// Computes the probability mass (PMF) at k, i.e. P(X = k). diff --git a/src/Numerics/Distributions/Dirichlet.cs b/src/Numerics/Distributions/Dirichlet.cs index 350c2de0..c9f4c36c 100644 --- a/src/Numerics/Distributions/Dirichlet.cs +++ b/src/Numerics/Distributions/Dirichlet.cs @@ -164,35 +164,26 @@ namespace MathNet.Numerics.Distributions /// /// Gets or sets the parameters of the Dirichlet distribution. /// - public double[] Alpha - { - get { return _alpha; } - } + public double[] Alpha => _alpha; /// /// Gets or sets the random number generator which is used to draw random samples. /// public System.Random RandomSource { - get { return _random; } - set { _random = value ?? SystemRandomSource.Default; } + get => _random; + set => _random = value ?? SystemRandomSource.Default; } /// /// Gets the dimension of the Dirichlet distribution. /// - public int Dimension - { - get { return _alpha.Length; } - } + public int Dimension => _alpha.Length; /// /// Gets the sum of the Dirichlet parameters. /// - double AlphaSum - { - get { return _alpha.Sum(); } - } + double AlphaSum => _alpha.Sum(); /// /// Gets the mean of the Dirichlet distribution. diff --git a/src/Numerics/Distributions/DiscreteUniform.cs b/src/Numerics/Distributions/DiscreteUniform.cs index 2380c767..0b1a5d29 100644 --- a/src/Numerics/Distributions/DiscreteUniform.cs +++ b/src/Numerics/Distributions/DiscreteUniform.cs @@ -106,99 +106,66 @@ namespace MathNet.Numerics.Distributions /// /// Gets the inclusive lower bound of the probability distribution. /// - public int LowerBound - { - get { return _lower; } - } + public int LowerBound => _lower; /// /// Gets the inclusive upper bound of the probability distribution. /// - public int UpperBound - { - get { return _upper; } - } + public int UpperBound => _upper; /// /// Gets or sets the random number generator which is used to draw random samples. /// public System.Random RandomSource { - get { return _random; } - set { _random = value ?? SystemRandomSource.Default; } + get => _random; + set => _random = value ?? SystemRandomSource.Default; } /// /// Gets the mean of the distribution. /// - public double Mean - { - get { return (_lower + _upper)/2.0; } - } + public double Mean => (_lower + _upper)/2.0; /// /// Gets the standard deviation of the distribution. /// - 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); /// /// Gets the variance of the distribution. /// - 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; /// /// Gets the entropy of the distribution. /// - public double Entropy - { - get { return Math.Log(_upper - _lower + 1.0); } - } + public double Entropy => Math.Log(_upper - _lower + 1.0); /// /// Gets the skewness of the distribution. /// - public double Skewness - { - get { return 0.0; } - } + public double Skewness => 0.0; /// /// Gets the smallest element in the domain of the distributions which can be represented by an integer. /// - public int Minimum - { - get { return _lower; } - } + public int Minimum => _lower; /// /// Gets the largest element in the domain of the distributions which can be represented by an integer. /// - public int Maximum - { - get { return _upper; } - } + public int Maximum => _upper; /// /// Gets the mode of the distribution; since every element in the domain has the same probability this method returns the middle one. /// - public int Mode - { - get { return (int)Math.Floor((_lower + _upper)/2.0); } - } + public int Mode => (int)Math.Floor((_lower + _upper)/2.0); /// /// Gets the median of the distribution. /// - public double Median - { - get { return (_lower + _upper)/2.0; } - } + public double Median => (_lower + _upper)/2.0; /// /// Computes the probability mass (PMF) at k, i.e. P(X = k). diff --git a/src/Numerics/Distributions/Erlang.cs b/src/Numerics/Distributions/Erlang.cs index 66d69fb4..5a9ee3a8 100644 --- a/src/Numerics/Distributions/Erlang.cs +++ b/src/Numerics/Distributions/Erlang.cs @@ -128,34 +128,25 @@ namespace MathNet.Numerics.Distributions /// /// Gets the shape (k) of the Erlang distribution. Range: k ≥ 0. /// - public int Shape - { - get { return _shape; } - } + public int Shape => _shape; /// /// Gets the rate or inverse scale (λ) of the Erlang distribution. Range: λ ≥ 0. /// - public double Rate - { - get { return _rate; } - } + public double Rate => _rate; /// /// Gets the scale of the Erlang distribution. /// - public double Scale - { - get { return 1.0/_rate; } - } + public double Scale => 1.0/_rate; /// /// Gets or sets the random number generator which is used to draw random samples. /// public System.Random RandomSource { - get { return _random; } - set { _random = value ?? SystemRandomSource.Default; } + get => _random; + set => _random = value ?? SystemRandomSource.Default; } /// @@ -292,26 +283,17 @@ namespace MathNet.Numerics.Distributions /// /// Gets the median of the distribution. /// - public double Median - { - get { throw new NotSupportedException(); } - } + public double Median => throw new NotSupportedException(); /// /// Gets the minimum value. /// - public double Minimum - { - get { return 0.0; } - } + public double Minimum => 0.0; /// /// Gets the Maximum value. /// - public double Maximum - { - get { return double.PositiveInfinity; } - } + public double Maximum => double.PositiveInfinity; /// /// Computes the probability density of the distribution (PDF) at x, i.e. ∂P(X ≤ x)/∂x. diff --git a/src/Numerics/Distributions/Exponential.cs b/src/Numerics/Distributions/Exponential.cs index 1eb40964..a7967d0a 100644 --- a/src/Numerics/Distributions/Exponential.cs +++ b/src/Numerics/Distributions/Exponential.cs @@ -99,91 +99,61 @@ namespace MathNet.Numerics.Distributions /// /// Gets the rate (λ) parameter of the distribution. Range: λ ≥ 0. /// - public double Rate - { - get { return _rate; } - } + public double Rate => _rate; /// /// Gets or sets the random number generator which is used to draw random samples. /// public System.Random RandomSource { - get { return _random; } - set { _random = value ?? SystemRandomSource.Default; } + get => _random; + set => _random = value ?? SystemRandomSource.Default; } /// /// Gets the mean of the distribution. /// - public double Mean - { - get { return 1.0/_rate; } - } + public double Mean => 1.0/_rate; /// /// Gets the variance of the distribution. /// - public double Variance - { - get { return 1.0/(_rate*_rate); } - } + public double Variance => 1.0/(_rate*_rate); /// /// Gets the standard deviation of the distribution. /// - public double StdDev - { - get { return 1.0/_rate; } - } + public double StdDev => 1.0/_rate; /// /// Gets the entropy of the distribution. /// - public double Entropy - { - get { return 1.0 - Math.Log(_rate); } - } + public double Entropy => 1.0 - Math.Log(_rate); /// /// Gets the skewness of the distribution. /// - public double Skewness - { - get { return 2.0; } - } + public double Skewness => 2.0; /// /// Gets the mode of the distribution. /// - public double Mode - { - get { return 0.0; } - } + public double Mode => 0.0; /// /// Gets the median of the distribution. /// - public double Median - { - get { return Math.Log(2.0)/_rate; } - } + public double Median => Math.Log(2.0)/_rate; /// /// Gets the minimum of the distribution. /// - public double Minimum - { - get { return 0.0; } - } + public double Minimum => 0.0; /// /// Gets the maximum of the distribution. /// - public double Maximum - { - get { return double.PositiveInfinity; } - } + public double Maximum => double.PositiveInfinity; /// /// Computes the probability density of the distribution (PDF) at x, i.e. ∂P(X ≤ x)/∂x. diff --git a/src/Numerics/Distributions/FisherSnedecor.cs b/src/Numerics/Distributions/FisherSnedecor.cs index 1d1f91f6..d6277d39 100644 --- a/src/Numerics/Distributions/FisherSnedecor.cs +++ b/src/Numerics/Distributions/FisherSnedecor.cs @@ -105,26 +105,20 @@ namespace MathNet.Numerics.Distributions /// /// Gets the first degree of freedom (d1) of the distribution. Range: d1 > 0. /// - public double DegreesOfFreedom1 - { - get { return _freedom1; } - } + public double DegreesOfFreedom1 => _freedom1; /// /// Gets the second degree of freedom (d2) of the distribution. Range: d2 > 0. /// - public double DegreesOfFreedom2 - { - get { return _freedom2; } - } + public double DegreesOfFreedom2 => _freedom2; /// /// Gets or sets the random number generator which is used to draw random samples. /// public System.Random RandomSource { - get { return _random; } - set { _random = value ?? SystemRandomSource.Default; } + get => _random; + set => _random = value ?? SystemRandomSource.Default; } /// @@ -162,18 +156,12 @@ namespace MathNet.Numerics.Distributions /// /// Gets the standard deviation of the distribution. /// - public double StdDev - { - get { return Math.Sqrt(Variance); } - } + public double StdDev => Math.Sqrt(Variance); /// /// Gets the entropy of the distribution. /// - public double Entropy - { - get { throw new NotSupportedException(); } - } + public double Entropy => throw new NotSupportedException(); /// /// Gets the skewness of the distribution. @@ -210,26 +198,17 @@ namespace MathNet.Numerics.Distributions /// /// Gets the median of the distribution. /// - public double Median - { - get { throw new NotSupportedException(); } - } + public double Median => throw new NotSupportedException(); /// /// Gets the minimum of the distribution. /// - public double Minimum - { - get { return 0.0; } - } + public double Minimum => 0.0; /// /// Gets the maximum of the distribution. /// - public double Maximum - { - get { return double.PositiveInfinity; } - } + public double Maximum => double.PositiveInfinity; /// /// Computes the probability density of the distribution (PDF) at x, i.e. ∂P(X ≤ x)/∂x. diff --git a/src/Numerics/Distributions/Gamma.cs b/src/Numerics/Distributions/Gamma.cs index 6fbf2d4e..b7ada40b 100644 --- a/src/Numerics/Distributions/Gamma.cs +++ b/src/Numerics/Distributions/Gamma.cs @@ -137,34 +137,25 @@ namespace MathNet.Numerics.Distributions /// /// Gets or sets the shape (k, α) of the Gamma distribution. Range: α ≥ 0. /// - public double Shape - { - get { return _shape; } - } + public double Shape => _shape; /// /// Gets or sets the rate or inverse scale (β) of the Gamma distribution. Range: β ≥ 0. /// - public double Rate - { - get { return _rate; } - } + public double Rate => _rate; /// /// Gets or sets the scale (θ) of the Gamma distribution. /// - public double Scale - { - get { return 1.0/_rate; } - } + public double Scale => 1.0/_rate; /// /// Gets or sets the random number generator which is used to draw random samples. /// public System.Random RandomSource { - get { return _random; } - set { _random = value ?? SystemRandomSource.Default; } + get => _random; + set => _random = value ?? SystemRandomSource.Default; } /// @@ -296,26 +287,17 @@ namespace MathNet.Numerics.Distributions /// /// Gets the median of the Gamma distribution. /// - public double Median - { - get { throw new NotSupportedException(); } - } + public double Median => throw new NotSupportedException(); /// /// Gets the minimum of the Gamma distribution. /// - public double Minimum - { - get { return 0.0; } - } + public double Minimum => 0.0; /// /// Gets the maximum of the Gamma distribution. /// - public double Maximum - { - get { return double.PositiveInfinity; } - } + public double Maximum => double.PositiveInfinity; /// /// Computes the probability density of the distribution (PDF) at x, i.e. ∂P(X ≤ x)/∂x. diff --git a/src/Numerics/Distributions/Geometric.cs b/src/Numerics/Distributions/Geometric.cs index 8e051819..6a3bfed9 100644 --- a/src/Numerics/Distributions/Geometric.cs +++ b/src/Numerics/Distributions/Geometric.cs @@ -100,92 +100,62 @@ namespace MathNet.Numerics.Distributions /// /// Gets the probability of generating a one. Range: 0 ≤ p ≤ 1. /// - public double P - { - get { return _p; } - } + public double P => _p; /// /// Gets or sets the random number generator which is used to draw random samples. /// public System.Random RandomSource { - get { return _random; } - set { _random = value ?? SystemRandomSource.Default; } + get => _random; + set => _random = value ?? SystemRandomSource.Default; } /// /// Gets the mean of the distribution. /// - public double Mean - { - get { return 1.0/_p; } - } + public double Mean => 1.0/_p; /// /// Gets the variance of the distribution. /// - public double Variance - { - get { return (1.0 - _p)/(_p*_p); } - } + public double Variance => (1.0 - _p)/(_p*_p); /// /// Gets the standard deviation of the distribution. /// - public double StdDev - { - get { return Math.Sqrt(1.0 - _p)/_p; } - } + public double StdDev => Math.Sqrt(1.0 - _p)/_p; /// /// Gets the entropy of the distribution. /// - 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; /// /// Gets the skewness of the distribution. /// /// Throws a not supported exception. - public double Skewness - { - get { return (2.0 - _p)/Math.Sqrt(1.0 - _p); } - } + public double Skewness => (2.0 - _p)/Math.Sqrt(1.0 - _p); /// /// Gets the mode of the distribution. /// - public int Mode - { - get { return 1; } - } + public int Mode => 1; /// /// Gets the median of the distribution. /// - 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)); /// /// Gets the smallest element in the domain of the distributions which can be represented by an integer. /// - public int Minimum - { - get { return 1; } - } + public int Minimum => 1; /// /// Gets the largest element in the domain of the distributions which can be represented by an integer. /// - public int Maximum - { - get { return int.MaxValue; } - } + public int Maximum => int.MaxValue; /// /// Computes the probability mass (PMF) at k, i.e. P(X = k). diff --git a/src/Numerics/Distributions/Hypergeometric.cs b/src/Numerics/Distributions/Hypergeometric.cs index 752e059a..225a2681 100644 --- a/src/Numerics/Distributions/Hypergeometric.cs +++ b/src/Numerics/Distributions/Hypergeometric.cs @@ -115,105 +115,69 @@ namespace MathNet.Numerics.Distributions /// public System.Random RandomSource { - get { return _random; } - set { _random = value ?? SystemRandomSource.Default; } + get => _random; + set => _random = value ?? SystemRandomSource.Default; } /// /// Gets the size of the population (N). /// - public int Population - { - get { return _population; } - } + public int Population => _population; /// /// Gets the number of draws without replacement (n). /// - public int Draws - { - get { return _draws; } - } + public int Draws => _draws; /// /// Gets the number successes within the population (K, M). /// - public int Success - { - get { return _success; } - } + public int Success => _success; /// /// Gets the mean of the distribution. /// - public double Mean - { - get { return (double)_success*_draws/_population; } - } + public double Mean => (double)_success*_draws/_population; /// /// Gets the variance of the distribution. /// - 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)); /// /// Gets the standard deviation of the distribution. /// - public double StdDev - { - get { return Math.Sqrt(Variance); } - } + public double StdDev => Math.Sqrt(Variance); /// /// Gets the entropy of the distribution. /// - public double Entropy - { - get { throw new NotSupportedException(); } - } + public double Entropy => throw new NotSupportedException(); /// /// Gets the skewness of the distribution. /// - 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)); /// /// Gets the mode of the distribution. /// - public int Mode - { - get { return (_draws + 1)*(_success + 1)/(_population + 2); } - } + public int Mode => (_draws + 1)*(_success + 1)/(_population + 2); /// /// Gets the median of the distribution. /// - public double Median - { - get { throw new NotSupportedException(); } - } + public double Median => throw new NotSupportedException(); /// /// Gets the minimum of the distribution. /// - public int Minimum - { - get { return Math.Max(0, _draws + _success - _population); } - } + public int Minimum => Math.Max(0, _draws + _success - _population); /// /// Gets the maximum of the distribution. /// - public int Maximum - { - get { return Math.Min(_success, _draws); } - } + public int Maximum => Math.Min(_success, _draws); /// /// Computes the probability mass (PMF) at k, i.e. P(X = k). diff --git a/src/Numerics/Distributions/InverseGamma.cs b/src/Numerics/Distributions/InverseGamma.cs index f751993f..90dbf58e 100644 --- a/src/Numerics/Distributions/InverseGamma.cs +++ b/src/Numerics/Distributions/InverseGamma.cs @@ -106,26 +106,20 @@ namespace MathNet.Numerics.Distributions /// /// Gets or sets the shape (α) parameter. Range: α > 0. /// - public double Shape - { - get { return _shape; } - } + public double Shape => _shape; /// /// Gets or sets The scale (β) parameter. Range: β > 0. /// - public double Scale - { - get { return _scale; } - } + public double Scale => _scale; /// /// Gets or sets the random number generator which is used to draw random samples. /// public System.Random RandomSource { - get { return _random; } - set { _random = value ?? SystemRandomSource.Default; } + get => _random; + set => _random = value ?? SystemRandomSource.Default; } /// @@ -163,18 +157,12 @@ namespace MathNet.Numerics.Distributions /// /// Gets the standard deviation of the distribution. /// - 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)); /// /// Gets the entropy of the distribution. /// - 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)); /// /// Gets the skewness of the distribution. @@ -195,35 +183,23 @@ namespace MathNet.Numerics.Distributions /// /// Gets the mode of the distribution. /// - public double Mode - { - get { return _scale/(_shape + 1.0); } - } + public double Mode => _scale/(_shape + 1.0); /// /// Gets the median of the distribution. /// /// Throws . - public double Median - { - get { throw new NotSupportedException(); } - } + public double Median => throw new NotSupportedException(); /// /// Gets the minimum of the distribution. /// - public double Minimum - { - get { return 0.0; } - } + public double Minimum => 0.0; /// /// Gets the maximum of the distribution. /// - public double Maximum - { - get { return double.PositiveInfinity; } - } + public double Maximum => double.PositiveInfinity; /// /// Computes the probability density of the distribution (PDF) at x, i.e. ∂P(X ≤ x)/∂x. diff --git a/src/Numerics/Distributions/InverseGaussian.cs b/src/Numerics/Distributions/InverseGaussian.cs index 4355ccac..9eb4541a 100644 --- a/src/Numerics/Distributions/InverseGaussian.cs +++ b/src/Numerics/Distributions/InverseGaussian.cs @@ -92,99 +92,60 @@ namespace MathNet.Numerics.Distributions /// public System.Random RandomSource { - get { return _random; } - set { _random = value ?? SystemRandomSource.Default; } + get => _random; + set => _random = value ?? SystemRandomSource.Default; } /// /// Gets the mean of the Inverse Gaussian distribution. /// - public double Mean - { - get - { - return Mu; - } - } + public double Mean => Mu; /// /// Gets the variance of the Inverse Gaussian distribution. /// - public double Variance - { - get - { - return Math.Pow(Mu, 3) / Lambda; - } - } + public double Variance => Math.Pow(Mu, 3) / Lambda; /// /// Gets the standard deviation of the Inverse Gaussian distribution. /// - public double StdDev - { - get - { - return Math.Sqrt(Variance); - } - } + public double StdDev => Math.Sqrt(Variance); /// /// 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. /// - public double Median - { - get { return InvCDF(0.5); } - } + public double Median => InvCDF(0.5); /// /// Gets the minimum of the Inverse Gaussian distribution. /// - public double Minimum - { - get { return 0.0; } - } + public double Minimum => 0.0; /// /// Gets the maximum of the Inverse Gaussian distribution. /// - public double Maximum - { - get { return double.PositiveInfinity; } - } + public double Maximum => double.PositiveInfinity; /// /// Gets the skewness of the Inverse Gaussian distribution. /// - public double Skewness - { - get { return 3 * Math.Sqrt(Mu / Lambda); } - } + public double Skewness => 3 * Math.Sqrt(Mu / Lambda); /// /// Gets the kurtosis of the Inverse Gaussian distribution. /// - public double Kurtosis - { - get { return 15 * Mu / Lambda; } - } + public double Kurtosis => 15 * Mu / Lambda; /// /// Gets the mode of the Inverse Gaussian distribution. /// - 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)); /// /// Gets the entropy of the Inverse Gaussian distribution (currently not supported). /// - public double Entropy - { - get { throw new NotSupportedException(); } - } + public double Entropy => throw new NotSupportedException(); /// /// Generates a sample from the inverse Gaussian distribution. diff --git a/src/Numerics/Distributions/InverseWishart.cs b/src/Numerics/Distributions/InverseWishart.cs index 4d1eddd8..34142abf 100644 --- a/src/Numerics/Distributions/InverseWishart.cs +++ b/src/Numerics/Distributions/InverseWishart.cs @@ -125,46 +125,34 @@ namespace MathNet.Numerics.Distributions /// /// Gets or sets the degree of freedom (ν) for the inverse Wishart distribution. /// - public double DegreesOfFreedom - { - get { return _freedom; } - } + public double DegreesOfFreedom => _freedom; /// /// Gets or sets the scale matrix (Ψ) for the inverse Wishart distribution. /// - public Matrix Scale - { - get { return _scale; } - } + public Matrix Scale => _scale; /// /// Gets or sets the random number generator which is used to draw random samples. /// public System.Random RandomSource { - get { return _random; } - set { _random = value ?? SystemRandomSource.Default; } + get => _random; + set => _random = value ?? SystemRandomSource.Default; } /// /// Gets the mean. /// /// The mean of the distribution. - public Matrix Mean - { - get { return _scale*(1.0/(_freedom - _scale.RowCount - 1.0)); } - } + public Matrix Mean => _scale*(1.0/(_freedom - _scale.RowCount - 1.0)); /// /// Gets the mode of the distribution. /// /// The mode of the distribution. /// 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. - public Matrix Mode - { - get { return _scale*(1.0/(_freedom + _scale.RowCount + 1.0)); } - } + public Matrix Mode => _scale*(1.0/(_freedom + _scale.RowCount + 1.0)); /// /// Gets the variance of the distribution. diff --git a/src/Numerics/Distributions/Laplace.cs b/src/Numerics/Distributions/Laplace.cs index b7bd86db..203777bf 100644 --- a/src/Numerics/Distributions/Laplace.cs +++ b/src/Numerics/Distributions/Laplace.cs @@ -116,99 +116,66 @@ namespace MathNet.Numerics.Distributions /// /// Gets the location (μ) of the Laplace distribution. /// - public double Location - { - get { return _location; } - } + public double Location => _location; /// /// Gets the scale (b) of the Laplace distribution. Range: b > 0. /// - public double Scale - { - get { return _scale; } - } + public double Scale => _scale; /// /// Gets or sets the random number generator which is used to draw random samples. /// public System.Random RandomSource { - get { return _random; } - set { _random = value ?? SystemRandomSource.Default; } + get => _random; + set => _random = value ?? SystemRandomSource.Default; } /// /// Gets the mean of the distribution. /// - public double Mean - { - get { return _location; } - } + public double Mean => _location; /// /// Gets the variance of the distribution. /// - public double Variance - { - get { return 2.0*_scale*_scale; } - } + public double Variance => 2.0*_scale*_scale; /// /// Gets the standard deviation of the distribution. /// - public double StdDev - { - get { return Constants.Sqrt2*_scale; } - } + public double StdDev => Constants.Sqrt2*_scale; /// /// Gets the entropy of the distribution. /// - public double Entropy - { - get { return Math.Log(2.0*Constants.E*_scale); } - } + public double Entropy => Math.Log(2.0*Constants.E*_scale); /// /// Gets the skewness of the distribution. /// - public double Skewness - { - get { return 0.0; } - } + public double Skewness => 0.0; /// /// Gets the mode of the distribution. /// - public double Mode - { - get { return _location; } - } + public double Mode => _location; /// /// Gets the median of the distribution. /// - public double Median - { - get { return _location; } - } + public double Median => _location; /// /// Gets the minimum of the distribution. /// - public double Minimum - { - get { return double.NegativeInfinity; } - } + public double Minimum => double.NegativeInfinity; /// /// Gets the maximum of the distribution. /// - public double Maximum - { - get { return double.PositiveInfinity; } - } + public double Maximum => double.PositiveInfinity; /// /// Computes the probability density of the distribution (PDF) at x, i.e. ∂P(X ≤ x)/∂x. diff --git a/src/Numerics/Distributions/LogNormal.cs b/src/Numerics/Distributions/LogNormal.cs index b774175c..b4916538 100644 --- a/src/Numerics/Distributions/LogNormal.cs +++ b/src/Numerics/Distributions/LogNormal.cs @@ -148,35 +148,26 @@ namespace MathNet.Numerics.Distributions /// /// Gets the log-scale (μ) (mean of the logarithm) of the distribution. /// - public double Mu - { - get { return _mu; } - } + public double Mu => _mu; /// /// Gets the shape (σ) (standard deviation of the logarithm) of the distribution. Range: σ ≥ 0. /// - public double Sigma - { - get { return _sigma; } - } + public double Sigma => _sigma; /// /// Gets or sets the random number generator which is used to draw random samples. /// public System.Random RandomSource { - get { return _random; } - set { _random = value ?? SystemRandomSource.Default; } + get => _random; + set => _random = value ?? SystemRandomSource.Default; } /// /// Gets the mu of the log-normal distribution. /// - public double Mean - { - get { return Math.Exp(_mu + (_sigma*_sigma/2.0)); } - } + public double Mean => Math.Exp(_mu + (_sigma*_sigma/2.0)); /// /// Gets the variance of the log-normal distribution. @@ -205,10 +196,7 @@ namespace MathNet.Numerics.Distributions /// /// Gets the entropy of the log-normal distribution. /// - public double Entropy - { - get { return 0.5 + Math.Log(_sigma) + _mu + Constants.LogSqrt2Pi; } - } + public double Entropy => 0.5 + Math.Log(_sigma) + _mu + Constants.LogSqrt2Pi; /// /// Gets the skewness of the log-normal distribution. @@ -225,34 +213,22 @@ namespace MathNet.Numerics.Distributions /// /// Gets the mode of the log-normal distribution. /// - public double Mode - { - get { return Math.Exp(_mu - (_sigma*_sigma)); } - } + public double Mode => Math.Exp(_mu - (_sigma*_sigma)); /// /// Gets the median of the log-normal distribution. /// - public double Median - { - get { return Math.Exp(_mu); } - } + public double Median => Math.Exp(_mu); /// /// Gets the minimum of the log-normal distribution. /// - public double Minimum - { - get { return 0.0; } - } + public double Minimum => 0.0; /// /// Gets the maximum of the log-normal distribution. /// - public double Maximum - { - get { return double.PositiveInfinity; } - } + public double Maximum => double.PositiveInfinity; /// /// Computes the probability density of the distribution (PDF) at x, i.e. ∂P(X ≤ x)/∂x. diff --git a/src/Numerics/Distributions/MatrixNormal.cs b/src/Numerics/Distributions/MatrixNormal.cs index adcd1c65..5ffc2b0e 100644 --- a/src/Numerics/Distributions/MatrixNormal.cs +++ b/src/Numerics/Distributions/MatrixNormal.cs @@ -155,36 +155,27 @@ namespace MathNet.Numerics.Distributions /// Gets the mean. (M) /// /// The mean of the distribution. - public Matrix Mean - { - get { return _m; } - } + public Matrix Mean => _m; /// /// Gets the row covariance. (V) /// /// The row covariance. - public Matrix RowCovariance - { - get { return _v; } - } + public Matrix RowCovariance => _v; /// /// Gets the column covariance. (K) /// /// The column covariance. - public Matrix ColumnCovariance - { - get { return _k; } - } + public Matrix ColumnCovariance => _k; /// /// Gets or sets the random number generator which is used to draw random samples. /// public System.Random RandomSource { - get { return _random; } - set { _random = value ?? SystemRandomSource.Default; } + get => _random; + set => _random = value ?? SystemRandomSource.Default; } /// diff --git a/src/Numerics/Distributions/Multinomial.cs b/src/Numerics/Distributions/Multinomial.cs index 00ef5d21..3879e8ff 100644 --- a/src/Numerics/Distributions/Multinomial.cs +++ b/src/Numerics/Distributions/Multinomial.cs @@ -177,35 +177,26 @@ namespace MathNet.Numerics.Distributions /// /// Gets the proportion of ratios. /// - public double[] P - { - get { return (double[])_p.Clone(); } - } + public double[] P => (double[])_p.Clone(); /// /// Gets the number of trials. /// - public int N - { - get { return _trials; } - } + public int N => _trials; /// /// Gets or sets the random number generator which is used to draw random samples. /// public System.Random RandomSource { - get { return _random; } - set { _random = value ?? SystemRandomSource.Default; } + get => _random; + set => _random = value ?? SystemRandomSource.Default; } /// /// Gets the mean of the distribution. /// - public Vector Mean - { - get { return _trials*(DenseVector)P; } - } + public Vector Mean => _trials*(DenseVector)P; /// /// Gets the variance of the distribution. diff --git a/src/Numerics/Distributions/NegativeBinomial.cs b/src/Numerics/Distributions/NegativeBinomial.cs index 8fdd1fb9..d2b48eee 100644 --- a/src/Numerics/Distributions/NegativeBinomial.cs +++ b/src/Numerics/Distributions/NegativeBinomial.cs @@ -107,99 +107,66 @@ namespace MathNet.Numerics.Distributions /// /// Gets the number of successes. Range: r ≥ 0. /// - public double R - { - get { return _r; } - } + public double R => _r; /// /// Gets the probability of success. Range: 0 ≤ p ≤ 1. /// - public double P - { - get { return _p; } - } + public double P => _p; /// /// Gets or sets the random number generator which is used to draw random samples. /// public System.Random RandomSource { - get { return _random; } - set { _random = value ?? SystemRandomSource.Default; } + get => _random; + set => _random = value ?? SystemRandomSource.Default; } /// /// Gets the mean of the distribution. /// - public double Mean - { - get { return _r*(1.0 - _p)/_p; } - } + public double Mean => _r*(1.0 - _p)/_p; /// /// Gets the variance of the distribution. /// - public double Variance - { - get { return _r*(1.0 - _p)/(_p*_p); } - } + public double Variance => _r*(1.0 - _p)/(_p*_p); /// /// Gets the standard deviation of the distribution. /// - public double StdDev - { - get { return Math.Sqrt(_r*(1.0 - _p))/_p; } - } + public double StdDev => Math.Sqrt(_r*(1.0 - _p))/_p; /// /// Gets the entropy of the distribution. /// - public double Entropy - { - get { throw new NotSupportedException(); } - } + public double Entropy => throw new NotSupportedException(); /// /// Gets the skewness of the distribution. /// - 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)); /// /// Gets the mode of the distribution /// - 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; /// /// Gets the median of the distribution. /// - public double Median - { - get { throw new NotSupportedException(); } - } + public double Median => throw new NotSupportedException(); /// /// Gets the smallest element in the domain of the distributions which can be represented by an integer. /// - public int Minimum - { - get { return 0; } - } + public int Minimum => 0; /// /// Gets the largest element in the domain of the distributions which can be represented by an integer. /// - public int Maximum - { - get { return int.MaxValue; } - } + public int Maximum => int.MaxValue; /// /// Computes the probability mass (PMF) at k, i.e. P(X = k). diff --git a/src/Numerics/Distributions/Normal.cs b/src/Numerics/Distributions/Normal.cs index 65b2ecde..1a465827 100644 --- a/src/Numerics/Distributions/Normal.cs +++ b/src/Numerics/Distributions/Normal.cs @@ -176,91 +176,61 @@ namespace MathNet.Numerics.Distributions /// /// Gets the mean (μ) of the normal distribution. /// - public double Mean - { - get { return _mean; } - } + public double Mean => _mean; /// /// Gets the standard deviation (σ) of the normal distribution. Range: σ ≥ 0. /// - public double StdDev - { - get { return _stdDev; } - } + public double StdDev => _stdDev; /// /// Gets the variance of the normal distribution. /// - public double Variance - { - get { return _stdDev*_stdDev; } - } + public double Variance => _stdDev*_stdDev; /// /// Gets the precision of the normal distribution. /// - public double Precision - { - get { return 1.0/(_stdDev*_stdDev); } - } + public double Precision => 1.0/(_stdDev*_stdDev); /// /// Gets the random number generator which is used to draw random samples. /// public System.Random RandomSource { - get { return _random; } - set { _random = value ?? SystemRandomSource.Default; } + get => _random; + set => _random = value ?? SystemRandomSource.Default; } /// /// Gets the entropy of the normal distribution. /// - public double Entropy - { - get { return Math.Log(_stdDev) + Constants.LogSqrt2PiE; } - } + public double Entropy => Math.Log(_stdDev) + Constants.LogSqrt2PiE; /// /// Gets the skewness of the normal distribution. /// - public double Skewness - { - get { return 0.0; } - } + public double Skewness => 0.0; /// /// Gets the mode of the normal distribution. /// - public double Mode - { - get { return _mean; } - } + public double Mode => _mean; /// /// Gets the median of the normal distribution. /// - public double Median - { - get { return _mean; } - } + public double Median => _mean; /// /// Gets the minimum of the normal distribution. /// - public double Minimum - { - get { return double.NegativeInfinity; } - } + public double Minimum => double.NegativeInfinity; /// /// Gets the maximum of the normal distribution. /// - public double Maximum - { - get { return double.PositiveInfinity; } - } + public double Maximum => double.PositiveInfinity; /// /// Computes the probability density of the distribution (PDF) at x, i.e. ∂P(X ≤ x)/∂x. diff --git a/src/Numerics/Distributions/NormalGamma.cs b/src/Numerics/Distributions/NormalGamma.cs index f3f2819d..f345faee 100644 --- a/src/Numerics/Distributions/NormalGamma.cs +++ b/src/Numerics/Distributions/NormalGamma.cs @@ -40,16 +40,6 @@ namespace MathNet.Numerics.Distributions /// public struct MeanPrecisionPair { - /// - /// The mean value. - /// - double _mean; - - /// - /// The precision value. - /// - double _precision; - /// /// Initializes a new instance of the struct. /// @@ -57,27 +47,19 @@ namespace MathNet.Numerics.Distributions /// The precision of the pair. public MeanPrecisionPair(double m, double p) { - _mean = m; - _precision = p; + Mean = m; + Precision = p; } /// /// Gets or sets the mean of the pair. /// - public double Mean - { - get { return _mean; } - set { _mean = value; } - } + public double Mean { get; set; } /// /// Gets or sets the precision of the pair. /// - public double Precision - { - get { return _precision; } - set { _precision = value; } - } + public double Precision { get; set; } } /// @@ -170,42 +152,30 @@ namespace MathNet.Numerics.Distributions /// /// Gets the location of the mean. /// - public double MeanLocation - { - get { return _meanLocation; } - } + public double MeanLocation => _meanLocation; /// /// Gets the scale of the mean. /// - public double MeanScale - { - get { return _meanScale; } - } + public double MeanScale => _meanScale; /// /// Gets the shape of the precision. /// - public double PrecisionShape - { - get { return _precisionShape; } - } + public double PrecisionShape => _precisionShape; /// /// Gets the inverse scale of the precision. /// - public double PrecisionInverseScale - { - get { return _precisionInvScale; } - } + public double PrecisionInverseScale => _precisionInvScale; /// /// Gets or sets the random number generator which is used to draw random samples. /// public System.Random RandomSource { - get { return _random; } - set { _random = value ?? SystemRandomSource.Default; } + get => _random; + set => _random = value ?? SystemRandomSource.Default; } /// @@ -235,19 +205,13 @@ namespace MathNet.Numerics.Distributions /// Gets the mean of the distribution. /// /// The mean of the distribution. - 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); /// /// Gets the variance of the distribution. /// /// The mean of the distribution. - 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)); /// /// Evaluates the probability density function for a NormalGamma distribution. diff --git a/src/Numerics/Distributions/Pareto.cs b/src/Numerics/Distributions/Pareto.cs index a10b6330..35093854 100644 --- a/src/Numerics/Distributions/Pareto.cs +++ b/src/Numerics/Distributions/Pareto.cs @@ -109,26 +109,20 @@ namespace MathNet.Numerics.Distributions /// /// Gets the scale (xm) of the distribution. Range: xm > 0. /// - public double Scale - { - get { return _scale; } - } + public double Scale => _scale; /// /// Gets the shape (α) of the distribution. Range: α > 0. /// - public double Shape - { - get { return _shape; } - } + public double Shape => _shape; /// /// Gets or sets the random number generator which is used to draw random samples. /// public System.Random RandomSource { - get { return _random; } - set { _random = value ?? SystemRandomSource.Default; } + get => _random; + set => _random = value ?? SystemRandomSource.Default; } /// @@ -166,58 +160,37 @@ namespace MathNet.Numerics.Distributions /// /// Gets the standard deviation of the distribution. /// - 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)); /// /// Gets the entropy of the distribution. /// - 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; /// /// Gets the skewness of the distribution. /// - 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); /// /// Gets the mode of the distribution. /// - public double Mode - { - get { return _scale; } - } + public double Mode => _scale; /// /// Gets the median of the distribution. /// - public double Median - { - get { return _scale*Math.Pow(2.0, 1.0/_shape); } - } + public double Median => _scale*Math.Pow(2.0, 1.0/_shape); /// /// Gets the minimum of the distribution. /// - public double Minimum - { - get { return _scale; } - } + public double Minimum => _scale; /// /// Gets the maximum of the distribution. /// - public double Maximum - { - get { return double.PositiveInfinity; } - } + public double Maximum => double.PositiveInfinity; /// /// Computes the probability density of the distribution (PDF) at x, i.e. ∂P(X ≤ x)/∂x. diff --git a/src/Numerics/Distributions/Poisson.cs b/src/Numerics/Distributions/Poisson.cs index 3bbaacd8..94dafbef 100644 --- a/src/Numerics/Distributions/Poisson.cs +++ b/src/Numerics/Distributions/Poisson.cs @@ -104,93 +104,63 @@ namespace MathNet.Numerics.Distributions /// /// Gets the Poisson distribution parameter λ. Range: λ > 0. /// - public double Lambda - { - get { return _lambda; } - } + public double Lambda => _lambda; /// /// Gets the random number generator which is used to draw random samples. /// public System.Random RandomSource { - get { return _random; } - set { _random = value ?? SystemRandomSource.Default; } + get => _random; + set => _random = value ?? SystemRandomSource.Default; } /// /// Gets the mean of the distribution. /// - public double Mean - { - get { return _lambda; } - } + public double Mean => _lambda; /// /// Gets the variance of the distribution. /// - public double Variance - { - get { return _lambda; } - } + public double Variance => _lambda; /// /// Gets the standard deviation of the distribution. /// - public double StdDev - { - get { return Math.Sqrt(_lambda); } - } + public double StdDev => Math.Sqrt(_lambda); /// /// Gets the entropy of the distribution. /// /// Approximation, see Wikipedia Poisson distribution - 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)); /// /// Gets the skewness of the distribution. /// - public double Skewness - { - get { return 1.0/Math.Sqrt(_lambda); } - } + public double Skewness => 1.0/Math.Sqrt(_lambda); /// /// Gets the smallest element in the domain of the distributions which can be represented by an integer. /// - public int Minimum - { - get { return 0; } - } + public int Minimum => 0; /// /// Gets the largest element in the domain of the distributions which can be represented by an integer. /// - public int Maximum - { - get { return int.MaxValue; } - } + public int Maximum => int.MaxValue; /// /// Gets the mode of the distribution. /// - public int Mode - { - get { return (int)Math.Floor(_lambda); } - } + public int Mode => (int)Math.Floor(_lambda); /// /// Gets the median of the distribution. /// /// Approximation, see Wikipedia Poisson distribution - 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)); /// /// Computes the probability mass (PMF) at k, i.e. P(X = k). diff --git a/src/Numerics/Distributions/Rayleigh.cs b/src/Numerics/Distributions/Rayleigh.cs index 47c5fcb5..3c4e0bd8 100644 --- a/src/Numerics/Distributions/Rayleigh.cs +++ b/src/Numerics/Distributions/Rayleigh.cs @@ -104,91 +104,61 @@ namespace MathNet.Numerics.Distributions /// /// Gets the scale (σ) of the distribution. Range: σ > 0. /// - public double Scale - { - get { return _scale; } - } + public double Scale => _scale; /// /// Gets or sets the random number generator which is used to draw random samples. /// public System.Random RandomSource { - get { return _random; } - set { _random = value ?? SystemRandomSource.Default; } + get => _random; + set => _random = value ?? SystemRandomSource.Default; } /// /// Gets the mean of the distribution. /// - public double Mean - { - get { return _scale*Math.Sqrt(Constants.PiOver2); } - } + public double Mean => _scale*Math.Sqrt(Constants.PiOver2); /// /// Gets the variance of the distribution. /// - public double Variance - { - get { return (2.0 - Constants.PiOver2)*_scale*_scale; } - } + public double Variance => (2.0 - Constants.PiOver2)*_scale*_scale; /// /// Gets the standard deviation of the distribution. /// - public double StdDev - { - get { return Math.Sqrt(2.0 - Constants.PiOver2)*_scale; } - } + public double StdDev => Math.Sqrt(2.0 - Constants.PiOver2)*_scale; /// /// Gets the entropy of the distribution. /// - 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); /// /// Gets the skewness of the distribution. /// - 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); /// /// Gets the mode of the distribution. /// - public double Mode - { - get { return _scale; } - } + public double Mode => _scale; /// /// Gets the median of the distribution. /// - public double Median - { - get { return _scale*Math.Sqrt(Math.Log(4.0)); } - } + public double Median => _scale*Math.Sqrt(Math.Log(4.0)); /// /// Gets the minimum of the distribution. /// - public double Minimum - { - get { return 0.0; } - } + public double Minimum => 0.0; /// /// Gets the maximum of the distribution. /// - public double Maximum - { - get { return double.PositiveInfinity; } - } + public double Maximum => double.PositiveInfinity; /// /// Computes the probability density of the distribution (PDF) at x, i.e. ∂P(X ≤ x)/∂x. diff --git a/src/Numerics/Distributions/Stable.cs b/src/Numerics/Distributions/Stable.cs index 016e8cd7..13299e6b 100644 --- a/src/Numerics/Distributions/Stable.cs +++ b/src/Numerics/Distributions/Stable.cs @@ -118,42 +118,30 @@ namespace MathNet.Numerics.Distributions /// /// Gets the stability (α) of the distribution. Range: 2 ≥ α > 0. /// - public double Alpha - { - get { return _alpha; } - } + public double Alpha => _alpha; /// /// Gets The skewness (β) of the distribution. Range: 1 ≥ β ≥ -1. /// - public double Beta - { - get { return _beta; } - } + public double Beta => _beta; /// /// Gets the scale (c) of the distribution. Range: c > 0. /// - public double Scale - { - get { return _scale; } - } + public double Scale => _scale; /// /// Gets the location (μ) of the distribution. /// - public double Location - { - get { return _location; } - } + public double Location => _location; /// /// Gets or sets the random number generator which is used to draw random samples. /// public System.Random RandomSource { - get { return _random; } - set { _random = value ?? SystemRandomSource.Default; } + get => _random; + set => _random = value ?? SystemRandomSource.Default; } /// @@ -208,10 +196,7 @@ namespace MathNet.Numerics.Distributions /// Gets he entropy of the distribution. /// /// Always throws a not supported exception. - public double Entropy - { - get { throw new NotSupportedException(); } - } + public double Entropy => throw new NotSupportedException(); /// /// Gets the skewness of the distribution. @@ -283,10 +268,7 @@ namespace MathNet.Numerics.Distributions /// /// Gets the maximum of the distribution. /// - public double Maximum - { - get { return double.PositiveInfinity; } - } + public double Maximum => double.PositiveInfinity; /// /// Computes the probability density of the distribution (PDF) at x, i.e. ∂P(X ≤ x)/∂x. diff --git a/src/Numerics/Distributions/StudentT.cs b/src/Numerics/Distributions/StudentT.cs index 42241327..b51b9650 100644 --- a/src/Numerics/Distributions/StudentT.cs +++ b/src/Numerics/Distributions/StudentT.cs @@ -140,43 +140,31 @@ namespace MathNet.Numerics.Distributions /// /// Gets the location (μ) of the Student t-distribution. /// - public double Location - { - get { return _location; } - } + public double Location => _location; /// /// Gets the scale (σ) of the Student t-distribution. Range: σ > 0. /// - public double Scale - { - get { return _scale; } - } + public double Scale => _scale; /// /// Gets the degrees of freedom (ν) of the Student t-distribution. Range: ν > 0. /// - public double DegreesOfFreedom - { - get { return _freedom; } - } + public double DegreesOfFreedom => _freedom; /// /// Gets or sets the random number generator which is used to draw random samples. /// public System.Random RandomSource { - get { return _random; } - set { _random = value ?? SystemRandomSource.Default; } + get => _random; + set => _random = value ?? SystemRandomSource.Default; } /// /// Gets the mean of the Student t-distribution. /// - public double Mean - { - get { return _freedom > 1.0 ? _location : double.NaN; } - } + public double Mean => _freedom > 1.0 ? _location : double.NaN; /// /// Gets the variance of the Student t-distribution. @@ -256,34 +244,22 @@ namespace MathNet.Numerics.Distributions /// /// Gets the mode of the Student t-distribution. /// - public double Mode - { - get { return _location; } - } + public double Mode => _location; /// /// Gets the median of the Student t-distribution. /// - public double Median - { - get { return _location; } - } + public double Median => _location; /// /// Gets the minimum of the Student t-distribution. /// - public double Minimum - { - get { return double.NegativeInfinity; } - } + public double Minimum => double.NegativeInfinity; /// /// Gets the maximum of the Student t-distribution. /// - public double Maximum - { - get { return double.PositiveInfinity; } - } + public double Maximum => double.PositiveInfinity; /// /// Computes the probability density of the distribution (PDF) at x, i.e. ∂P(X ≤ x)/∂x. diff --git a/src/Numerics/Distributions/Triangular.cs b/src/Numerics/Distributions/Triangular.cs index d7c9e031..48be7c5c 100644 --- a/src/Numerics/Distributions/Triangular.cs +++ b/src/Numerics/Distributions/Triangular.cs @@ -116,35 +116,26 @@ namespace MathNet.Numerics.Distributions /// /// Gets the lower bound of the distribution. /// - public double LowerBound - { - get { return _lower; } - } + public double LowerBound => _lower; /// /// Gets the upper bound of the distribution. /// - public double UpperBound - { - get { return _upper; } - } + public double UpperBound => _upper; /// /// Gets or sets the random number generator which is used to draw random samples. /// public System.Random RandomSource { - get { return _random; } - set { _random = value ?? SystemRandomSource.Default; } + get => _random; + set => _random = value ?? SystemRandomSource.Default; } /// /// Gets the mean of the distribution. /// - public double Mean - { - get { return (_lower + _upper + _mode)/3.0; } - } + public double Mean => (_lower + _upper + _mode)/3.0; /// /// Gets the variance of the distribution. @@ -163,19 +154,13 @@ namespace MathNet.Numerics.Distributions /// /// Gets the standard deviation of the distribution. /// - public double StdDev - { - get { return Math.Sqrt(Variance); } - } + public double StdDev => Math.Sqrt(Variance); /// /// Gets the entropy of the distribution. /// /// - public double Entropy - { - get { return 0.5 + Math.Log((_upper - _lower)/2); } - } + public double Entropy => 0.5 + Math.Log((_upper - _lower)/2); /// /// Gets the skewness of the distribution. @@ -196,10 +181,7 @@ namespace MathNet.Numerics.Distributions /// /// Gets or sets the mode of the distribution. /// - public double Mode - { - get { return _mode; } - } + public double Mode => _mode; /// /// Gets the median of the distribution. @@ -221,18 +203,12 @@ namespace MathNet.Numerics.Distributions /// /// Gets the minimum of the distribution. /// - public double Minimum - { - get { return _lower; } - } + public double Minimum => _lower; /// /// Gets the maximum of the distribution. /// - public double Maximum - { - get { return _upper; } - } + public double Maximum => _upper; /// /// Computes the probability density of the distribution (PDF) at x, i.e. ∂P(X ≤ x)/∂x. diff --git a/src/Numerics/Distributions/TruncatedPareto.cs b/src/Numerics/Distributions/TruncatedPareto.cs index 62190733..1edcd190 100644 --- a/src/Numerics/Distributions/TruncatedPareto.cs +++ b/src/Numerics/Distributions/TruncatedPareto.cs @@ -84,8 +84,8 @@ namespace MathNet.Numerics.Distributions /// public System.Random RandomSource { - get { return _random; } - set { _random = value ?? SystemRandomSource.Default; } + get => _random; + set => _random = value ?? SystemRandomSource.Default; } /// @@ -126,67 +126,37 @@ namespace MathNet.Numerics.Distributions /// /// Gets the mean of the truncated Pareto distribution. /// - public double Mean - { - get - { - return GetMoment(1); - } - } + public double Mean => GetMoment(1); /// /// Gets the variance of the truncated Pareto distribution. /// - public double Variance - { - get - { - return GetMoment(2) - Math.Pow(GetMoment(1), 2); - } - } + public double Variance => GetMoment(2) - Math.Pow(GetMoment(1), 2); /// /// Gets the standard deviation of the truncated Pareto distribution. /// - public double StdDev - { - get - { - return Math.Sqrt(Variance); - } - } + public double StdDev => Math.Sqrt(Variance); /// /// Gets the mode of the truncated Pareto distribution (not supported). /// - public double Mode - { - get { throw new NotSupportedException(); } - } + public double Mode => throw new NotSupportedException(); /// /// Gets the minimum of the truncated Pareto distribution. /// - public double Minimum - { - get { return Scale; } - } + public double Minimum => Scale; /// /// Gets the maximum of the truncated Pareto distribution. /// - public double Maximum - { - get { return Truncation; } - } + public double Maximum => Truncation; /// /// Gets the entropy of the truncated Pareto distribution (not supported). /// - public double Entropy - { - get { throw new NotSupportedException(); } - } + public double Entropy => throw new NotSupportedException(); /// /// Gets the skewness of the truncated Pareto distribution. @@ -205,13 +175,7 @@ namespace MathNet.Numerics.Distributions /// /// Gets the median of the truncated Pareto distribution. /// - 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)); /// /// Generates a sample from the truncated Pareto distribution. diff --git a/src/Numerics/Distributions/Weibull.cs b/src/Numerics/Distributions/Weibull.cs index 9abdbda9..9c377be0 100644 --- a/src/Numerics/Distributions/Weibull.cs +++ b/src/Numerics/Distributions/Weibull.cs @@ -119,59 +119,41 @@ namespace MathNet.Numerics.Distributions /// /// Gets the shape (k) of the Weibull distribution. Range: k > 0. /// - public double Shape - { - get { return _shape; } - } + public double Shape => _shape; /// /// Gets the scale (λ) of the Weibull distribution. Range: λ > 0. /// - public double Scale - { - get { return _scale; } - } + public double Scale => _scale; /// /// Gets or sets the random number generator which is used to draw random samples. /// public System.Random RandomSource { - get { return _random; } - set { _random = value ?? SystemRandomSource.Default; } + get => _random; + set => _random = value ?? SystemRandomSource.Default; } /// /// Gets the mean of the Weibull distribution. /// - public double Mean - { - get { return _scale*SpecialFunctions.Gamma(1.0 + (1.0/_shape)); } - } + public double Mean => _scale*SpecialFunctions.Gamma(1.0 + (1.0/_shape)); /// /// Gets the variance of the Weibull distribution. /// - 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); /// /// Gets the standard deviation of the Weibull distribution. /// - public double StdDev - { - get { return Math.Sqrt(Variance); } - } + public double StdDev => Math.Sqrt(Variance); /// /// Gets the entropy of the Weibull distribution. /// - 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; /// /// Gets the skewness of the Weibull distribution. @@ -207,26 +189,17 @@ namespace MathNet.Numerics.Distributions /// /// Gets the median of the Weibull distribution. /// - public double Median - { - get { return _scale*Math.Pow(Constants.Ln2, 1.0/_shape); } - } + public double Median => _scale*Math.Pow(Constants.Ln2, 1.0/_shape); /// /// Gets the minimum of the Weibull distribution. /// - public double Minimum - { - get { return 0.0; } - } + public double Minimum => 0.0; /// /// Gets the maximum of the Weibull distribution. /// - public double Maximum - { - get { return double.PositiveInfinity; } - } + public double Maximum => double.PositiveInfinity; /// /// Computes the probability density of the distribution (PDF) at x, i.e. ∂P(X ≤ x)/∂x. diff --git a/src/Numerics/Distributions/Wishart.cs b/src/Numerics/Distributions/Wishart.cs index 2b8ee0d5..f2d0a5ba 100644 --- a/src/Numerics/Distributions/Wishart.cs +++ b/src/Numerics/Distributions/Wishart.cs @@ -130,18 +130,12 @@ namespace MathNet.Numerics.Distributions /// /// Gets or sets the degrees of freedom (n) for the Wishart distribution. /// - public double DegreesOfFreedom - { - get { return _degreesOfFreedom; } - } + public double DegreesOfFreedom => _degreesOfFreedom; /// /// Gets or sets the scale matrix (V) for the Wishart distribution. /// - public Matrix Scale - { - get { return _scale; } - } + public Matrix Scale => _scale; /// /// A string representation of the distribution. @@ -157,27 +151,21 @@ namespace MathNet.Numerics.Distributions /// public System.Random RandomSource { - get { return _random; } - set { _random = value ?? SystemRandomSource.Default; } + get => _random; + set => _random = value ?? SystemRandomSource.Default; } /// /// Gets the mean of the distribution. /// /// The mean of the distribution. - public Matrix Mean - { - get { return _degreesOfFreedom*_scale; } - } + public Matrix Mean => _degreesOfFreedom*_scale; /// /// Gets the mode of the distribution. /// /// The mode of the distribution. - public Matrix Mode - { - get { return (_degreesOfFreedom - _scale.RowCount - 1.0)*_scale; } - } + public Matrix Mode => (_degreesOfFreedom - _scale.RowCount - 1.0)*_scale; /// /// Gets the variance of the distribution. diff --git a/src/Numerics/Distributions/Zipf.cs b/src/Numerics/Distributions/Zipf.cs index f24177fd..5f59d9aa 100644 --- a/src/Numerics/Distributions/Zipf.cs +++ b/src/Numerics/Distributions/Zipf.cs @@ -113,35 +113,26 @@ namespace MathNet.Numerics.Distributions /// /// Gets or sets the s parameter of the distribution. /// - public double S - { - get { return _s; } - } + public double S => _s; /// /// Gets or sets the n parameter of the distribution. /// - public int N - { - get { return _n; } - } + public int N => _n; /// /// Gets or sets the random number generator which is used to draw random samples. /// public System.Random RandomSource { - get { return _random; } - set { _random = value ?? SystemRandomSource.Default; } + get => _random; + set => _random = value ?? SystemRandomSource.Default; } /// /// Gets the mean of the distribution. /// - 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); /// /// Gets the variance of the distribution. @@ -164,10 +155,7 @@ namespace MathNet.Numerics.Distributions /// /// Gets the standard deviation of the distribution. /// - public double StdDev - { - get { return Math.Sqrt(Variance); } - } + public double StdDev => Math.Sqrt(Variance); /// /// Gets the entropy of the distribution. @@ -205,34 +193,22 @@ namespace MathNet.Numerics.Distributions /// /// Gets the mode of the distribution. /// - public int Mode - { - get { return 1; } - } + public int Mode => 1; /// /// Gets the median of the distribution. /// - public double Median - { - get { throw new NotSupportedException(); } - } + public double Median => throw new NotSupportedException(); /// /// Gets the smallest element in the domain of the distributions which can be represented by an integer. /// - public int Minimum - { - get { return 1; } - } + public int Minimum => 1; /// /// Gets the largest element in the domain of the distributions which can be represented by an integer. /// - public int Maximum - { - get { return _n; } - } + public int Maximum => _n; /// /// Computes the probability mass (PMF) at k, i.e. P(X = k).