Browse Source

Distributions: bring back public static IsValidParameterSet functions

pull/222/head
Christoph Ruegg 12 years ago
parent
commit
95adce4c1f
  1. 9
      src/Numerics/Distributions/Bernoulli.cs
  2. 10
      src/Numerics/Distributions/Beta.cs
  3. 10
      src/Numerics/Distributions/Binomial.cs
  4. 4
      src/Numerics/Distributions/Categorical.cs
  5. 10
      src/Numerics/Distributions/Cauchy.cs
  6. 9
      src/Numerics/Distributions/Chi.cs
  7. 9
      src/Numerics/Distributions/ChiSquared.cs
  8. 10
      src/Numerics/Distributions/ContinuousUniform.cs
  9. 10
      src/Numerics/Distributions/ConwayMaxwellPoisson.cs
  10. 12
      src/Numerics/Distributions/Dirichlet.cs
  11. 10
      src/Numerics/Distributions/DiscreteUniform.cs
  12. 10
      src/Numerics/Distributions/Erlang.cs
  13. 9
      src/Numerics/Distributions/Exponential.cs
  14. 10
      src/Numerics/Distributions/FisherSnedecor.cs
  15. 10
      src/Numerics/Distributions/Gamma.cs
  16. 9
      src/Numerics/Distributions/Geometric.cs
  17. 11
      src/Numerics/Distributions/Hypergeometric.cs
  18. 10
      src/Numerics/Distributions/InverseGamma.cs
  19. 5
      src/Numerics/Distributions/InverseWishart.cs
  20. 10
      src/Numerics/Distributions/Laplace.cs
  21. 10
      src/Numerics/Distributions/LogNormal.cs
  22. 5
      src/Numerics/Distributions/MatrixNormal.cs
  23. 4
      src/Numerics/Distributions/Multinomial.cs
  24. 10
      src/Numerics/Distributions/NegativeBinomial.cs
  25. 10
      src/Numerics/Distributions/Normal.cs
  26. 7
      src/Numerics/Distributions/NormalGamma.cs
  27. 10
      src/Numerics/Distributions/Pareto.cs
  28. 9
      src/Numerics/Distributions/Poisson.cs
  29. 9
      src/Numerics/Distributions/Rayleigh.cs
  30. 12
      src/Numerics/Distributions/Stable.cs
  31. 11
      src/Numerics/Distributions/StudentT.cs
  32. 11
      src/Numerics/Distributions/Triangular.cs
  33. 10
      src/Numerics/Distributions/Weibull.cs
  34. 41
      src/Numerics/Distributions/Wishart.cs
  35. 10
      src/Numerics/Distributions/Zipf.cs

9
src/Numerics/Distributions/Bernoulli.cs

@ -79,6 +79,15 @@ namespace MathNet.Numerics.Distributions
return "Bernoulli(p = " + _p + ")";
}
/// <summary>
/// Tests whether the provided values are valid parameters for this distribution.
/// </summary>
/// <param name="p">The probability (p) of generating one. Range: 0 ≤ p ≤ 1.</param>
public static bool IsValidParameterSet(double p)
{
return p >= 0.0 && p <= 1.0;
}
/// <summary>
/// Sets the parameters of the distribution after checking their validity.
/// </summary>

10
src/Numerics/Distributions/Beta.cs

@ -88,6 +88,16 @@ namespace MathNet.Numerics.Distributions
return "Beta(α = " + _shapeA + ", β = " + _shapeB + ")";
}
/// <summary>
/// Tests whether the provided values are valid parameters for this distribution.
/// </summary>
/// <param name="a">The α shape parameter of the Beta distribution. Range: α ≥ 0.</param>
/// <param name="b">The β shape parameter of the Beta distribution. Range: β ≥ 0.</param>
public static bool IsValidParameterSet(double a, double b)
{
return a >= 0.0 && b >= 0.0;
}
/// <summary>
/// Sets the parameters of the distribution after checking their validity.
/// </summary>

10
src/Numerics/Distributions/Binomial.cs

