From 95adce4c1fc676d693569e0c1c496991263c54fe Mon Sep 17 00:00:00 2001 From: Christoph Ruegg Date: Thu, 5 Jun 2014 17:28:52 +0200 Subject: [PATCH] Distributions: bring back public static IsValidParameterSet functions --- src/Numerics/Distributions/Bernoulli.cs | 9 ++++ src/Numerics/Distributions/Beta.cs | 10 +++++ src/Numerics/Distributions/Binomial.cs | 10 +++++ src/Numerics/Distributions/Categorical.cs | 4 +- src/Numerics/Distributions/Cauchy.cs | 10 +++++ src/Numerics/Distributions/Chi.cs | 9 ++++ src/Numerics/Distributions/ChiSquared.cs | 9 ++++ .../Distributions/ContinuousUniform.cs | 10 +++++ .../Distributions/ConwayMaxwellPoisson.cs | 10 +++++ src/Numerics/Distributions/Dirichlet.cs | 12 ++---- src/Numerics/Distributions/DiscreteUniform.cs | 10 +++++ src/Numerics/Distributions/Erlang.cs | 10 +++++ src/Numerics/Distributions/Exponential.cs | 9 ++++ src/Numerics/Distributions/FisherSnedecor.cs | 10 +++++ src/Numerics/Distributions/Gamma.cs | 10 +++++ src/Numerics/Distributions/Geometric.cs | 9 ++++ src/Numerics/Distributions/Hypergeometric.cs | 11 +++++ src/Numerics/Distributions/InverseGamma.cs | 10 +++++ src/Numerics/Distributions/InverseWishart.cs | 5 +-- src/Numerics/Distributions/Laplace.cs | 10 +++++ src/Numerics/Distributions/LogNormal.cs | 10 +++++ src/Numerics/Distributions/MatrixNormal.cs | 5 +-- src/Numerics/Distributions/Multinomial.cs | 4 +- .../Distributions/NegativeBinomial.cs | 10 +++++ src/Numerics/Distributions/Normal.cs | 10 +++++ src/Numerics/Distributions/NormalGamma.cs | 7 ++-- src/Numerics/Distributions/Pareto.cs | 10 +++++ src/Numerics/Distributions/Poisson.cs | 9 ++++ src/Numerics/Distributions/Rayleigh.cs | 9 ++++ src/Numerics/Distributions/Stable.cs | 12 ++++++ src/Numerics/Distributions/StudentT.cs | 11 +++++ src/Numerics/Distributions/Triangular.cs | 11 +++++ src/Numerics/Distributions/Weibull.cs | 10 +++++ src/Numerics/Distributions/Wishart.cs | 41 +++++++++---------- src/Numerics/Distributions/Zipf.cs | 10 +++++ 35 files changed, 313 insertions(+), 43 deletions(-) diff --git a/src/Numerics/Distributions/Bernoulli.cs b/src/Numerics/Distributions/Bernoulli.cs index 3820a4e1..390ba0fd 100644 --- a/src/Numerics/Distributions/Bernoulli.cs +++ b/src/Numerics/Distributions/Bernoulli.cs @@ -79,6 +79,15 @@ namespace MathNet.Numerics.Distributions return "Bernoulli(p = " + _p + ")"; } + /// + /// Tests whether the provided values are valid parameters for this distribution. + /// + /// The probability (p) of generating one. Range: 0 ≤ p ≤ 1. + public static bool IsValidParameterSet(double p) + { + return p >= 0.0 && p <= 1.0; + } + /// /// Sets the parameters of the distribution after checking their validity. /// diff --git a/src/Numerics/Distributions/Beta.cs b/src/Numerics/Distributions/Beta.cs index dbf79e5b..b3868572 100644 --- a/src/Numerics/Distributions/Beta.cs +++ b/src/Numerics/Distributions/Beta.cs @@ -88,6 +88,16 @@ namespace MathNet.Numerics.Distributions return "Beta(α = " + _shapeA + ", β = " + _shapeB + ")"; } + /// + /// Tests whether the provided values are valid parameters for this distribution. + /// + /// The α shape parameter of the Beta distribution. Range: α ≥ 0. + /// The β shape parameter of the Beta distribution. Range: β ≥ 0. + public static bool IsValidParameterSet(double a, double b) + { + return a >= 0.0 && b >= 0.0; + } + /// /// Sets the parameters of the distribution after checking their validity. /// diff --git a/src/Numerics/Distributions/Binomial.cs b/src/Numerics/Distributions/Binomial.cs index a069ca1e..688e9b2e 100644 --- a/src/Numerics/Distributions/Binomial.cs +++ b/src/Numerics/Distributions/Binomial.cs @@ -86,6 +86,16 @@ namespace MathNet.Numerics.Distributions return "Binomial(p = " + _p + ", n = " + _trials + ")"; } + /// + /// Tests whether the provided values are valid parameters for this distribution. + /// + /// The success probability (p) in each trial. Range: 0 ≤ p ≤ 1. + /// The number of trials (n). Range: n ≥ 0. + public static bool IsValidParameterSet(double p, int n) + { + return p >= 0.0 && p <= 1.0 && n >= 0; + } + /// /// Sets the parameters of the distribution after checking their validity. /// diff --git a/src/Numerics/Distributions/Categorical.cs b/src/Numerics/Distributions/Categorical.cs index 4394eba2..f0ade93c 100644 --- a/src/Numerics/Distributions/Categorical.cs +++ b/src/Numerics/Distributions/Categorical.cs @@ -123,7 +123,7 @@ namespace MathNet.Numerics.Distributions /// /// An array of nonnegative ratios: this array does not need to be normalized as this is often impossible using floating point arithmetic. /// If any of the probabilities are negative returns false, or if the sum of parameters is 0.0; otherwise true - static bool IsValidProbabilityMass(double[] p) + public static bool IsValidProbabilityMass(double[] p) { var sum = 0.0; for (int i = 0; i < p.Length; i++) @@ -145,7 +145,7 @@ namespace MathNet.Numerics.Distributions /// /// An array of nonnegative ratios: this array does not need to be normalized as this is often impossible using floating point arithmetic. /// If any of the probabilities are negative returns false, or if the sum of parameters is 0.0; otherwise true - static bool IsValidCumulativeDistribution(double[] cdf) + public static bool IsValidCumulativeDistribution(double[] cdf) { var last = 0.0; for (int i = 0; i < cdf.Length; i++) diff --git a/src/Numerics/Distributions/Cauchy.cs b/src/Numerics/Distributions/Cauchy.cs index 7a58c789..5db3835d 100644 --- a/src/Numerics/Distributions/Cauchy.cs +++ b/src/Numerics/Distributions/Cauchy.cs @@ -87,6 +87,16 @@ namespace MathNet.Numerics.Distributions return "Cauchy(x0 = " + _location + ", γ = " + _scale + ")"; } + /// + /// Tests whether the provided values are valid parameters for this distribution. + /// + /// The location (x0) of the distribution. + /// The scale (γ) of the distribution. Range: γ > 0. + public static bool IsValidParameterSet(double location, double scale) + { + return scale > 0.0 && !Double.IsNaN(location); + } + /// /// Sets the parameters of the distribution after checking their validity. /// diff --git a/src/Numerics/Distributions/Chi.cs b/src/Numerics/Distributions/Chi.cs index 09e518e3..4d03072a 100644 --- a/src/Numerics/Distributions/Chi.cs +++ b/src/Numerics/Distributions/Chi.cs @@ -78,6 +78,15 @@ namespace MathNet.Numerics.Distributions return "Chi(k = " + _freedom + ")"; } + /// + /// Tests whether the provided values are valid parameters for this distribution. + /// + /// The degrees of freedom (k) of the distribution. Range: k > 0. + public static bool IsValidParameterSet(double freedom) + { + return freedom > 0.0; + } + /// /// Sets the parameters of the distribution after checking their validity. /// diff --git a/src/Numerics/Distributions/ChiSquared.cs b/src/Numerics/Distributions/ChiSquared.cs index d994f919..6c62f1cf 100644 --- a/src/Numerics/Distributions/ChiSquared.cs +++ b/src/Numerics/Distributions/ChiSquared.cs @@ -76,6 +76,15 @@ namespace MathNet.Numerics.Distributions return "ChiSquared(k = " + _freedom + ")"; } + /// + /// Tests whether the provided values are valid parameters for this distribution. + /// + /// The degrees of freedom (k) of the distribution. Range: k > 0. + public static bool IsValidParameterSet(double freedom) + { + return freedom > 0.0; + } + /// /// Sets the parameters of the distribution after checking their validity. /// diff --git a/src/Numerics/Distributions/ContinuousUniform.cs b/src/Numerics/Distributions/ContinuousUniform.cs index c8238022..32ee56c7 100644 --- a/src/Numerics/Distributions/ContinuousUniform.cs +++ b/src/Numerics/Distributions/ContinuousUniform.cs @@ -89,6 +89,16 @@ namespace MathNet.Numerics.Distributions return "ContinuousUniform(Lower = " + _lower + ", Upper = " + _upper + ")"; } + /// + /// Tests whether the provided values are valid parameters for this distribution. + /// + /// Lower bound. Range: lower ≤ upper. + /// Upper bound. Range: lower ≤ upper. + public static bool IsValidParameterSet(double lower, double upper) + { + return lower <= upper && !Double.IsInfinity(lower) && !Double.IsInfinity(upper); + } + /// /// Sets the parameters of the distribution after checking their validity. /// diff --git a/src/Numerics/Distributions/ConwayMaxwellPoisson.cs b/src/Numerics/Distributions/ConwayMaxwellPoisson.cs index cc87f23c..83c2a6af 100644 --- a/src/Numerics/Distributions/ConwayMaxwellPoisson.cs +++ b/src/Numerics/Distributions/ConwayMaxwellPoisson.cs @@ -107,6 +107,16 @@ namespace MathNet.Numerics.Distributions return "ConwayMaxwellPoisson(λ = " + _lambda + ", ν = " + _nu + ")"; } + /// + /// Tests whether the provided values are valid parameters for this distribution. + /// + /// The lambda (λ) parameter. Range: λ > 0. + /// The rate of decay (ν) parameter. Range: ν ≥ 0. + public static bool IsValidParameterSet(double lambda, double nu) + { + return lambda > 0.0 && nu >= 0.0; + } + /// /// Sets the parameters of the distribution after checking their validity. /// diff --git a/src/Numerics/Distributions/Dirichlet.cs b/src/Numerics/Distributions/Dirichlet.cs index bd401c2a..ac69706c 100644 --- a/src/Numerics/Distributions/Dirichlet.cs +++ b/src/Numerics/Distributions/Dirichlet.cs @@ -117,15 +117,11 @@ namespace MathNet.Numerics.Distributions } /// - /// Checks whether the parameters of the distribution are valid: no - /// parameter can be less than zero and at least one parameter should be - /// larger than zero. + /// Tests whether the provided values are valid parameters for this distribution. + /// No parameter can be less than zero and at least one parameter should be larger than zero. /// - /// The parameters of the Dirichlet distribution. - /// - /// true when the parameters are valid, false - /// otherwise. - static bool IsValidParameterSet(double[] alpha) + /// The parameters of the Dirichlet distribution. + public static bool IsValidParameterSet(double[] alpha) { var allzero = true; diff --git a/src/Numerics/Distributions/DiscreteUniform.cs b/src/Numerics/Distributions/DiscreteUniform.cs index 852da707..8baf31b9 100644 --- a/src/Numerics/Distributions/DiscreteUniform.cs +++ b/src/Numerics/Distributions/DiscreteUniform.cs @@ -82,6 +82,16 @@ namespace MathNet.Numerics.Distributions return "DiscreteUniform(Lower = " + _lower + ", Upper = " + _upper + ")"; } + /// + /// Tests whether the provided values are valid parameters for this distribution. + /// + /// Lower bound. Range: lower ≤ upper. + /// Upper bound. Range: lower ≤ upper. + public static bool IsValidParameterSet(int lower, int upper) + { + return lower <= upper; + } + /// /// Sets the parameters of the distribution after checking their validity. /// diff --git a/src/Numerics/Distributions/Erlang.cs b/src/Numerics/Distributions/Erlang.cs index 2dc2381b..c57f0c25 100644 --- a/src/Numerics/Distributions/Erlang.cs +++ b/src/Numerics/Distributions/Erlang.cs @@ -104,6 +104,16 @@ namespace MathNet.Numerics.Distributions return "Erlang(k = " + _shape + ", λ = " + _rate + ")"; } + /// + /// Tests whether the provided values are valid parameters for this distribution. + /// + /// The shape (k) of the Erlang distribution. Range: k ≥ 0. + /// The rate or inverse scale (λ) of the Erlang distribution. Range: λ ≥ 0. + public static bool IsValidParameterSet(double shape, double rate) + { + return shape >= 0.0 && rate >= 0.0; + } + /// /// Sets the parameters of the distribution after checking their validity. /// diff --git a/src/Numerics/Distributions/Exponential.cs b/src/Numerics/Distributions/Exponential.cs index c6937557..038fd415 100644 --- a/src/Numerics/Distributions/Exponential.cs +++ b/src/Numerics/Distributions/Exponential.cs @@ -78,6 +78,15 @@ namespace MathNet.Numerics.Distributions return "Exponential(λ = " + _rate + ")"; } + /// + /// Tests whether the provided values are valid parameters for this distribution. + /// + /// The rate (λ) parameter of the distribution. Range: λ ≥ 0. + public static bool IsValidParameterSet(double rate) + { + return rate >= 0.0; + } + /// /// Sets the parameters of the distribution after checking their validity. /// diff --git a/src/Numerics/Distributions/FisherSnedecor.cs b/src/Numerics/Distributions/FisherSnedecor.cs index b990133f..b379b51a 100644 --- a/src/Numerics/Distributions/FisherSnedecor.cs +++ b/src/Numerics/Distributions/FisherSnedecor.cs @@ -80,6 +80,16 @@ namespace MathNet.Numerics.Distributions return "FisherSnedecor(d1 = " + _freedom1 + ", d2 = " + _freedom2 + ")"; } + /// + /// Tests whether the provided values are valid parameters for this distribution. + /// + /// The first degree of freedom (d1) of the distribution. Range: d1 > 0. + /// The second degree of freedom (d2) of the distribution. Range: d2 > 0. + public static bool IsValidParameterSet(double d1, double d2) + { + return d1 > 0.0 && d2 > 0.0; + } + /// /// Sets the parameters of the distribution after checking their validity. /// diff --git a/src/Numerics/Distributions/Gamma.cs b/src/Numerics/Distributions/Gamma.cs index a01a244c..7987ce5f 100644 --- a/src/Numerics/Distributions/Gamma.cs +++ b/src/Numerics/Distributions/Gamma.cs @@ -113,6 +113,16 @@ namespace MathNet.Numerics.Distributions return "Gamma(α = " + _shape + ", β = " + _rate + ")"; } + /// + /// Tests whether the provided values are valid parameters for this distribution. + /// + /// The shape (k, α) of the Gamma distribution. Range: α ≥ 0. + /// The rate or inverse scale (β) of the Gamma distribution. Range: β ≥ 0. + public static bool IsValidParameterSet(double shape, double rate) + { + return shape >= 0.0 && rate >= 0.0; + } + /// /// Sets the parameters of the distribution after checking their validity. /// diff --git a/src/Numerics/Distributions/Geometric.cs b/src/Numerics/Distributions/Geometric.cs index dc1cf91f..e7bbc056 100644 --- a/src/Numerics/Distributions/Geometric.cs +++ b/src/Numerics/Distributions/Geometric.cs @@ -77,6 +77,15 @@ namespace MathNet.Numerics.Distributions return "Geometric(p = " + _p + ")"; } + /// + /// Tests whether the provided values are valid parameters for this distribution. + /// + /// The probability (p) of generating one. Range: 0 ≤ p ≤ 1. + public static bool IsValidParameterSet(double p) + { + return p >= 0.0 && p <= 1.0; + } + /// /// Sets the parameters of the distribution after checking their validity. /// diff --git a/src/Numerics/Distributions/Hypergeometric.cs b/src/Numerics/Distributions/Hypergeometric.cs index 13a9b3e2..774507e6 100644 --- a/src/Numerics/Distributions/Hypergeometric.cs +++ b/src/Numerics/Distributions/Hypergeometric.cs @@ -86,6 +86,17 @@ namespace MathNet.Numerics.Distributions return "Hypergeometric(N = " + _population + ", M = " + _success + ", n = " + _draws + ")"; } + /// + /// Tests whether the provided values are valid parameters for this distribution. + /// + /// The size of the population (N). + /// The number successes within the population (K, M). + /// The number of draws without replacement (n). + public static bool IsValidParameterSet(int population, int success, int draws) + { + return population >= 0 && success >= 0 && draws >= 0 && success <= population && draws <= population; + } + /// /// Sets the parameters of the distribution after checking their validity. /// diff --git a/src/Numerics/Distributions/InverseGamma.cs b/src/Numerics/Distributions/InverseGamma.cs index 3fe36547..92e64a86 100644 --- a/src/Numerics/Distributions/InverseGamma.cs +++ b/src/Numerics/Distributions/InverseGamma.cs @@ -81,6 +81,16 @@ namespace MathNet.Numerics.Distributions return "InverseGamma(α = " + _shape + ", β = " + _scale + ")"; } + /// + /// Tests whether the provided values are valid parameters for this distribution. + /// + /// The shape (α) of the distribution. Range: α > 0. + /// The scale (β) of the distribution. Range: β > 0. + public static bool IsValidParameterSet(double shape, double scale) + { + return shape > 0.0 && scale > 0.0; + } + /// /// Sets the parameters of the distribution after checking their validity. /// diff --git a/src/Numerics/Distributions/InverseWishart.cs b/src/Numerics/Distributions/InverseWishart.cs index de039e88..7bf0242e 100644 --- a/src/Numerics/Distributions/InverseWishart.cs +++ b/src/Numerics/Distributions/InverseWishart.cs @@ -87,12 +87,11 @@ namespace MathNet.Numerics.Distributions } /// - /// Checks whether the parameters of the distribution are valid. + /// Tests whether the provided values are valid parameters for this distribution. /// /// The degree of freedom (ν) for the inverse Wishart distribution. /// The scale matrix (Ψ) for the inverse Wishart distribution. - /// true when the parameters are valid, false otherwise. - static bool IsValidParameterSet(double degreesOfFreedom, Matrix scale) + public static bool IsValidParameterSet(double degreesOfFreedom, Matrix scale) { if (scale.RowCount != scale.ColumnCount) { diff --git a/src/Numerics/Distributions/Laplace.cs b/src/Numerics/Distributions/Laplace.cs index ed68ecd7..a8fb0518 100644 --- a/src/Numerics/Distributions/Laplace.cs +++ b/src/Numerics/Distributions/Laplace.cs @@ -91,6 +91,16 @@ namespace MathNet.Numerics.Distributions return "Laplace(μ = " + _location + ", b = " + _scale + ")"; } + /// + /// Tests whether the provided values are valid parameters for this distribution. + /// + /// The location (μ) of the distribution. + /// The scale (b) of the distribution. Range: b > 0. + public static bool IsValidParameterSet(double location, double scale) + { + return scale > 0.0 && !Double.IsNaN(location); + } + /// /// Sets the parameters of the distribution after checking their validity. /// diff --git a/src/Numerics/Distributions/LogNormal.cs b/src/Numerics/Distributions/LogNormal.cs index cbf8f243..eb298892 100644 --- a/src/Numerics/Distributions/LogNormal.cs +++ b/src/Numerics/Distributions/LogNormal.cs @@ -124,6 +124,16 @@ namespace MathNet.Numerics.Distributions return "LogNormal(μ = " + _mu + ", σ = " + _sigma + ")"; } + /// + /// Tests whether the provided values are valid parameters for this distribution. + /// + /// The log-scale (μ) of the distribution. + /// The shape (σ) of the distribution. Range: σ ≥ 0. + public static bool IsValidParameterSet(double mu, double sigma) + { + return sigma >= 0.0 && !Double.IsNaN(mu); + } + /// /// Sets the parameters of the distribution after checking their validity. /// diff --git a/src/Numerics/Distributions/MatrixNormal.cs b/src/Numerics/Distributions/MatrixNormal.cs index d0875e1e..ecbbb402 100644 --- a/src/Numerics/Distributions/MatrixNormal.cs +++ b/src/Numerics/Distributions/MatrixNormal.cs @@ -100,13 +100,12 @@ namespace MathNet.Numerics.Distributions } /// - /// Checks whether the parameters of the distribution are valid. + /// Tests whether the provided values are valid parameters for this distribution. /// /// The mean of the matrix normal. /// The covariance matrix for the rows. /// The covariance matrix for the columns. - /// true when the parameters are valid, false otherwise. - static bool IsValidParameterSet(Matrix m, Matrix v, Matrix k) + public static bool IsValidParameterSet(Matrix m, Matrix v, Matrix k) { var n = m.RowCount; var p = m.ColumnCount; diff --git a/src/Numerics/Distributions/Multinomial.cs b/src/Numerics/Distributions/Multinomial.cs index c599e0da..2a287278 100644 --- a/src/Numerics/Distributions/Multinomial.cs +++ b/src/Numerics/Distributions/Multinomial.cs @@ -129,14 +129,14 @@ namespace MathNet.Numerics.Distributions } /// - /// Checks whether the parameters of the distribution are valid. + /// Tests whether the provided values are valid parameters for this distribution. /// /// An array of nonnegative ratios: this array does not need to be normalized /// as this is often impossible using floating point arithmetic. /// The number of trials. /// If any of the probabilities are negative returns false, /// if the sum of parameters is 0.0, or if the number of trials is negative; otherwise true. - static bool IsValidParameterSet(IEnumerable p, int n) + public static bool IsValidParameterSet(IEnumerable p, int n) { var sum = 0.0; foreach (var t in p) diff --git a/src/Numerics/Distributions/NegativeBinomial.cs b/src/Numerics/Distributions/NegativeBinomial.cs index 73f38547..3fb83997 100644 --- a/src/Numerics/Distributions/NegativeBinomial.cs +++ b/src/Numerics/Distributions/NegativeBinomial.cs @@ -83,6 +83,16 @@ namespace MathNet.Numerics.Distributions return "NegativeBinomial(R = " + _trials + ", P = " + _p + ")"; } + /// + /// Tests whether the provided values are valid parameters for this distribution. + /// + /// The number of failures (r) until the experiment stopped. Range: r ≥ 0. + /// The probability (p) of a trial resulting in success. Range: 0 ≤ p ≤ 1. + public static bool IsValidParameterSet(double r, double p) + { + return r >= 0.0 && p >= 0.0 && p <= 1.0; + } + /// /// Sets the parameters of the distribution after checking their validity. /// diff --git a/src/Numerics/Distributions/Normal.cs b/src/Numerics/Distributions/Normal.cs index 6cb56024..677dbedb 100644 --- a/src/Numerics/Distributions/Normal.cs +++ b/src/Numerics/Distributions/Normal.cs @@ -152,6 +152,16 @@ namespace MathNet.Numerics.Distributions return "Normal(μ = " + _mean + ", σ = " + _stdDev + ")"; } + /// + /// Tests whether the provided values are valid parameters for this distribution. + /// + /// The mean (μ) of the normal distribution. + /// The standard deviation (σ) of the normal distribution. Range: σ ≥ 0. + public static bool IsValidParameterSet(double mean, double stddev) + { + return stddev >= 0.0 && !Double.IsNaN(mean); + } + /// /// Sets the parameters of the distribution after checking their validity. /// diff --git a/src/Numerics/Distributions/NormalGamma.cs b/src/Numerics/Distributions/NormalGamma.cs index 0f761a0c..0ccf863b 100644 --- a/src/Numerics/Distributions/NormalGamma.cs +++ b/src/Numerics/Distributions/NormalGamma.cs @@ -143,16 +143,15 @@ namespace MathNet.Numerics.Distributions } /// - /// Checks whether the parameters of the distribution are valid. + /// Tests whether the provided values are valid parameters for this distribution. /// /// The location of the mean. /// The scale of the mean. /// The shape of the precision. /// The inverse scale of the precision. - /// true when the parameters are valid, false otherwise. - static bool IsValidParameterSet(double meanLocation, double meanScale, double precShape, double precInvScale) + public static bool IsValidParameterSet(double meanLocation, double meanScale, double precShape, double precInvScale) { - return (meanScale > 0.0) && (precShape > 0.0) && (precInvScale > 0.0) && !Double.IsNaN(meanLocation); + return meanScale > 0.0 && precShape > 0.0 && precInvScale > 0.0 && !Double.IsNaN(meanLocation); } /// diff --git a/src/Numerics/Distributions/Pareto.cs b/src/Numerics/Distributions/Pareto.cs index 3f4d1e98..a4378ffa 100644 --- a/src/Numerics/Distributions/Pareto.cs +++ b/src/Numerics/Distributions/Pareto.cs @@ -85,6 +85,16 @@ namespace MathNet.Numerics.Distributions return "Pareto(xm = " + _scale + ", α = " + _shape + ")"; } + /// + /// Tests whether the provided values are valid parameters for this distribution. + /// + /// The scale (xm) of the distribution. Range: xm > 0. + /// The shape (α) of the distribution. Range: α > 0. + public static bool IsValidParameterSet(double scale, double shape) + { + return scale > 0.0 && shape > 0.0; + } + /// /// Sets the parameters of the distribution after checking their validity. /// diff --git a/src/Numerics/Distributions/Poisson.cs b/src/Numerics/Distributions/Poisson.cs index 886641e0..d9d56eb8 100644 --- a/src/Numerics/Distributions/Poisson.cs +++ b/src/Numerics/Distributions/Poisson.cs @@ -83,6 +83,15 @@ namespace MathNet.Numerics.Distributions return "Poisson(λ = " + _lambda + ")"; } + /// + /// Tests whether the provided values are valid parameters for this distribution. + /// + /// The lambda (λ) parameter of the Poisson distribution. Range: λ > 0. + public static bool IsValidParameterSet(double lambda) + { + return lambda > 0.0; + } + /// /// Sets the parameters of the distribution after checking their validity. /// diff --git a/src/Numerics/Distributions/Rayleigh.cs b/src/Numerics/Distributions/Rayleigh.cs index 2ee2e8ef..773a6edd 100644 --- a/src/Numerics/Distributions/Rayleigh.cs +++ b/src/Numerics/Distributions/Rayleigh.cs @@ -83,6 +83,15 @@ namespace MathNet.Numerics.Distributions return "Rayleigh(σ = " + _scale + ")"; } + /// + /// Tests whether the provided values are valid parameters for this distribution. + /// + /// The scale (σ) of the distribution. Range: σ > 0. + public static bool IsValidParameterSet(double scale) + { + return scale > 0.0; + } + /// /// Sets the parameters of the distribution after checking their validity. /// diff --git a/src/Numerics/Distributions/Stable.cs b/src/Numerics/Distributions/Stable.cs index b7fe5567..9417abb2 100644 --- a/src/Numerics/Distributions/Stable.cs +++ b/src/Numerics/Distributions/Stable.cs @@ -88,6 +88,18 @@ namespace MathNet.Numerics.Distributions return "Stable(α = " + _alpha + ", β = " + _beta + ", c = " + _scale + ", μ = " + _location + ")"; } + /// + /// Tests whether the provided values are valid parameters for this distribution. + /// + /// The stability (α) of the distribution. Range: 2 ≥ α > 0. + /// The skewness (β) of the distribution. Range: 1 ≥ β ≥ -1. + /// The scale (c) of the distribution. Range: c > 0. + /// The location (μ) of the distribution. + public static bool IsValidParameterSet(double alpha, double beta, double scale, double location) + { + return alpha > 0.0 && alpha <= 2.0 && beta >= -1.0 && beta <= 1.0 && scale > 0.0 && !Double.IsNaN(location); + } + /// /// Sets the parameters of the distribution after checking their validity. /// diff --git a/src/Numerics/Distributions/StudentT.cs b/src/Numerics/Distributions/StudentT.cs index 92a26619..ab30c847 100644 --- a/src/Numerics/Distributions/StudentT.cs +++ b/src/Numerics/Distributions/StudentT.cs @@ -111,6 +111,17 @@ namespace MathNet.Numerics.Distributions return "StudentT(μ = " + _location + ", σ = " + _scale + ", ν = " + _freedom + ")"; } + /// + /// Tests whether the provided values are valid parameters for this distribution. + /// + /// The location (μ) of the distribution. + /// The scale (σ) of the distribution. Range: σ > 0. + /// The degrees of freedom (ν) for the distribution. Range: ν > 0. + public static bool IsValidParameterSet(double location, double scale, double freedom) + { + return scale > 0.0 && freedom > 0.0; + } + /// /// Sets the parameters of the distribution after checking their validity. /// diff --git a/src/Numerics/Distributions/Triangular.cs b/src/Numerics/Distributions/Triangular.cs index 1e85fd9e..8b25c5e3 100644 --- a/src/Numerics/Distributions/Triangular.cs +++ b/src/Numerics/Distributions/Triangular.cs @@ -89,6 +89,17 @@ namespace MathNet.Numerics.Distributions return "Triangular(Lower = " + _lower + ", Upper = " + _upper + ", Mode = " + _mode + ")"; } + /// + /// Tests whether the provided values are valid parameters for this distribution. + /// + /// Lower bound. Range: lower ≤ mode ≤ upper + /// Upper bound. Range: lower ≤ mode ≤ upper + /// Mode (most frequent value). Range: lower ≤ mode ≤ upper + public static bool IsValidParameterSet(double lower, double upper, double mode) + { + return upper >= mode && mode >= lower && !Double.IsInfinity(upper) && !Double.IsInfinity(lower) && !Double.IsInfinity(mode); + } + /// /// Sets the parameters of the distribution after checking their validity. /// diff --git a/src/Numerics/Distributions/Weibull.cs b/src/Numerics/Distributions/Weibull.cs index fec31cf5..c88f87bb 100644 --- a/src/Numerics/Distributions/Weibull.cs +++ b/src/Numerics/Distributions/Weibull.cs @@ -93,6 +93,16 @@ namespace MathNet.Numerics.Distributions return "Weibull(k = " + _shape + ", λ = " + _scale + ")"; } + /// + /// Tests whether the provided values are valid parameters for this distribution. + /// + /// The shape (k) of the Weibull distribution. Range: k > 0. + /// The scale (λ) of the Weibull distribution. Range: λ > 0. + public static bool IsValidParameterSet(double shape, double scale) + { + return shape > 0.0 && scale > 0.0; + } + /// /// Sets the parameters of the distribution after checking their validity. /// diff --git a/src/Numerics/Distributions/Wishart.cs b/src/Numerics/Distributions/Wishart.cs index 799f7690..997958e3 100644 --- a/src/Numerics/Distributions/Wishart.cs +++ b/src/Numerics/Distributions/Wishart.cs @@ -87,30 +87,11 @@ namespace MathNet.Numerics.Distributions } /// - /// Sets the parameters of the distribution after checking their validity. - /// - /// The degrees of freedom (n) for the Wishart distribution. - /// The scale matrix (V) for the Wishart distribution. - /// When the parameters are out of range. - void SetParameters(double degreesOfFreedom, Matrix scale) - { - if (Control.CheckDistributionParameters && !IsValidParameterSet(degreesOfFreedom, scale)) - { - throw new ArgumentException(Resources.InvalidDistributionParameters); - } - - _degreesOfFreedom = degreesOfFreedom; - _scale = scale; - _chol = _scale.Cholesky(); - } - - /// - /// Checks whether the parameters of the distribution are valid. + /// Tests whether the provided values are valid parameters for this distribution. /// /// The degrees of freedom (n) for the Wishart distribution. /// The scale matrix (V) for the Wishart distribution. - /// true when the parameters are valid, false otherwise. - static bool IsValidParameterSet(double degreesOfFreedom, Matrix scale) + public static bool IsValidParameterSet(double degreesOfFreedom, Matrix scale) { if (scale.RowCount != scale.ColumnCount) { @@ -133,6 +114,24 @@ namespace MathNet.Numerics.Distributions return true; } + /// + /// Sets the parameters of the distribution after checking their validity. + /// + /// The degrees of freedom (n) for the Wishart distribution. + /// The scale matrix (V) for the Wishart distribution. + /// When the parameters are out of range. + void SetParameters(double degreesOfFreedom, Matrix scale) + { + if (Control.CheckDistributionParameters && !IsValidParameterSet(degreesOfFreedom, scale)) + { + throw new ArgumentException(Resources.InvalidDistributionParameters); + } + + _degreesOfFreedom = degreesOfFreedom; + _scale = scale; + _chol = _scale.Cholesky(); + } + /// /// Gets or sets the degrees of freedom (n) for the Wishart distribution. /// diff --git a/src/Numerics/Distributions/Zipf.cs b/src/Numerics/Distributions/Zipf.cs index 3009088f..a2679ea7 100644 --- a/src/Numerics/Distributions/Zipf.cs +++ b/src/Numerics/Distributions/Zipf.cs @@ -89,6 +89,16 @@ namespace MathNet.Numerics.Distributions return "Zipf(S = " + _s + ", N = " + _n + ")"; } + /// + /// Tests whether the provided values are valid parameters for this distribution. + /// + /// The s parameter of the distribution. + /// The n parameter of the distribution. + public static bool IsValidParameterSet(double s, int n) + { + return n > 0 && s > 0.0; + } + /// /// Sets the parameters of the distribution after checking their validity. ///