@ -86,6 +86,16 @@ namespace MathNet.Numerics.Distributions
return "Binomial(p = " + _p + ", n = " + _trials + ")";
}
/// <summary>
/// Tests whether the provided values are valid parameters for this distribution.
/// </summary>
/// <param name="p">The success probability (p) in each trial. Range: 0 ≤ p ≤ 1.</param>
/// <param name="n">The number of trials (n). Range: n ≥ 0.</param>
public static bool IsValidParameterSet(double p, int n)
{
return p >= 0.0 && p <= 1.0 && n >= 0;
}
/// <summary>
/// Sets the parameters of the distribution after checking their validity.
/// </summary>

4
src/Numerics/Distributions/Categorical.cs

@ -123,7 +123,7 @@ namespace MathNet.Numerics.Distributions
/// </summary>
/// <param name="p">An array of nonnegative ratios: this array does not need to be normalized as this is often impossible using floating point arithmetic.</param>
/// <returns>If any of the probabilities are negative returns <c>false</c>, or if the sum of parameters is 0.0; otherwise <c>true</c></returns>
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
/// </summary>
/// <param name="cdf">An array of nonnegative ratios: this array does not need to be normalized as this is often impossible using floating point arithmetic.</param>
/// <returns>If any of the probabilities are negative returns <c>false</c>, or if the sum of parameters is 0.0; otherwise <c>true</c></returns>
static bool IsValidCumulativeDistribution(double[] cdf)
public static bool IsValidCumulativeDistribution(double[] cdf)
{
var last = 0.0;
for (int i = 0; i < cdf.Length; i++)

10
src/Numerics/Distributions/Cauchy.cs

@ -87,6 +87,16 @@ namespace MathNet.Numerics.Distributions
return "Cauchy(x0 = " + _location + ", γ = " + _scale + ")";
}
/// <summary>
/// Tests whether the provided values are valid parameters for this distribution.
/// </summary>
/// <param name="location">The location (x0) of the distribution.</param>
/// <param name="scale">The scale (γ) of the distribution. Range: γ > 0.</param>
public static bool IsValidParameterSet(double location, double scale)
{
return scale > 0.0 && !Double.IsNaN(location);
}
/// <summary>
/// Sets the parameters of the distribution after checking their validity.
/// </summary>

9
src/Numerics/Distributions/Chi.cs

@ -78,6 +78,15 @@ namespace MathNet.Numerics.Distributions
return "Chi(k = " + _freedom + ")";
}
/// <summary>
/// Tests whether the provided values are valid parameters for this distribution.
/// </summary>
/// <param name="freedom">The degrees of freedom (k) of the distribution. Range: k > 0.</param>
public static bool IsValidParameterSet(double freedom)
{
return freedom > 0.0;
}
/// <summary>
/// Sets the parameters of the distribution after checking their validity.
/// </summary>

9
src/Numerics/Distributions/ChiSquared.cs

@ -76,6 +76,15 @@ namespace MathNet.Numerics.Distributions
return "ChiSquared(k = " + _freedom + ")";
}
/// <summary>
/// Tests whether the provided values are valid parameters for this distribution.
/// </summary>
/// <param name="freedom">The degrees of freedom (k) of the distribution. Range: k > 0.</param>
public static bool IsValidParameterSet(double freedom)
{
return freedom > 0.0;
}
/// <summary>
/// Sets the parameters of the distribution after checking their validity.
/// </summary>

10
src/Numerics/Distributions/ContinuousUniform.cs

@ -89,6 +89,16 @@ namespace MathNet.Numerics.Distributions
return "ContinuousUniform(Lower = " + _lower + ", Upper = " + _upper + ")";
}
/// <summary>
/// Tests whether the provided values are valid parameters for this distribution.
/// </summary>
/// <param name="lower">Lower bound. Range: lower ≤ upper.</param>
/// <param name="upper">Upper bound. Range: lower ≤ upper.</param>
public static bool IsValidParameterSet(double lower, double upper)
{
return lower <= upper && !Double.IsInfinity(lower) && !Double.IsInfinity(upper);
}
/// <summary>
/// Sets the parameters of the distribution after checking their validity.
/// </summary>

10
src/Numerics/Distributions/ConwayMaxwellPoisson.cs

@ -107,6 +107,16 @@ namespace MathNet.Numerics.Distributions
return "ConwayMaxwellPoisson(λ = " + _lambda + ", ν = " + _nu + ")";
}
/// <summary>
/// Tests whether the provided values are valid parameters for this distribution.
/// </summary>
/// <param name="lambda">The lambda (λ) parameter. Range: λ > 0.</param>
/// <param name="nu">The rate of decay (ν) parameter. Range: ν ≥ 0.</param>
public static bool IsValidParameterSet(double lambda, double nu)
{
return lambda > 0.0 && nu >= 0.0;
}
/// <summary>
/// Sets the parameters of the distribution after checking their validity.
/// </summary>

12
src/Numerics/Distributions/Dirichlet.cs

@ -117,15 +117,11 @@ namespace MathNet.Numerics.Distributions
}
/// <summary>
/// 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.
/// </summary>
/// <param name="alpha">The parameters of the Dirichlet distribution.
/// </param>
/// <returns><c>true</c> when the parameters are valid, <c>false</c>
/// otherwise.</returns>
static bool IsValidParameterSet(double[] alpha)
/// <param name="alpha">The parameters of the Dirichlet distribution.</param>
public static bool IsValidParameterSet(double[] alpha)
{
var allzero = true;

10
src/Numerics/Distributions/DiscreteUniform.cs

@ -82,6 +82,16 @@ namespace MathNet.Numerics.Distributions
return "DiscreteUniform(Lower = " + _lower + ", Upper = " + _upper + ")";
}
/// <summary>
/// Tests whether the provided values are valid parameters for this distribution.
/// </summary>
/// <param name="lower">Lower bound. Range: lower ≤ upper.</param>
/// <param name="upper">Upper bound. Range: lower ≤ upper.</param>
public static bool IsValidParameterSet(int lower, int upper)
{
return lower <= upper;
}
/// <summary>
/// Sets the parameters of the distribution after checking their validity.
/// </summary>

10
src/Numerics/Distributions/Erlang.cs

@ -104,6 +104,16 @@ namespace MathNet.Numerics.Distributions
return "Erlang(k = " + _shape + ", λ = " + _rate + ")";
}
/// <summary>
/// Tests whether the provided values are valid parameters for this distribution.
/// </summary>
/// <param name="shape">The shape (k) of the Erlang distribution. Range: k ≥ 0.</param>
/// <param name="rate">The rate or inverse scale (λ) of the Erlang distribution. Range: λ ≥ 0.</param>
public static bool IsValidParameterSet(double shape, double rate)
{
return shape >= 0.0 && rate >= 0.0;
}
/// <summary>
/// Sets the parameters of the distribution after checking their validity.
/// </summary>

9
src/Numerics/Distributions/Exponential.cs

@ -78,6 +78,15 @@ namespace MathNet.Numerics.Distributions
return "Exponential(λ = " + _rate + ")";
}
/// <summary>
/// Tests whether the provided values are valid parameters for this distribution.
/// </summary>
/// <param name="rate">The rate (λ) parameter of the distribution. Range: λ ≥ 0.</param>
public static bool IsValidParameterSet(double rate)
{
return rate >= 0.0;
}
/// <summary>
/// Sets the parameters of the distribution after checking their validity.
/// </summary>

10
src/Numerics/Distributions/FisherSnedecor.cs

@ -80,6 +80,16 @@ namespace MathNet.Numerics.Distributions
return "FisherSnedecor(d1 = " + _freedom1 + ", d2 = " + _freedom2 + ")";
}
/// <summary>
/// Tests whether the provided values are valid parameters for this distribution.
/// </summary>
/// <param name="d1">The first degree of freedom (d1) of the distribution. Range: d1 > 0.</param>
/// <param name="d2">The second degree of freedom (d2) of the distribution. Range: d2 > 0.</param>
public static bool IsValidParameterSet(double d1, double d2)
{
return d1 > 0.0 && d2 > 0.0;
}
/// <summary>
/// Sets the parameters of the distribution after checking their validity.
/// </summary>

10
src/Numerics/Distributions/Gamma.cs

@ -113,6 +113,16 @@ namespace MathNet.Numerics.Distributions
return "Gamma(α = " + _shape + ", β = " + _rate + ")";
}
/// <summary>
/// Tests whether the provided values are valid parameters for this distribution.
/// </summary>
/// <param name="shape">The shape (k, α) of the Gamma distribution. Range: α ≥ 0.</param>
/// <param name="rate">The rate or inverse scale (β) of the Gamma distribution. Range: β ≥ 0.</param>
public static bool IsValidParameterSet(double shape, double rate)
{
return shape >= 0.0 && rate >= 0.0;
}
/// <summary>
/// Sets the parameters of the distribution after checking their validity.
/// </summary>

9
src/Numerics/Distributions/Geometric.cs

@ -77,6 +77,15 @@ namespace MathNet.Numerics.Distributions
return "Geometric(p = " + _p + ")";
}
/// <summary>
/// Tests whether the provided values are valid parameters for this distribution.
/// </summary>
/// <param name="p">The probability (p) of generating one. Range: 0 ≤ p ≤ 1.</param>
public static bool IsValidParameterSet(double p)
{
return p >= 0.0 && p <= 1.0;
}
/// <summary>
/// Sets the parameters of the distribution after checking their validity.
/// </summary>

11
src/Numerics/Distributions/Hypergeometric.cs

@ -86,6 +86,17 @@ namespace MathNet.Numerics.Distributions
return "Hypergeometric(N = " + _population + ", M = " + _success + ", n = " + _draws + ")";
}
/// <summary>
/// Tests whether the provided values are valid parameters for this distribution.
/// </summary>
/// <param name="population">The size of the population (N).</param>
/// <param name="success">The number successes within the population (K, M).</param>
/// <param name="draws">The number of draws without replacement (n).</param>
public static bool IsValidParameterSet(int population, int success, int draws)
{
return population >= 0 && success >= 0 && draws >= 0 && success <= population && draws <= population;
}
/// <summary>
/// Sets the parameters of the distribution after checking their validity.
/// </summary>

10
src/Numerics/Distributions/InverseGamma.cs

@ -81,6 +81,16 @@ namespace MathNet.Numerics.Distributions
return "InverseGamma(α = " + _shape + ", β = " + _scale + ")";
}
/// <summary>
/// Tests whether the provided values are valid parameters for this distribution.
/// </summary>
/// <param name="shape">The shape (α) of the distribution. Range: α > 0.</param>
/// <param name="scale">The scale (β) of the distribution. Range: β > 0.</param>
public static bool IsValidParameterSet(double shape, double scale)
{
return shape > 0.0 && scale > 0.0;
}
/// <summary>
/// Sets the parameters of the distribution after checking their validity.
/// </summary>

5
src/Numerics/Distributions/InverseWishart.cs

@ -87,12 +87,11 @@ namespace MathNet.Numerics.Distributions
}
/// <summary>
/// Checks whether the parameters of the distribution are valid.
/// Tests whether the provided values are valid parameters for this distribution.
/// </summary>
/// <param name="degreesOfFreedom">The degree of freedom (ν) for the inverse Wishart distribution.</param>
/// <param name="scale">The scale matrix (Ψ) for the inverse Wishart distribution.</param>
/// <returns><c>true</c> when the parameters are valid, <c>false</c> otherwise.</returns>
static bool IsValidParameterSet(double degreesOfFreedom, Matrix<double> scale)
public static bool IsValidParameterSet(double degreesOfFreedom, Matrix<double> scale)
{
if (scale.RowCount != scale.ColumnCount)
{

10
src/Numerics/Distributions/Laplace.cs

@ -91,6 +91,16 @@ namespace MathNet.Numerics.Distributions
return "Laplace(μ = " + _location + ", b = " + _scale + ")";
}
/// <summary>
/// Tests whether the provided values are valid parameters for this distribution.
/// </summary>
/// <param name="location">The location (μ) of the distribution.</param>
/// <param name="scale">The scale (b) of the distribution. Range: b > 0.</param>
public static bool IsValidParameterSet(double location, double scale)
{
return scale > 0.0 && !Double.IsNaN(location);
}
/// <summary>
/// Sets the parameters of the distribution after checking their validity.
/// </summary>

10
src/Numerics/Distributions/LogNormal.cs

@ -124,6 +124,16 @@ namespace MathNet.Numerics.Distributions
return "LogNormal(μ = " + _mu + ", σ = " + _sigma + ")";
}
/// <summary>
/// Tests whether the provided values are valid parameters for this distribution.
/// </summary>
/// <param name="mu">The log-scale (μ) of the distribution.</param>
/// <param name="sigma">The shape (σ) of the distribution. Range: σ ≥ 0.</param>
public static bool IsValidParameterSet(double mu, double sigma)
{
return sigma >= 0.0 && !Double.IsNaN(mu);
}
/// <summary>
/// Sets the parameters of the distribution after checking their validity.
/// </summary>

5
src/Numerics/Distributions/MatrixNormal.cs

@ -100,13 +100,12 @@ namespace MathNet.Numerics.Distributions
}
/// <summary>
/// Checks whether the parameters of the distribution are valid.
/// Tests whether the provided values are valid parameters for this distribution.
/// </summary>
/// <param name="m">The mean of the matrix normal.</param>
/// <param name="v">The covariance matrix for the rows.</param>
/// <param name="k">The covariance matrix for the columns.</param>
/// <returns><c>true</c> when the parameters are valid, <c>false</c> otherwise.</returns>
static bool IsValidParameterSet(Matrix<double> m, Matrix<double> v, Matrix<double> k)
public static bool IsValidParameterSet(Matrix<double> m, Matrix<double> v, Matrix<double> k)
{
var n = m.RowCount;
var p = m.ColumnCount;

4
src/Numerics/Distributions/Multinomial.cs

@ -129,14 +129,14 @@ namespace MathNet.Numerics.Distributions
}
/// <summary>
/// Checks whether the parameters of the distribution are valid.
/// Tests whether the provided values are valid parameters for this distribution.
/// </summary>
/// <param name="p">An array of nonnegative ratios: this array does not need to be normalized
/// as this is often impossible using floating point arithmetic.</param>
/// <param name="n">The number of trials.</param>
/// <returns>If any of the probabilities are negative returns <c>false</c>,
/// if the sum of parameters is 0.0, or if the number of trials is negative; otherwise <c>true</c>.</returns>
static bool IsValidParameterSet(IEnumerable<double> p, int n)
public static bool IsValidParameterSet(IEnumerable<double> p, int n)
{
var sum = 0.0;
foreach (var t in p)

10
src/Numerics/Distributions/NegativeBinomial.cs

@ -83,6 +83,16 @@ namespace MathNet.Numerics.Distributions
return "NegativeBinomial(R = " + _trials + ", P = " + _p + ")";
}
/// <summary>
/// Tests whether the provided values are valid parameters for this distribution.
/// </summary>
/// <param name="r">The number of failures (r) until the experiment stopped. Range: r ≥ 0.</param>
/// <param name="p">The probability (p) of a trial resulting in success. Range: 0 ≤ p ≤ 1.</param>
public static bool IsValidParameterSet(double r, double p)
{
return r >= 0.0 && p >= 0.0 && p <= 1.0;
}
/// <summary>
/// Sets the parameters of the distribution after checking their validity.
/// </summary>

10
src/Numerics/Distributions/Normal.cs

@ -152,6 +152,16 @@ namespace MathNet.Numerics.Distributions
return "Normal(μ = " + _mean + ", σ = " + _stdDev + ")";
}
/// <summary>
/// Tests whether the provided values are valid parameters for this distribution.
/// </summary>
/// <param name="mean">The mean (μ) of the normal distribution.</param>
/// <param name="stddev">The standard deviation (σ) of the normal distribution. Range: σ ≥ 0.</param>
public static bool IsValidParameterSet(double mean, double stddev)
{
return stddev >= 0.0 && !Double.IsNaN(mean);
}
/// <summary>
/// Sets the parameters of the distribution after checking their validity.
/// </summary>

7
src/Numerics/Distributions/NormalGamma.cs

@ -143,16 +143,15 @@ namespace MathNet.Numerics.Distributions
}
/// <summary>
/// Checks whether the parameters of the distribution are valid.
/// Tests whether the provided values are valid parameters for this distribution.
/// </summary>
/// <param name="meanLocation">The location of the mean.</param>
/// <param name="meanScale">The scale of the mean.</param>
/// <param name="precShape">The shape of the precision.</param>
/// <param name="precInvScale">The inverse scale of the precision.</param>
/// <returns><c>true</c> when the parameters are valid, <c>false</c> otherwise.</returns>
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);
}
/// <summary>

10
src/Numerics/Distributions/Pareto.cs

@ -85,6 +85,16 @@ namespace MathNet.Numerics.Distributions
return "Pareto(xm = " + _scale + ", α = " + _shape + ")";
}
/// <summary>
/// Tests whether the provided values are valid parameters for this distribution.
/// </summary>
/// <param name="scale">The scale (xm) of the distribution. Range: xm > 0.</param>
/// <param name="shape">The shape (α) of the distribution. Range: α > 0.</param>
public static bool IsValidParameterSet(double scale, double shape)
{
return scale > 0.0 && shape > 0.0;
}
/// <summary>
/// Sets the parameters of the distribution after checking their validity.
/// </summary>

9
src/Numerics/Distributions/Poisson.cs

@ -83,6 +83,15 @@ namespace MathNet.Numerics.Distributions
return "Poisson(λ = " + _lambda + ")";
}
/// <summary>
/// Tests whether the provided values are valid parameters for this distribution.
/// </summary>
/// <param name="lambda">The lambda (λ) parameter of the Poisson distribution. Range: λ > 0.</param>
public static bool IsValidParameterSet(double lambda)
{
return lambda > 0.0;
}
/// <summary>
/// Sets the parameters of the distribution after checking their validity.
/// </summary>

9
src/Numerics/Distributions/Rayleigh.cs

@ -83,6 +83,15 @@ namespace MathNet.Numerics.Distributions
return "Rayleigh(σ = " + _scale + ")";
}
/// <summary>
/// Tests whether the provided values are valid parameters for this distribution.
/// </summary>
/// <param name="scale">The scale (σ) of the distribution. Range: σ > 0.</param>
public static bool IsValidParameterSet(double scale)
{
return scale > 0.0;
}
/// <summary>
/// Sets the parameters of the distribution after checking their validity.
/// </summary>

12
src/Numerics/Distributions/Stable.cs

@ -88,6 +88,18 @@ namespace MathNet.Numerics.Distributions
return "Stable(α = " + _alpha + ", β = " + _beta + ", c = " + _scale + ", μ = " + _location + ")";
}
/// <summary>
/// Tests whether the provided values are valid parameters for this distribution.
/// </summary>
/// <param name="alpha">The stability (α) of the distribution. Range: 2 ≥ α > 0.</param>
/// <param name="beta">The skewness (β) of the distribution. Range: 1 ≥ β ≥ -1.</param>
/// <param name="scale">The scale (c) of the distribution. Range: c > 0.</param>
/// <param name="location">The location (μ) of the distribution.</param>
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);
}
/// <summary>
/// Sets the parameters of the distribution after checking their validity.
/// </summary>

11
src/Numerics/Distributions/StudentT.cs

@ -111,6 +111,17 @@ namespace MathNet.Numerics.Distributions
return "StudentT(μ = " + _location + ", σ = " + _scale + ", ν = " + _freedom + ")";
}
/// <summary>
/// Tests whether the provided values are valid parameters for this distribution.
/// </summary>
/// <param name="location">The location (μ) of the distribution.</param>
/// <param name="scale">The scale (σ) of the distribution. Range: σ > 0.</param>
/// <param name="freedom">The degrees of freedom (ν) for the distribution. Range: ν > 0.</param>
public static bool IsValidParameterSet(double location, double scale, double freedom)
{
return scale > 0.0 && freedom > 0.0;
}
/// <summary>
/// Sets the parameters of the distribution after checking their validity.
/// </summary>

11
src/Numerics/Distributions/Triangular.cs

@ -89,6 +89,17 @@ namespace MathNet.Numerics.Distributions
return "Triangular(Lower = " + _lower + ", Upper = " + _upper + ", Mode = " + _mode + ")";
}
/// <summary>
/// Tests whether the provided values are valid parameters for this distribution.
/// </summary>
/// <param name="lower">Lower bound. Range: lower ≤ mode ≤ upper</param>
/// <param name="upper">Upper bound. Range: lower ≤ mode ≤ upper</param>
/// <param name="mode">Mode (most frequent value). Range: lower ≤ mode ≤ upper</param>
public static bool IsValidParameterSet(double lower, double upper, double mode)
{
return upper >= mode && mode >= lower && !Double.IsInfinity(upper) && !Double.IsInfinity(lower) && !Double.IsInfinity(mode);
}
/// <summary>
/// Sets the parameters of the distribution after checking their validity.
/// </summary>

10
src/Numerics/Distributions/Weibull.cs

@ -93,6 +93,16 @@ namespace MathNet.Numerics.Distributions
return "Weibull(k = " + _shape + ", λ = " + _scale + ")";
}
/// <summary>
/// Tests whether the provided values are valid parameters for this distribution.
/// </summary>
/// <param name="shape">The shape (k) of the Weibull distribution. Range: k > 0.</param>
/// <param name="scale">The scale (λ) of the Weibull distribution. Range: λ > 0.</param>
public static bool IsValidParameterSet(double shape, double scale)
{
return shape > 0.0 && scale > 0.0;
}
/// <summary>
/// Sets the parameters of the distribution after checking their validity.
/// </summary>

41
src/Numerics/Distributions/Wishart.cs

@ -87,30 +87,11 @@ namespace MathNet.Numerics.Distributions
}
/// <summary>
/// Sets the parameters of the distribution after checking their validity.
/// </summary>
/// <param name="degreesOfFreedom">The degrees of freedom (n) for the Wishart distribution.</param>
/// <param name="scale">The scale matrix (V) for the Wishart distribution.</param>
/// <exception cref="ArgumentOutOfRangeException">When the parameters are out of range.</exception>
void SetParameters(double degreesOfFreedom, Matrix<double> scale)
{
if (Control.CheckDistributionParameters && !IsValidParameterSet(degreesOfFreedom, scale))
{
throw new ArgumentException(Resources.InvalidDistributionParameters);
}
_degreesOfFreedom = degreesOfFreedom;
_scale = scale;
_chol = _scale.Cholesky();
}
/// <summary>
/// Checks whether the parameters of the distribution are valid.
/// Tests whether the provided values are valid parameters for this distribution.
/// </summary>
/// <param name="degreesOfFreedom">The degrees of freedom (n) for the Wishart distribution.</param>
/// <param name="scale">The scale matrix (V) for the Wishart distribution.</param>
/// <returns><c>true</c> when the parameters are valid, <c>false</c> otherwise.</returns>
static bool IsValidParameterSet(double degreesOfFreedom, Matrix<double> scale)
public static bool IsValidParameterSet(double degreesOfFreedom, Matrix<double> scale)
{
if (scale.RowCount != scale.ColumnCount)
{
@ -133,6 +114,24 @@ namespace MathNet.Numerics.Distributions
return true;
}
/// <summary>
/// Sets the parameters of the distribution after checking their validity.
/// </summary>
/// <param name="degreesOfFreedom">The degrees of freedom (n) for the Wishart distribution.</param>
/// <param name="scale">The scale matrix (V) for the Wishart distribution.</param>
/// <exception cref="ArgumentOutOfRangeException">When the parameters are out of range.</exception>
void SetParameters(double degreesOfFreedom, Matrix<double> scale)
{
if (Control.CheckDistributionParameters && !IsValidParameterSet(degreesOfFreedom, scale))
{
throw new ArgumentException(Resources.InvalidDistributionParameters);
}
_degreesOfFreedom = degreesOfFreedom;
_scale = scale;
_chol = _scale.Cholesky();
}
/// <summary>
/// Gets or sets the degrees of freedom (n) for the Wishart distribution.
/// </summary>

10
src/Numerics/Distributions/Zipf.cs

@ -89,6 +89,16 @@ namespace MathNet.Numerics.Distributions
return "Zipf(S = " + _s + ", N = " + _n + ")";
}
/// <summary>
/// Tests whether the provided values are valid parameters for this distribution.
/// </summary>
/// <param name="s">The s parameter of the distribution.</param>
/// <param name="n">The n parameter of the distribution.</param>
public static bool IsValidParameterSet(double s, int n)
{
return n > 0 && s > 0.0;
}
/// <summary>
/// Sets the parameters of the distribution after checking their validity.
/// </summary>

Loading…
Cancel
Save