Browse Source

Distributions: upgrade to simpler parameter verification (discrete)

pull/203/head
Christoph Ruegg 12 years ago
parent
commit
3803923670
  1. 38
      src/Numerics/Distributions/Bernoulli.cs
  2. 45
      src/Numerics/Distributions/Binomial.cs
  3. 41
      src/Numerics/Distributions/ConwayMaxwellPoisson.cs
  4. 43
      src/Numerics/Distributions/DiscreteUniform.cs
  5. 40
      src/Numerics/Distributions/Geometric.cs
  6. 50
      src/Numerics/Distributions/Hypergeometric.cs
  7. 2
      src/Numerics/Distributions/IDiscreteDistribution.cs
  8. 42
      src/Numerics/Distributions/NegativeBinomial.cs
  9. 46
      src/Numerics/Distributions/Poisson.cs
  10. 41
      src/Numerics/Distributions/Zipf.cs
  11. 15
      src/UnitTests/DistributionTests/Continuous/BetaTests.cs
  12. 11
      src/UnitTests/DistributionTests/Continuous/CauchyTests.cs
  13. 15
      src/UnitTests/DistributionTests/Continuous/ChiSquareTests.cs
  14. 11
      src/UnitTests/DistributionTests/Continuous/ChiTests.cs
  15. 15
      src/UnitTests/DistributionTests/Continuous/ContinuousUniformTests.cs
  16. 15
      src/UnitTests/DistributionTests/Continuous/ErlangTests.cs
  17. 15
      src/UnitTests/DistributionTests/Continuous/ExponentialTests.cs
  18. 15
      src/UnitTests/DistributionTests/Continuous/FisherSnedecorTests.cs
  19. 15
      src/UnitTests/DistributionTests/Continuous/GammaTests.cs
  20. 15
      src/UnitTests/DistributionTests/Continuous/InverseGammaTests.cs
  21. 15
      src/UnitTests/DistributionTests/Continuous/LaplaceTests.cs
  22. 15
      src/UnitTests/DistributionTests/Continuous/LogNormalTests.cs
  23. 15
      src/UnitTests/DistributionTests/Continuous/NormalTests.cs
  24. 15
      src/UnitTests/DistributionTests/Continuous/ParetoTests.cs
  25. 15
      src/UnitTests/DistributionTests/Continuous/RayleighTests.cs
  26. 15
      src/UnitTests/DistributionTests/Continuous/StableTests.cs
  27. 15
      src/UnitTests/DistributionTests/Continuous/StudentTTests.cs
  28. 15
      src/UnitTests/DistributionTests/Continuous/WeibullTests.cs
  29. 23
      src/UnitTests/DistributionTests/Discrete/BernoulliTests.cs
  30. 23
      src/UnitTests/DistributionTests/Discrete/BinomialTests.cs
  31. 6
      src/UnitTests/DistributionTests/Discrete/CategoricalTests.cs
  32. 21
      src/UnitTests/DistributionTests/Discrete/ConwayMaxwellPoissonTests.cs
  33. 25
      src/UnitTests/DistributionTests/Discrete/DiscreteUniformTests.cs
  34. 19
      src/UnitTests/DistributionTests/Discrete/GeometricTests.cs
  35. 23
      src/UnitTests/DistributionTests/Discrete/HypergeometricTests.cs
  36. 21
      src/UnitTests/DistributionTests/Discrete/NegativeBinomialTests.cs
  37. 19
      src/UnitTests/DistributionTests/Discrete/PoissonTests.cs
  38. 21
      src/UnitTests/DistributionTests/Discrete/ZipfTests.cs

38
src/Numerics/Distributions/Bernoulli.cs

@ -4,7 +4,7 @@
// http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com
//
// Copyright (c) 2009-2013 Math.NET
// Copyright (c) 2009-2014 Math.NET
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
@ -79,16 +79,6 @@ namespace MathNet.Numerics.Distributions
return "Bernoulli(p = " + _p + ")";
}
/// <summary>
/// Checks whether the parameters of the distribution are valid.
/// </summary>
/// <param name="p">The probability (p) of generating one. Range: 0 ≤ p ≤ 1.</param>
/// <returns><c>true</c> when the parameters are valid, <c>false</c> otherwise.</returns>
static bool IsValidParameterSet(double p)
{
return p >= 0.0 && p <= 1.0;
}
/// <summary>
/// Sets the parameters of the distribution after checking their validity.
/// </summary>
@ -96,9 +86,9 @@ namespace MathNet.Numerics.Distributions
/// <exception cref="ArgumentOutOfRangeException">When the parameters are out of range.</exception>
void SetParameters(double p)
{
if (Control.CheckDistributionParameters && !IsValidParameterSet(p))
if (!(p >= 0.0 && p <= 1.0))
{
throw new ArgumentOutOfRangeException(Resources.InvalidDistributionParameters);
throw new ArgumentException(Resources.InvalidDistributionParameters);
}
_p = p;
@ -294,11 +284,7 @@ namespace MathNet.Numerics.Distributions
/// <returns>A sample from the Bernoulli distribution.</returns>
public static int Sample(System.Random rnd, double p)
{
if (Control.CheckDistributionParameters && !IsValidParameterSet(p))
{
throw new ArgumentOutOfRangeException(Resources.InvalidDistributionParameters);
}
if (!(p >= 0.0 && p <= 1.0)) throw new ArgumentException(Resources.InvalidDistributionParameters);
return SampleUnchecked(rnd, p);
}
@ -310,11 +296,7 @@ namespace MathNet.Numerics.Distributions
/// <returns>a sequence of samples from the distribution.</returns>
public static IEnumerable<int> Samples(System.Random rnd, double p)
{
if (Control.CheckDistributionParameters && !IsValidParameterSet(p))
{
throw new ArgumentOutOfRangeException(Resources.InvalidDistributionParameters);
}
if (!(p >= 0.0 && p <= 1.0)) throw new ArgumentException(Resources.InvalidDistributionParameters);
while (true)
{
yield return SampleUnchecked(rnd, p);
@ -328,7 +310,8 @@ namespace MathNet.Numerics.Distributions
/// <returns>A sample from the Bernoulli distribution.</returns>
public static int Sample(double p)
{
return Sample(SystemRandomSource.Default, p);
if (!(p >= 0.0 && p <= 1.0)) throw new ArgumentException(Resources.InvalidDistributionParameters);
return SampleUnchecked(SystemRandomSource.Default, p);
}
/// <summary>
@ -338,7 +321,12 @@ namespace MathNet.Numerics.Distributions
/// <returns>a sequence of samples from the distribution.</returns>
public static IEnumerable<int> Samples(double p)
{
return Samples(SystemRandomSource.Default, p);
if (!(p >= 0.0 && p <= 1.0)) throw new ArgumentException(Resources.InvalidDistributionParameters);
SystemRandomSource rnd = SystemRandomSource.Default;
while (true)
{
yield return SampleUnchecked(rnd, p);
}
}
}

45
src/Numerics/Distributions/Binomial.cs

@ -4,7 +4,7 @@
// http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com
//
// Copyright (c) 2009-2013 Math.NET
// Copyright (c) 2009-2014 Math.NET
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
@ -86,17 +86,6 @@ namespace MathNet.Numerics.Distributions
return "Binomial(p = " + _p + ", n = " + _trials + ")";
}
/// <summary>
/// Checks whether the parameters of the distribution are valid.
/// </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>
/// <returns><c>false</c> <paramref name="p"/> is not in the interval [0.0,1.0] or <paramref name="n"/> is negative, <c>true</c> otherwise.</returns>
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>
@ -106,9 +95,9 @@ namespace MathNet.Numerics.Distributions
/// <exception cref="ArgumentOutOfRangeException">If <paramref name="n"/> is negative.</exception>
void SetParameters(double p, int n)
{
if (Control.CheckDistributionParameters && !IsValidParameterSet(p, n))
if (!(p >= 0.0 && p <= 1.0 && n >= 0))
{
throw new ArgumentOutOfRangeException(Resources.InvalidDistributionParameters);
throw new ArgumentException(Resources.InvalidDistributionParameters);
}
_p = p;
@ -220,7 +209,7 @@ namespace MathNet.Numerics.Distributions
if (_p == 1.0) return _trials;
if (_p == 0.0) return 0;
return (int) Math.Floor((_trials + 1)*_p);
return (int)Math.Floor((_trials + 1)*_p);
}
}
@ -229,7 +218,7 @@ namespace MathNet.Numerics.Distributions
/// </summary>
public int Median
{
get { return (int) Math.Floor(_p*_trials); }
get { return (int)Math.Floor(_p*_trials); }
}
/// <summary>
@ -277,7 +266,7 @@ namespace MathNet.Numerics.Distributions
if (x > _trials) return 1.0;
var cdf = 0.0;
for (var i = 0; i <= (int) Math.Floor(x); i++)
for (var i = 0; i <= (int)Math.Floor(x); i++)
{
cdf += Combinatorics.Combinations(_trials, i)*Math.Pow(_p, i)*Math.Pow(1.0 - _p, _trials - i);
}
@ -333,11 +322,7 @@ namespace MathNet.Numerics.Distributions
/// <returns>The number of successes in <paramref name="n"/> trials.</returns>
public static int Sample(System.Random rnd, double p, int n)
{
if (Control.CheckDistributionParameters && !IsValidParameterSet(p, n))
{
throw new ArgumentOutOfRangeException(Resources.InvalidDistributionParameters);
}
if (!(p >= 0.0 && p <= 1.0 && n >= 0)) throw new ArgumentException(Resources.InvalidDistributionParameters);
return SampleUnchecked(rnd, p, n);
}
@ -350,11 +335,7 @@ namespace MathNet.Numerics.Distributions
/// <returns>a sequence of successes in <paramref name="n"/> trials.</returns>
public static IEnumerable<int> Samples(System.Random rnd, double p, int n)
{
if (Control.CheckDistributionParameters && !IsValidParameterSet(p, n))
{
throw new ArgumentOutOfRangeException(Resources.InvalidDistributionParameters);
}
if (!(p >= 0.0 && p <= 1.0 && n >= 0)) throw new ArgumentException(Resources.InvalidDistributionParameters);
while (true)
{
yield return SampleUnchecked(rnd, p, n);
@ -370,7 +351,8 @@ namespace MathNet.Numerics.Distributions
/// <returns>The number of successes in <paramref name="n"/> trials.</returns>
public static int Sample(double p, int n)
{
return Sample(SystemRandomSource.Default, p, n);
if (!(p >= 0.0 && p <= 1.0 && n >= 0)) throw new ArgumentException(Resources.InvalidDistributionParameters);
return SampleUnchecked(SystemRandomSource.Default, p, n);
}
/// <summary>
@ -382,7 +364,12 @@ namespace MathNet.Numerics.Distributions
/// <returns>a sequence of successes in <paramref name="n"/> trials.</returns>
public static IEnumerable<int> Samples(double p, int n)
{
return Samples(SystemRandomSource.Default, p, n);
if (!(p >= 0.0 && p <= 1.0 && n >= 0)) throw new ArgumentException(Resources.InvalidDistributionParameters);
SystemRandomSource rnd = SystemRandomSource.Default;
while (true)
{
yield return SampleUnchecked(rnd, p, n);
}
}
}
}

41
src/Numerics/Distributions/ConwayMaxwellPoisson.cs

@ -4,7 +4,7 @@
// http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com
//
// Copyright (c) 2009-2013 Math.NET
// Copyright (c) 2009-2014 Math.NET
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
@ -107,17 +107,6 @@ namespace MathNet.Numerics.Distributions
return "ConwayMaxwellPoisson(λ = " + _lambda + ", ν = " + _nu + ")";
}
/// <summary>
/// Checks whether the parameters of the distribution are valid.
/// </summary>
/// <param name="lambda">The lambda (λ) parameter. Range: λ > 0.</param>
/// <param name="nu">The rate of decay (ν) parameter. Range: ν ≥ 0.</param>
/// <returns><c>true</c> when the parameters are valid, <c>false</c> otherwise.</returns>
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>
@ -126,9 +115,9 @@ namespace MathNet.Numerics.Distributions
/// <exception cref="ArgumentOutOfRangeException">When the parameters are out of range.</exception>
void SetParameters(double lambda, double nu)
{
if (Control.CheckDistributionParameters && !IsValidParameterSet(lambda, nu))
if (!(lambda > 0.0 && nu >= 0.0))
{
throw new ArgumentOutOfRangeException(Resources.InvalidDistributionParameters);
throw new ArgumentException(Resources.InvalidDistributionParameters);
}
_lambda = lambda;
@ -493,11 +482,7 @@ namespace MathNet.Numerics.Distributions
/// <param name="nu">The rate of decay (ν) parameter. Range: ν ≥ 0.</param>
public static int Sample(System.Random rnd, double lambda, double nu)
{
if (Control.CheckDistributionParameters && !IsValidParameterSet(lambda, nu))
{
throw new ArgumentOutOfRangeException(Resources.InvalidDistributionParameters);
}
if (!(lambda > 0.0 && nu >= 0.0)) throw new ArgumentException(Resources.InvalidDistributionParameters);
var z = Normalization(lambda, nu);
return SampleUnchecked(rnd, lambda, nu, z);
}
@ -510,11 +495,7 @@ namespace MathNet.Numerics.Distributions
/// <param name="nu">The rate of decay (ν) parameter. Range: ν ≥ 0.</param>
public static IEnumerable<int> Samples(System.Random rnd, double lambda, double nu)
{
if (Control.CheckDistributionParameters && !IsValidParameterSet(lambda, nu))
{
throw new ArgumentOutOfRangeException(Resources.InvalidDistributionParameters);
}
if (!(lambda > 0.0 && nu >= 0.0)) throw new ArgumentException(Resources.InvalidDistributionParameters);
var z = Normalization(lambda, nu);
while (true)
{
@ -529,7 +510,9 @@ namespace MathNet.Numerics.Distributions
/// <param name="nu">The rate of decay (ν) parameter. Range: ν ≥ 0.</param>
public static int Sample(double lambda, double nu)
{
return Sample(SystemRandomSource.Default, lambda, nu);
if (!(lambda > 0.0 && nu >= 0.0)) throw new ArgumentException(Resources.InvalidDistributionParameters);
var z = Normalization(lambda, nu);
return SampleUnchecked(SystemRandomSource.Default, lambda, nu, z);
}
/// <summary>
@ -539,7 +522,13 @@ namespace MathNet.Numerics.Distributions
/// <param name="nu">The rate of decay (ν) parameter. Range: ν ≥ 0.</param>
public static IEnumerable<int> Samples(double lambda, double nu)
{
return Samples(SystemRandomSource.Default, lambda, nu);
if (!(lambda > 0.0 && nu >= 0.0)) throw new ArgumentException(Resources.InvalidDistributionParameters);
var z = Normalization(lambda, nu);
SystemRandomSource rnd = SystemRandomSource.Default;
while (true)
{
yield return SampleUnchecked(rnd, lambda, nu, z);
}
}
}
}

43
src/Numerics/Distributions/DiscreteUniform.cs

@ -4,7 +4,7 @@
// http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com
//
// Copyright (c) 2009-2013 Math.NET
// Copyright (c) 2009-2014 Math.NET
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
@ -82,17 +82,6 @@ namespace MathNet.Numerics.Distributions
return "DiscreteUniform(Lower = " + _lower + ", Upper = " + _upper + ")";
}
/// <summary>
/// Checks whether the parameters of the distribution are valid.
/// </summary>
/// <param name="lower">Lower bound. Range: lower ≤ upper.</param>
/// <param name="upper">Upper bound. Range: lower ≤ upper.</param>
/// <returns><c>true</c> when the parameters are valid, <c>false</c> otherwise.</returns>
static bool IsValidParameterSet(int lower, int upper)
{
return lower <= upper;
}
/// <summary>
/// Sets the parameters of the distribution after checking their validity.
/// </summary>
@ -101,9 +90,9 @@ namespace MathNet.Numerics.Distributions
/// <exception cref="ArgumentOutOfRangeException">When the parameters are out of range.</exception>
void SetParameters(int lower, int upper)
{
if (Control.CheckDistributionParameters && !IsValidParameterSet(lower, upper))
if (!(lower <= upper))
{
throw new ArgumentOutOfRangeException(Resources.InvalidDistributionParameters);
throw new ArgumentException(Resources.InvalidDistributionParameters);
}
_lower = lower;
@ -198,7 +187,7 @@ namespace MathNet.Numerics.Distributions
/// </summary>
public int Mode
{
get { return (int) Math.Floor((_lower + _upper)/2.0); }
get { return (int)Math.Floor((_lower + _upper)/2.0); }
}
/// <summary>
@ -206,7 +195,7 @@ namespace MathNet.Numerics.Distributions
/// </summary>
public int Median
{
get { return (int) Math.Floor((_lower + _upper)/2.0); }
get { return (int)Math.Floor((_lower + _upper)/2.0); }
}
/// <summary>
@ -301,11 +290,7 @@ namespace MathNet.Numerics.Distributions
/// <returns>A sample from the discrete uniform distribution.</returns>
public static int Sample(System.Random rnd, int lower, int upper)
{
if (Control.CheckDistributionParameters && !IsValidParameterSet(lower, upper))
{
throw new ArgumentOutOfRangeException(Resources.InvalidDistributionParameters);
}
if (!(lower <= upper)) throw new ArgumentException(Resources.InvalidDistributionParameters);
return SampleUnchecked(rnd, lower, upper);
}
@ -318,11 +303,7 @@ namespace MathNet.Numerics.Distributions
/// <returns>a sequence of samples from the discrete uniform distribution.</returns>
public static IEnumerable<int> Samples(System.Random rnd, int lower, int upper)
{
if (Control.CheckDistributionParameters && !IsValidParameterSet(lower, upper))
{
throw new ArgumentOutOfRangeException(Resources.InvalidDistributionParameters);
}
if (!(lower <= upper)) throw new ArgumentException(Resources.InvalidDistributionParameters);
while (true)
{
yield return SampleUnchecked(rnd, lower, upper);
@ -337,7 +318,8 @@ namespace MathNet.Numerics.Distributions
/// <returns>A sample from the discrete uniform distribution.</returns>
public static int Sample(int lower, int upper)
{
return Sample(SystemRandomSource.Default, lower, upper);
if (!(lower <= upper)) throw new ArgumentException(Resources.InvalidDistributionParameters);
return SampleUnchecked(SystemRandomSource.Default, lower, upper);
}
/// <summary>
@ -348,7 +330,12 @@ namespace MathNet.Numerics.Distributions
/// <returns>a sequence of samples from the discrete uniform distribution.</returns>
public static IEnumerable<int> Samples(int lower, int upper)
{
return Samples(SystemRandomSource.Default, lower, upper);
if (!(lower <= upper)) throw new ArgumentException(Resources.InvalidDistributionParameters);
SystemRandomSource rnd = SystemRandomSource.Default;
while (true)
{
yield return SampleUnchecked(rnd, lower, upper);
}
}
}
}

40
src/Numerics/Distributions/Geometric.cs

@ -4,7 +4,7 @@
// http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com
//
// Copyright (c) 2009-2013 Math.NET
// Copyright (c) 2009-2014 Math.NET
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
@ -77,16 +77,6 @@ namespace MathNet.Numerics.Distributions
return "Geometric(p = " + _p + ")";
}
/// <summary>
/// Checks whether the parameters of the distribution are valid.
/// </summary>
/// <param name="p">The probability (p) of generating one. Range: 0 ≤ p ≤ 1.</param>
/// <returns><c>true</c> when the parameters are valid, <c>false</c> otherwise.</returns>
static bool IsValidParameterSet(double p)
{
return p >= 0.0 && p <= 1.0;
}
/// <summary>
/// Sets the parameters of the distribution after checking their validity.
/// </summary>
@ -94,9 +84,9 @@ namespace MathNet.Numerics.Distributions
/// <exception cref="ArgumentOutOfRangeException">When the parameters are out of range.</exception>
void SetParameters(double p)
{
if (Control.CheckDistributionParameters && !IsValidParameterSet(p))
if (!(p >= 0.0 && p <= 1.0))
{
throw new ArgumentOutOfRangeException(Resources.InvalidDistributionParameters);
throw new ArgumentException(Resources.InvalidDistributionParameters);
}
_p = p;
@ -174,7 +164,7 @@ namespace MathNet.Numerics.Distributions
/// </summary>
public int Median
{
get { return (int) Math.Ceiling(-Constants.Ln2/Math.Log(1 - _p)); }
get { return (int)Math.Ceiling(-Constants.Ln2/Math.Log(1 - _p)); }
}
/// <summary>
@ -272,11 +262,7 @@ namespace MathNet.Numerics.Distributions
/// <param name="p">The probability (p) of generating one. Range: 0 ≤ p ≤ 1.</param>
public static int Sample(System.Random rnd, double p)
{
if (Control.CheckDistributionParameters && !IsValidParameterSet(p))
{
throw new ArgumentOutOfRangeException(Resources.InvalidDistributionParameters);
}
if (!(p >= 0.0 && p <= 1.0)) throw new ArgumentException(Resources.InvalidDistributionParameters);
return SampleUnchecked(rnd, p);
}
@ -287,11 +273,7 @@ namespace MathNet.Numerics.Distributions
/// <param name="p">The probability (p) of generating one. Range: 0 ≤ p ≤ 1.</param>
public static IEnumerable<int> Samples(System.Random rnd, double p)
{
if (Control.CheckDistributionParameters && !IsValidParameterSet(p))
{
throw new ArgumentOutOfRangeException(Resources.InvalidDistributionParameters);
}
if (!(p >= 0.0 && p <= 1.0)) throw new ArgumentException(Resources.InvalidDistributionParameters);
while (true)
{
yield return SampleUnchecked(rnd, p);
@ -304,7 +286,8 @@ namespace MathNet.Numerics.Distributions
/// <param name="p">The probability (p) of generating one. Range: 0 ≤ p ≤ 1.</param>
public static int Sample(double p)
{
return Sample(SystemRandomSource.Default, p);
if (!(p >= 0.0 && p <= 1.0)) throw new ArgumentException(Resources.InvalidDistributionParameters);
return SampleUnchecked(SystemRandomSource.Default, p);
}
/// <summary>
@ -313,7 +296,12 @@ namespace MathNet.Numerics.Distributions
/// <param name="p">The probability (p) of generating one. Range: 0 ≤ p ≤ 1.</param>
public static IEnumerable<int> Samples(double p)
{
return Samples(SystemRandomSource.Default, p);
if (!(p >= 0.0 && p <= 1.0)) throw new ArgumentException(Resources.InvalidDistributionParameters);
SystemRandomSource rnd = SystemRandomSource.Default;
while (true)
{
yield return SampleUnchecked(rnd, p);
}
}
}
}

50
src/Numerics/Distributions/Hypergeometric.cs

@ -4,7 +4,7 @@
// http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com
//
// Copyright (c) 2009-2013 Math.NET
// Copyright (c) 2009-2014 Math.NET
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
@ -86,18 +86,6 @@ namespace MathNet.Numerics.Distributions
return "Hypergeometric(N = " + _population + ", M = " + _success + ", n = " + _draws + ")";
}
/// <summary>
/// Checks whether the parameters of the distribution are valid.
/// </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>
/// <returns><c>true</c> when the parameters are valid, <c>false</c> otherwise.</returns>
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>
@ -107,9 +95,9 @@ namespace MathNet.Numerics.Distributions
/// <exception cref="ArgumentOutOfRangeException">When the parameters are out of range.</exception>
void SetParameters(int population, int success, int draws)
{
if (Control.CheckDistributionParameters && !IsValidParameterSet(population, success, draws))
if (!(population >= 0 && success >= 0 && draws >= 0 && success <= population && draws <= population))
{
throw new ArgumentOutOfRangeException(Resources.InvalidDistributionParameters);
throw new ArgumentException(Resources.InvalidDistributionParameters);
}
_population = population;
@ -188,7 +176,7 @@ namespace MathNet.Numerics.Distributions
/// </summary>
public double Mean
{
get { return (double) _success*_draws/_population; }
get { return (double)_success*_draws/_population; }
}
/// <summary>
@ -291,7 +279,7 @@ namespace MathNet.Numerics.Distributions
return 1.0;
}
var k = (int) Math.Floor(x);
var k = (int)Math.Floor(x);
var denominatorLn = SpecialFunctions.BinomialLn(_population, _draws);
var sum = 0.0;
for (var i = 0; i <= k; i++)
@ -315,7 +303,7 @@ namespace MathNet.Numerics.Distributions
do
{
var p = (double) success/population;
var p = (double)success/population;
var r = rnd.NextDouble();
if (r < p)
{
@ -360,9 +348,9 @@ namespace MathNet.Numerics.Distributions
/// <param name="draws">The number of draws without replacement (n).</param>
public static int Sample(System.Random rnd, int population, int success, int draws)
{
if (Control.CheckDistributionParameters && !IsValidParameterSet(population, success, draws))
if (!(population >= 0 && success >= 0 && draws >= 0 && success <= population && draws <= population))
{
throw new ArgumentOutOfRangeException(Resources.InvalidDistributionParameters);
throw new ArgumentException(Resources.InvalidDistributionParameters);
}
return SampleUnchecked(rnd, population, success, draws);
@ -377,9 +365,9 @@ namespace MathNet.Numerics.Distributions
/// <param name="draws">The number of draws without replacement (n).</param>
public static IEnumerable<int> Samples(System.Random rnd, int population, int success, int draws)
{
if (Control.CheckDistributionParameters && !IsValidParameterSet(population, success, draws))
if (!(population >= 0 && success >= 0 && draws >= 0 && success <= population && draws <= population))
{
throw new ArgumentOutOfRangeException(Resources.InvalidDistributionParameters);
throw new ArgumentException(Resources.InvalidDistributionParameters);
}
while (true)
@ -396,7 +384,12 @@ namespace MathNet.Numerics.Distributions
/// <param name="draws">The number of draws without replacement (n).</param>
public static int Sample(int population, int success, int draws)
{
return Sample(SystemRandomSource.Default, population, success, draws);
if (!(population >= 0 && success >= 0 && draws >= 0 && success <= population && draws <= population))
{
throw new ArgumentException(Resources.InvalidDistributionParameters);
}
return SampleUnchecked(SystemRandomSource.Default, population, success, draws);
}
/// <summary>
@ -407,7 +400,16 @@ namespace MathNet.Numerics.Distributions
/// <param name="draws">The number of draws without replacement (n).</param>
public static IEnumerable<int> Samples(int population, int success, int draws)
{
return Samples(SystemRandomSource.Default, population, success, draws);
if (!(population >= 0 && success >= 0 && draws >= 0 && success <= population && draws <= population))
{
throw new ArgumentException(Resources.InvalidDistributionParameters);
}
SystemRandomSource rnd = SystemRandomSource.Default;
while (true)
{
yield return SampleUnchecked(rnd, population, success, draws);
}
}
}
}

2
src/Numerics/Distributions/IDiscreteDistribution.cs

@ -4,7 +4,7 @@
// http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com
//
// Copyright (c) 2009-2013 Math.NET
// Copyright (c) 2009-2014 Math.NET
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation

42
src/Numerics/Distributions/NegativeBinomial.cs

@ -4,7 +4,7 @@
// http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com
//
// Copyright (c) 2009-2013 Math.NET
// Copyright (c) 2009-2014 Math.NET
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
@ -83,17 +83,6 @@ namespace MathNet.Numerics.Distributions
return "NegativeBinomial(R = " + _trials + ", P = " + _p + ")";
}
/// <summary>
/// Checks whether the parameters of the distribution are valid.
/// </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>
/// <returns><c>true</c> when the parameters are valid, <c>false</c> otherwise.</returns>
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>
@ -102,9 +91,9 @@ namespace MathNet.Numerics.Distributions
/// <exception cref="ArgumentOutOfRangeException">When the parameters are out of range.</exception>
void SetParameters(double r, double p)
{
if (Control.CheckDistributionParameters && !IsValidParameterSet(r, p))
if (!(r >= 0.0 && p >= 0.0 && p <= 1.0))
{
throw new ArgumentOutOfRangeException(Resources.InvalidDistributionParameters);
throw new ArgumentException(Resources.InvalidDistributionParameters);
}
_p = p;
@ -137,6 +126,7 @@ namespace MathNet.Numerics.Distributions
get { return _random; }
set { _random = value ?? SystemRandomSource.Default; }
}
/// <summary>
/// Gets the mean of the distribution.
/// </summary>
@ -182,7 +172,7 @@ namespace MathNet.Numerics.Distributions
/// </summary>
public int Mode
{
get { return _trials > 1.0 ? (int) Math.Floor((_trials - 1.0)*(1.0 - _p)/_p) : 0; }
get { return _trials > 1.0 ? (int)Math.Floor((_trials - 1.0)*(1.0 - _p)/_p) : 0; }
}
/// <summary>
@ -299,11 +289,7 @@ namespace MathNet.Numerics.Distributions
/// <param name="p">The probability (p) of a trial resulting in success. Range: 0 ≤ p ≤ 1.</param>
public static int Sample(System.Random rnd, double r, double p)
{
if (Control.CheckDistributionParameters && !IsValidParameterSet(r, p))
{
throw new ArgumentOutOfRangeException(Resources.InvalidDistributionParameters);
}
if (!(r >= 0.0 && p >= 0.0 && p <= 1.0)) throw new ArgumentException(Resources.InvalidDistributionParameters);
return SampleUnchecked(rnd, r, p);
}
@ -315,11 +301,7 @@ namespace MathNet.Numerics.Distributions
/// <param name="p">The probability (p) of a trial resulting in success. Range: 0 ≤ p ≤ 1.</param>
public static IEnumerable<int> Samples(System.Random rnd, double r, double p)
{
if (Control.CheckDistributionParameters && !IsValidParameterSet(r, p))
{
throw new ArgumentOutOfRangeException(Resources.InvalidDistributionParameters);
}
if (!(r >= 0.0 && p >= 0.0 && p <= 1.0)) throw new ArgumentException(Resources.InvalidDistributionParameters);
while (true)
{
yield return SampleUnchecked(rnd, r, p);
@ -333,7 +315,8 @@ namespace MathNet.Numerics.Distributions
/// <param name="p">The probability (p) of a trial resulting in success. Range: 0 ≤ p ≤ 1.</param>
public static int Sample(double r, double p)
{
return Sample(SystemRandomSource.Default, r, p);
if (!(r >= 0.0 && p >= 0.0 && p <= 1.0)) throw new ArgumentException(Resources.InvalidDistributionParameters);
return SampleUnchecked(SystemRandomSource.Default, r, p);
}
/// <summary>
@ -343,7 +326,12 @@ namespace MathNet.Numerics.Distributions
/// <param name="p">The probability (p) of a trial resulting in success. Range: 0 ≤ p ≤ 1.</param>
public static IEnumerable<int> Samples(double r, double p)
{
return Samples(SystemRandomSource.Default, r, p);
if (!(r >= 0.0 && p >= 0.0 && p <= 1.0)) throw new ArgumentException(Resources.InvalidDistributionParameters);
SystemRandomSource rnd = SystemRandomSource.Default;
while (true)
{
yield return SampleUnchecked(rnd, r, p);
}
}
}
}

46
src/Numerics/Distributions/Poisson.cs

@ -4,7 +4,7 @@
// http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com
//
// Copyright (c) 2009-2013 Math.NET
// Copyright (c) 2009-2014 Math.NET
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
@ -38,7 +38,7 @@ namespace MathNet.Numerics.Distributions
/// <summary>
/// Discrete Univariate Poisson distribution.
/// </summary>
/// <remarks>
/// <remarks>
/// <para>Distribution is described at <a href="http://en.wikipedia.org/wiki/Poisson_distribution"> Wikipedia - Poisson distribution</a>.</para>
/// <para>Knuth's method is used to generate Poisson distributed random variables.</para>
/// <para>f(x) = exp(-λ)*λ^x/x!;</para>
@ -83,16 +83,6 @@ namespace MathNet.Numerics.Distributions
return "Poisson(λ = " + _lambda + ")";
}
/// <summary>
/// Checks whether the parameters of the distribution are valid.
/// </summary>
/// <param name="lambda">The lambda (λ) parameter of the Poisson distribution. Range: λ > 0.</param>
/// <returns><c>true</c> when the parameters are valid, <c>false</c> otherwise.</returns>
static bool IsValidParameterSet(double lambda)
{
return lambda > 0.00;
}
/// <summary>
/// Sets the parameters of the distribution after checking their validity.
/// </summary>
@ -100,9 +90,9 @@ namespace MathNet.Numerics.Distributions
/// <exception cref="ArgumentOutOfRangeException">When the parameters are out of range.</exception>
void SetParameters(double lambda)
{
if (Control.CheckDistributionParameters && !IsValidParameterSet(lambda))
if (!(lambda > 0.0))
{
throw new ArgumentOutOfRangeException(Resources.InvalidDistributionParameters);
throw new ArgumentException(Resources.InvalidDistributionParameters);
}
_lambda = lambda;
@ -188,7 +178,7 @@ namespace MathNet.Numerics.Distributions
/// </summary>
public int Mode
{
get { return (int) Math.Floor(_lambda); }
get { return (int)Math.Floor(_lambda); }
}
/// <summary>
@ -197,7 +187,7 @@ namespace MathNet.Numerics.Distributions
/// <remarks>Approximation, see Wikipedia <a href="http://en.wikipedia.org/wiki/Poisson_distribution">Poisson distribution</a></remarks>
public int Median
{
get { return (int) Math.Floor(_lambda + (1.0/3.0) - (0.02/_lambda)); }
get { return (int)Math.Floor(_lambda + (1.0/3.0) - (0.02/_lambda)); }
}
/// <summary>
@ -279,7 +269,7 @@ namespace MathNet.Numerics.Distributions
{
var u = rnd.NextDouble();
var x = (alpha - Math.Log((1.0 - u)/u))/beta;
var n = (int) Math.Floor(x + 0.5);
var n = (int)Math.Floor(x + 0.5);
if (n < 0)
{
continue;
@ -326,11 +316,7 @@ namespace MathNet.Numerics.Distributions
/// <returns>A sample from the Poisson distribution.</returns>
public static int Sample(System.Random rnd, double lambda)
{
if (Control.CheckDistributionParameters && !IsValidParameterSet(lambda))
{
throw new ArgumentOutOfRangeException(Resources.InvalidDistributionParameters);
}
if (!(lambda > 0.0)) throw new ArgumentException(Resources.InvalidDistributionParameters);
return SampleUnchecked(rnd, lambda);
}
@ -342,11 +328,7 @@ namespace MathNet.Numerics.Distributions
/// <returns>a sequence of samples from the distribution.</returns>
public static IEnumerable<int> Samples(System.Random rnd, double lambda)
{
if (Control.CheckDistributionParameters && !IsValidParameterSet(lambda))
{
throw new ArgumentOutOfRangeException(Resources.InvalidDistributionParameters);
}
if (!(lambda > 0.0)) throw new ArgumentException(Resources.InvalidDistributionParameters);
while (true)
{
yield return SampleUnchecked(rnd, lambda);
@ -360,7 +342,8 @@ namespace MathNet.Numerics.Distributions
/// <returns>A sample from the Poisson distribution.</returns>
public static int Sample(double lambda)
{
return Sample(SystemRandomSource.Default, lambda);
if (!(lambda > 0.0)) throw new ArgumentException(Resources.InvalidDistributionParameters);
return SampleUnchecked(SystemRandomSource.Default, lambda);
}
/// <summary>
@ -370,7 +353,12 @@ namespace MathNet.Numerics.Distributions
/// <returns>a sequence of samples from the distribution.</returns>
public static IEnumerable<int> Samples(double lambda)
{
return Samples(SystemRandomSource.Default, lambda);
if (!(lambda > 0.0)) throw new ArgumentException(Resources.InvalidDistributionParameters);
SystemRandomSource rnd = SystemRandomSource.Default;
while (true)
{
yield return SampleUnchecked(rnd, lambda);
}
}
}
}

41
src/Numerics/Distributions/Zipf.cs

@ -4,7 +4,7 @@
// http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com
//
// Copyright (c) 2009-2013 Math.NET
// Copyright (c) 2009-2014 Math.NET
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
@ -89,17 +89,6 @@ namespace MathNet.Numerics.Distributions
return "Zipf(S = " + _s + ", N = " + _n + ")";
}
/// <summary>
/// Checks whether the parameters of the distribution are valid.
/// </summary>
/// <param name="s">The s parameter of the distribution.</param>
/// <param name="n">The n parameter of the distribution.</param>
/// <returns><c>true</c> when the parameters are valid, <c>false</c> otherwise.</returns>
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>
@ -108,9 +97,9 @@ namespace MathNet.Numerics.Distributions
/// <exception cref="ArgumentOutOfRangeException">When the parameters are out of range.</exception>
void SetParameters(double s, int n)
{
if (Control.CheckDistributionParameters && !IsValidParameterSet(s, n))
if (!(n > 0 && s > 0.0))
{
throw new ArgumentOutOfRangeException(Resources.InvalidDistributionParameters);
throw new ArgumentException(Resources.InvalidDistributionParameters);
}
_s = s;
@ -275,7 +264,7 @@ namespace MathNet.Numerics.Distributions
return 0.0;
}
return SpecialFunctions.GeneralHarmonic((int) x, _s)/SpecialFunctions.GeneralHarmonic(_n, _s);
return SpecialFunctions.GeneralHarmonic((int)x, _s)/SpecialFunctions.GeneralHarmonic(_n, _s);
}
/// <summary>
@ -337,11 +326,7 @@ namespace MathNet.Numerics.Distributions
/// <param name="n">The n parameter of the distribution.</param>
public static int Sample(System.Random rnd, double s, int n)
{
if (Control.CheckDistributionParameters && !IsValidParameterSet(s, n))
{
throw new ArgumentOutOfRangeException(Resources.InvalidDistributionParameters);
}
if (!(n > 0 && s > 0.0)) throw new ArgumentException(Resources.InvalidDistributionParameters);
return SampleUnchecked(rnd, s, n);
}
@ -353,11 +338,7 @@ namespace MathNet.Numerics.Distributions
/// <param name="n">The n parameter of the distribution.</param>
public static IEnumerable<int> Samples(System.Random rnd, double s, int n)
{
if (Control.CheckDistributionParameters && !IsValidParameterSet(s, n))
{
throw new ArgumentOutOfRangeException(Resources.InvalidDistributionParameters);
}
if (!(n > 0 && s > 0.0)) throw new ArgumentException(Resources.InvalidDistributionParameters);
while (true)
{
yield return SampleUnchecked(rnd, s, n);
@ -371,7 +352,8 @@ namespace MathNet.Numerics.Distributions
/// <param name="n">The n parameter of the distribution.</param>
public static int Sample(double s, int n)
{
return Sample(SystemRandomSource.Default, s, n);
if (!(n > 0 && s > 0.0)) throw new ArgumentException(Resources.InvalidDistributionParameters);
return SampleUnchecked(SystemRandomSource.Default, s, n);
}
/// <summary>
@ -381,7 +363,12 @@ namespace MathNet.Numerics.Distributions
/// <param name="n">The n parameter of the distribution.</param>
public static IEnumerable<int> Samples(double s, int n)
{
return Samples(SystemRandomSource.Default, s, n);
if (!(n > 0 && s > 0.0)) throw new ArgumentException(Resources.InvalidDistributionParameters);
SystemRandomSource rnd = SystemRandomSource.Default;
while (true)
{
yield return SampleUnchecked(rnd, s, n);
}
}
}
}

15
src/UnitTests/DistributionTests/Continuous/BetaTests.cs

@ -3,7 +3,9 @@
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com
// Copyright (c) 2009-2010 Math.NET
//
// Copyright (c) 2009-2014 Math.NET
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
@ -12,8 +14,10 @@
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
@ -39,15 +43,6 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
[TestFixture, Category("Distributions")]
public class BetaTests
{
/// <summary>
/// Set-up parameters.
/// </summary>
[SetUp]
public void SetUp()
{
Control.CheckDistributionParameters = true;
}
/// <summary>
/// Can create Beta distribution.
/// </summary>

11
src/UnitTests/DistributionTests/Continuous/CauchyTests.cs

@ -4,7 +4,7 @@
// http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com
//
// Copyright (c) 2009-2013 Math.NET
// Copyright (c) 2009-2014 Math.NET
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
@ -41,15 +41,6 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
[TestFixture, Category("Distributions")]
public class CauchyTests
{
/// <summary>
/// Set-up parameters.
/// </summary>
[SetUp]
public void SetUp()
{
Control.CheckDistributionParameters = true;
}
/// <summary>
/// Can create Cauchy.
/// </summary>

15
src/UnitTests/DistributionTests/Continuous/ChiSquareTests.cs

@ -3,7 +3,9 @@
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com
// Copyright (c) 2009-2010 Math.NET
//
// Copyright (c) 2009-2014 Math.NET
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
@ -12,8 +14,10 @@
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
@ -39,15 +43,6 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
[TestFixture, Category("Distributions")]
public class ChiSquareTests
{
/// <summary>
/// Set-up parameters.
/// </summary>
[SetUp]
public void SetUp()
{
Control.CheckDistributionParameters = true;
}
/// <summary>
/// Can create chi square.
/// </summary>

11
src/UnitTests/DistributionTests/Continuous/ChiTests.cs

@ -4,7 +4,7 @@
// http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com
//
// Copyright (c) 2009-2013 Math.NET
// Copyright (c) 2009-2014 Math.NET
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
@ -41,15 +41,6 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
[TestFixture, Category("Distributions")]
public class ChiTests
{
/// <summary>
/// Set-up parameters.
/// </summary>
[SetUp]
public void SetUp()
{
Control.CheckDistributionParameters = true;
}
/// <summary>
/// Can create chi.
/// </summary>

15
src/UnitTests/DistributionTests/Continuous/ContinuousUniformTests.cs

@ -3,7 +3,9 @@
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com
// Copyright (c) 2009-2010 Math.NET
//
// Copyright (c) 2009-2014 Math.NET
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
@ -12,8 +14,10 @@
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
@ -39,15 +43,6 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
[TestFixture, Category("Distributions")]
public class ContinuousUniformTests
{
/// <summary>
/// Set-up parameters.
/// </summary>
[SetUp]
public void SetUp()
{
Control.CheckDistributionParameters = true;
}
/// <summary>
/// Can create continuous uniform.
/// </summary>

15
src/UnitTests/DistributionTests/Continuous/ErlangTests.cs

@ -3,7 +3,9 @@
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com
// Copyright (c) 2009-2010 Math.NET
//
// Copyright (c) 2009-2014 Math.NET
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
@ -12,8 +14,10 @@
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
@ -37,15 +41,6 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
[TestFixture, Category("Distributions")]
public class ErlangTests
{
/// <summary>
/// Set-up parameters.
/// </summary>
[SetUp]
public void SetUp()
{
Control.CheckDistributionParameters = true;
}
/// <summary>
/// Can create Erlang.
/// </summary>

15
src/UnitTests/DistributionTests/Continuous/ExponentialTests.cs

@ -3,7 +3,9 @@
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com
// Copyright (c) 2009-2010 Math.NET
//
// Copyright (c) 2009-2014 Math.NET
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
@ -12,8 +14,10 @@
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
@ -37,15 +41,6 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
[TestFixture, Category("Distributions")]
public class ExponentialTests
{
/// <summary>
/// Set-up parameters.
/// </summary>
[SetUp]
public void SetUp()
{
Control.CheckDistributionParameters = true;
}
/// <summary>
/// Can create exponential.
/// </summary>

15
src/UnitTests/DistributionTests/Continuous/FisherSnedecorTests.cs

@ -3,7 +3,9 @@
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com
// Copyright (c) 2009-2010 Math.NET
//
// Copyright (c) 2009-2014 Math.NET
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
@ -12,8 +14,10 @@
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
@ -37,15 +41,6 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
[TestFixture, Category("Distributions")]
public class FisherSnedecorTests
{
/// <summary>
/// Set-up parameters.
/// </summary>
[SetUp]
public void SetUp()
{
Control.CheckDistributionParameters = true;
}
/// <summary>
/// Can create fisher snedecor.
/// </summary>

15
src/UnitTests/DistributionTests/Continuous/GammaTests.cs

@ -3,7 +3,9 @@
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com
// Copyright (c) 2009-2010 Math.NET
//
// Copyright (c) 2009-2014 Math.NET
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
@ -12,8 +14,10 @@
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
@ -39,15 +43,6 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
[TestFixture, Category("Distributions")]
public class GammaTests
{
/// <summary>
/// Set-up parameters.
/// </summary>
[SetUp]
public void SetUp()
{
Control.CheckDistributionParameters = true;
}
/// <summary>
/// Can create gamma.
/// </summary>

15
src/UnitTests/DistributionTests/Continuous/InverseGammaTests.cs

@ -3,7 +3,9 @@
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com
// Copyright (c) 2009-2010 Math.NET
//
// Copyright (c) 2009-2014 Math.NET
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
@ -12,8 +14,10 @@
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
@ -37,15 +41,6 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
[TestFixture, Category("Distributions")]
public class InverseGammaTests
{
/// <summary>
/// Set-up parameters.
/// </summary>
[SetUp]
public void SetUp()
{
Control.CheckDistributionParameters = true;
}
/// <summary>
/// Can create inverse gamma.
/// </summary>

15
src/UnitTests/DistributionTests/Continuous/LaplaceTests.cs

@ -3,7 +3,9 @@
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com
// Copyright (c) 2009-2010 Math.NET
//
// Copyright (c) 2009-2014 Math.NET
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
@ -12,8 +14,10 @@
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
@ -37,15 +41,6 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
[TestFixture, Category("Distributions")]
public class LaplaceTests
{
/// <summary>
/// Set-up parameters.
/// </summary>
[SetUp]
public void SetUp()
{
Control.CheckDistributionParameters = true;
}
/// <summary>
/// Can create Laplace.
/// </summary>

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

@ -3,7 +3,9 @@
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com
// Copyright (c) 2009-2010 Math.NET
//
// Copyright (c) 2009-2014 Math.NET
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
@ -12,8 +14,10 @@
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
@ -39,15 +43,6 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
[TestFixture, Category("Distributions")]
public class LogNormalTests
{
/// <summary>
/// Set-up parameters.
/// </summary>
[SetUp]
public void SetUp()
{
Control.CheckDistributionParameters = true;
}
/// <summary>
/// Can create <c>LogNormal</c>.
/// </summary>

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

@ -3,7 +3,9 @@
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com
// Copyright (c) 2009-2010 Math.NET
//
// Copyright (c) 2009-2014 Math.NET
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
@ -12,8 +14,10 @@
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
@ -39,15 +43,6 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
[TestFixture, Category("Distributions")]
public class NormalTests
{
/// <summary>
/// Set-up parameters.
/// </summary>
[SetUp]
public void SetUp()
{
Control.CheckDistributionParameters = true;
}
/// <summary>
/// Can create standard normal.
/// </summary>

15
src/UnitTests/DistributionTests/Continuous/ParetoTests.cs

@ -3,7 +3,9 @@
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com
// Copyright (c) 2009-2010 Math.NET
//
// Copyright (c) 2009-2014 Math.NET
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
@ -12,8 +14,10 @@
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
@ -37,15 +41,6 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
[TestFixture, Category("Distributions")]
public class ParetoTests
{
/// <summary>
/// Set-up parameters.
/// </summary>
[SetUp]
public void SetUp()
{
Control.CheckDistributionParameters = true;
}
/// <summary>
/// Can create Pareto distribution.
/// </summary>

15
src/UnitTests/DistributionTests/Continuous/RayleighTests.cs

@ -3,7 +3,9 @@
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com
// Copyright (c) 2009-2010 Math.NET
//
// Copyright (c) 2009-2014 Math.NET
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
@ -12,8 +14,10 @@
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
@ -37,15 +41,6 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
[TestFixture, Category("Distributions")]
public class RayleighTests
{
/// <summary>
/// Set-up parameters.
/// </summary>
[SetUp]
public void SetUp()
{
Control.CheckDistributionParameters = true;
}
/// <summary>
/// Can create Rayleigh
/// </summary>

15
src/UnitTests/DistributionTests/Continuous/StableTests.cs

@ -3,7 +3,9 @@
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com
// Copyright (c) 2009-2010 Math.NET
//
// Copyright (c) 2009-2014 Math.NET
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
@ -12,8 +14,10 @@
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
@ -37,15 +41,6 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
[TestFixture, Category("Distributions")]
public class StableTests
{
/// <summary>
/// Set-up parameters.
/// </summary>
[SetUp]
public void SetUp()
{
Control.CheckDistributionParameters = true;
}
/// <summary>
/// Can create stable.
/// </summary>

15
src/UnitTests/DistributionTests/Continuous/StudentTTests.cs

@ -3,7 +3,9 @@
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com
// Copyright (c) 2009-2010 Math.NET
//
// Copyright (c) 2009-2014 Math.NET
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
@ -12,8 +14,10 @@
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
@ -39,15 +43,6 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
[TestFixture, Category("Distributions")]
public class StudentTTests
{
/// <summary>
/// Set-up parameters.
/// </summary>
[SetUp]
public void SetUp()
{
Control.CheckDistributionParameters = true;
}
/// <summary>
/// Can create standard <c>StudentT</c>.
/// </summary>

15
src/UnitTests/DistributionTests/Continuous/WeibullTests.cs

@ -3,7 +3,9 @@
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com
// Copyright (c) 2009-2010 Math.NET
//
// Copyright (c) 2009-2014 Math.NET
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
@ -12,8 +14,10 @@
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
@ -39,15 +43,6 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
[TestFixture, Category("Distributions")]
public class WeibullTests
{
/// <summary>
/// Set-up parameters.
/// </summary>
[SetUp]
public void SetUp()
{
Control.CheckDistributionParameters = true;
}
/// <summary>
/// Can create Weibull.
/// </summary>

23
src/UnitTests/DistributionTests/Discrete/BernoulliTests.cs

@ -3,7 +3,9 @@
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com
// Copyright (c) 2009-2010 Math.NET
//
// Copyright (c) 2009-2014 Math.NET
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
@ -12,8 +14,10 @@
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
@ -37,15 +41,6 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
[TestFixture, Category("Distributions")]
public class BernoulliTests
{
/// <summary>
/// Set-up parameters.
/// </summary>
[SetUp]
public void SetUp()
{
Control.CheckDistributionParameters = true;
}
/// <summary>
/// Can create Bernoulli.
/// </summary>
@ -68,7 +63,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
[TestCase(2.0)]
public void BernoulliCreateFailsWithBadParameters(double p)
{
Assert.Throws<ArgumentOutOfRangeException>(() => new Bernoulli(p));
Assert.That(() => new Bernoulli(p), Throws.ArgumentException);
}
/// <summary>
@ -106,7 +101,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
public void SetProbabilityOfOneFails(double p)
{
var b = new Bernoulli(0.3);
Assert.Throws<ArgumentOutOfRangeException>(() => b.P = p);
Assert.That(() => b.P = p, Throws.ArgumentException);
}
/// <summary>
@ -252,7 +247,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
[Test]
public void FailSampleStatic()
{
Assert.Throws<ArgumentOutOfRangeException>(() => Bernoulli.Sample(new Random(0), -1.0));
Assert.That(() => Bernoulli.Sample(new Random(0), -1.0), Throws.ArgumentException);
}
/// <summary>
@ -261,7 +256,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
[Test]
public void FailSampleSequenceStatic()
{
Assert.Throws<ArgumentOutOfRangeException>(() => Bernoulli.Samples(new Random(0), -1.0).First());
Assert.That(() => Bernoulli.Samples(new Random(0), -1.0).First(), Throws.ArgumentException);
}
/// <summary>

23
src/UnitTests/DistributionTests/Discrete/BinomialTests.cs

@ -3,7 +3,9 @@
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com
// Copyright (c) 2009-2010 Math.NET
//
// Copyright (c) 2009-2014 Math.NET
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
@ -12,8 +14,10 @@
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
@ -37,15 +41,6 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
[TestFixture, Category("Distributions")]
public class BinomialTests
{
/// <summary>
/// Set-up parameters.
/// </summary>
[SetUp]
public void SetUp()
{
Control.CheckDistributionParameters = true;
}
/// <summary>
/// Can create binomial.
/// </summary>
@ -71,7 +66,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
[TestCase(0.3, -2)]
public void BinomialCreateFailsWithBadParameters(double p, int n)
{
Assert.Throws<ArgumentOutOfRangeException>(() => new Binomial(p, n));
Assert.That(() => new Binomial(p, n), Throws.ArgumentException);
}
/// <summary>
@ -110,7 +105,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
public void SetProbabilityOfOneFails(double p)
{
var b = new Binomial(0.3, 1);
Assert.Throws<ArgumentOutOfRangeException>(() => b.P = p);
Assert.That(() => b.P = p, Throws.ArgumentException);
}
/// <summary>
@ -276,7 +271,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
[Test]
public void FailSampleStatic()
{
Assert.Throws<ArgumentOutOfRangeException>(() => Binomial.Sample(new Random(0), -1.0, 5));
Assert.That(() => Binomial.Sample(new Random(0), -1.0, 5), Throws.ArgumentException);
}
/// <summary>
@ -285,7 +280,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
[Test]
public void FailSampleSequenceStatic()
{
Assert.Throws<ArgumentOutOfRangeException>(() => Binomial.Samples(new Random(0), -1.0, 5).First());
Assert.That(() => Binomial.Samples(new Random(0), -1.0, 5).First(), Throws.ArgumentException);
}
/// <summary>

6
src/UnitTests/DistributionTests/Discrete/CategoricalTests.cs

@ -3,7 +3,9 @@
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com
// Copyright (c) 2009-2010 Math.NET
//
// Copyright (c) 2009-2014 Math.NET
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
@ -12,8 +14,10 @@
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND

21
src/UnitTests/DistributionTests/Discrete/ConwayMaxwellPoissonTests.cs

@ -3,7 +3,9 @@
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com
// Copyright (c) 2009-2010 Math.NET
//
// Copyright (c) 2009-2014 Math.NET
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
@ -12,8 +14,10 @@
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
@ -37,15 +41,6 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
[TestFixture, Category("Distributions")]
public class ConwayMaxwellPoissonTests
{
/// <summary>
/// Set-up test parameters.
/// </summary>
[SetUp]
public void SetUp()
{
Control.CheckDistributionParameters = true;
}
/// <summary>
/// Can create <c>ConwayMaxwellPoisson</c>.
/// </summary>
@ -69,7 +64,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
[Test]
public void ConwayMaxwellPoissonCreateFailsWithBadParameters()
{
Assert.Throws<ArgumentOutOfRangeException>(() => new ConwayMaxwellPoisson(-1.0, -2.0));
Assert.That(() => new ConwayMaxwellPoisson(-1.0, -2.0), Throws.ArgumentException);
}
/// <summary>
@ -125,7 +120,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
public void SetLambdaFails(double lambda)
{
var d = new ConwayMaxwellPoisson(1.0, 2.0);
Assert.Throws<ArgumentOutOfRangeException>(() => d.Lambda = lambda);
Assert.That(() => d.Lambda = lambda, Throws.ArgumentException);
}
/// <summary>
@ -139,7 +134,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
public void SetNuFails(double nu)
{
var d = new ConwayMaxwellPoisson(1.0, 2.0);
Assert.Throws<ArgumentOutOfRangeException>(() => d.Nu = nu);
Assert.That(() => d.Nu = nu, Throws.ArgumentException);
}
/// <summary>

25
src/UnitTests/DistributionTests/Discrete/DiscreteUniformTests.cs

@ -3,7 +3,9 @@
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com
// Copyright (c) 2009-2010 Math.NET
//
// Copyright (c) 2009-2014 Math.NET
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
@ -12,8 +14,10 @@
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
@ -37,15 +41,6 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
[TestFixture, Category("Distributions")]
public class DiscreteUniformTests
{
/// <summary>
/// Set-up tests parameters.
/// </summary>
[SetUp]
public void SetUp()
{
Control.CheckDistributionParameters = true;
}
/// <summary>
/// Can create discrete uniform.
/// </summary>
@ -71,7 +66,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
[TestCase(6, 5)]
public void DiscreteUniformCreateFailsWithBadParameters(int l, int u)
{
Assert.Throws<ArgumentOutOfRangeException>(() => new DiscreteUniform(l, u));
Assert.That(() => new DiscreteUniform(l, u), Throws.ArgumentException);
}
/// <summary>
@ -123,7 +118,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
public void SetLowerBoundFails(int p)
{
var b = new DiscreteUniform(0, 10);
Assert.Throws<ArgumentOutOfRangeException>(() => b.LowerBound = p);
Assert.That(() => b.LowerBound = p, Throws.ArgumentException);
}
/// <summary>
@ -135,7 +130,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
public void SetUpperBoundFails(int p)
{
var b = new DiscreteUniform(0, 10);
Assert.Throws<ArgumentOutOfRangeException>(() => b.UpperBound = p);
Assert.That(() => b.UpperBound = p, Throws.ArgumentException);
}
/// <summary>
@ -298,7 +293,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
[Test]
public void FailSampleStatic()
{
Assert.Throws<ArgumentOutOfRangeException>(() => DiscreteUniform.Sample(new Random(0), 20, 10));
Assert.That(() => DiscreteUniform.Sample(new Random(0), 20, 10), Throws.ArgumentException);
}
/// <summary>
@ -307,7 +302,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
[Test]
public void FailSampleSequenceStatic()
{
Assert.Throws<ArgumentOutOfRangeException>(() => DiscreteUniform.Samples(new Random(0), 20, 10).First());
Assert.That(() => DiscreteUniform.Samples(new Random(0), 20, 10).First(), Throws.ArgumentException);
}
/// <summary>

19
src/UnitTests/DistributionTests/Discrete/GeometricTests.cs

@ -3,7 +3,9 @@
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com
// Copyright (c) 2009-2010 Math.NET
//
// Copyright (c) 2009-2014 Math.NET
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
@ -12,8 +14,10 @@
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
@ -37,15 +41,6 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
[TestFixture, Category("Distributions")]
public class GeometricTests
{
/// <summary>
/// Set-up parameters.
/// </summary>
[SetUp]
public void SetUp()
{
Control.CheckDistributionParameters = true;
}
/// <summary>
/// Can create Geometric.
/// </summary>
@ -68,7 +63,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
[TestCase(2.0)]
public void GeometricCreateFailsWithBadParameters(double p)
{
Assert.Throws<ArgumentOutOfRangeException>(() => new Geometric(p));
Assert.That(() => new Geometric(p), Throws.ArgumentException);
}
/// <summary>
@ -106,7 +101,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
public void SetProbabilityOfOneFails(double p)
{
var d = new Geometric(0.3);
Assert.Throws<ArgumentOutOfRangeException>(() => d.P = p);
Assert.That(() => d.P = p, Throws.ArgumentException);
}
/// <summary>

23
src/UnitTests/DistributionTests/Discrete/HypergeometricTests.cs

@ -3,7 +3,9 @@
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com
// Copyright (c) 2009-2010 Math.NET
//
// Copyright (c) 2009-2014 Math.NET
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
@ -12,8 +14,10 @@
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
@ -37,15 +41,6 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
[TestFixture, Category("Distributions")]
public class HypergeometricTests
{
/// <summary>
/// Set-up parameters.
/// </summary>
[SetUp]
public void SetUp()
{
Control.CheckDistributionParameters = true;
}
/// <summary>
/// Can create Hypergeometric.
/// </summary>
@ -78,7 +73,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
[TestCase(0, 1, 1)]
public void HypergeometricCreateFailsWithBadParameters(int population, int success, int n)
{
Assert.Throws<ArgumentOutOfRangeException>(() => new Hypergeometric(population, success, n));
Assert.That(() => new Hypergeometric(population, success, n), Throws.ArgumentException);
}
/// <summary>
@ -115,7 +110,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
public void SetPopulationFails(int population)
{
var d = new Hypergeometric(10, 1, 1);
Assert.Throws<ArgumentOutOfRangeException>(() => d.Population = population);
Assert.That(() => d.Population = population, Throws.ArgumentException);
}
/// <summary>
@ -143,7 +138,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
public void SetSuccessFails(int success)
{
var d = new Hypergeometric(10, 1, 1);
Assert.Throws<ArgumentOutOfRangeException>(() => d.Success = success);
Assert.That(() => d.Success = success, Throws.ArgumentException);
}
/// <summary>
@ -171,7 +166,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
public void SetDrawsFails(int draws)
{
var d = new Hypergeometric(10, 1, 1);
Assert.Throws<ArgumentOutOfRangeException>(() => d.Draws = draws);
Assert.That(() => d.Draws = draws, Throws.ArgumentException);
}
/// <summary>

21
src/UnitTests/DistributionTests/Discrete/NegativeBinomialTests.cs

@ -3,7 +3,9 @@
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com
// Copyright (c) 2009-2010 Math.NET
//
// Copyright (c) 2009-2014 Math.NET
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
@ -12,8 +14,10 @@
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
@ -37,15 +41,6 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
[TestFixture, Category("Distributions")]
public class NegativeBinomialTests
{
/// <summary>
/// Set-up parameters.
/// </summary>
[SetUp]
public void SetUp()
{
Control.CheckDistributionParameters = true;
}
/// <summary>
/// Can create Negative Binomial.
/// </summary>
@ -76,7 +71,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
[TestCase(Double.NaN, Double.NaN)]
public void NegativeBinomialCreateFailsWithBadParameters(double r, double p)
{
Assert.Throws<ArgumentOutOfRangeException>(() => new NegativeBinomial(r, p));
Assert.That(() => new NegativeBinomial(r, p), Throws.ArgumentException);
}
/// <summary>
@ -114,7 +109,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
public void SetRFails(double r)
{
var d = new NegativeBinomial(1.0, 0.5);
Assert.Throws<ArgumentOutOfRangeException>(() => d.R = r);
Assert.That(() => d.R = r, Throws.ArgumentException);
}
/// <summary>
@ -142,7 +137,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
public void SetProbabilityOfOneFails(double p)
{
var d = new NegativeBinomial(1.0, 0.5);
Assert.Throws<ArgumentOutOfRangeException>(() => d.P = p);
Assert.That(() => d.P = p, Throws.ArgumentException);
}
/// <summary>

19
src/UnitTests/DistributionTests/Discrete/PoissonTests.cs

@ -3,7 +3,9 @@
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com
// Copyright (c) 2009-2010 Math.NET
//
// Copyright (c) 2009-2014 Math.NET
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
@ -12,8 +14,10 @@
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
@ -37,15 +41,6 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
[TestFixture, Category("Distributions")]
public class PoissonTests
{
/// <summary>
/// Set-up parameters.
/// </summary>
[SetUp]
public void SetUp()
{
Control.CheckDistributionParameters = true;
}
/// <summary>
/// Can create Poisson.
/// </summary>
@ -68,7 +63,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
[TestCase(0.0)]
public void PoissonCreateFailsWithBadParameters(double lambda)
{
Assert.Throws<ArgumentOutOfRangeException>(() => new Poisson(lambda));
Assert.That(() => new Poisson(lambda), Throws.ArgumentException);
}
/// <summary>
@ -106,7 +101,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
public void SetProbabilityOfOneFails(double lambda)
{
var d = new Poisson(0.3);
Assert.Throws<ArgumentOutOfRangeException>(() => d.Lambda = lambda);
Assert.That(() => d.Lambda = lambda, Throws.ArgumentException);
}
/// <summary>

21
src/UnitTests/DistributionTests/Discrete/ZipfTests.cs

@ -3,7 +3,9 @@
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com
// Copyright (c) 2009-2010 Math.NET
//
// Copyright (c) 2009-2014 Math.NET
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
@ -12,8 +14,10 @@
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
@ -37,15 +41,6 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
[TestFixture, Category("Distributions")]
public class ZipfTests
{
/// <summary>
/// Set-up parameters.
/// </summary>
[SetUp]
public void SetUp()
{
Control.CheckDistributionParameters = true;
}
/// <summary>
/// Can create zipf.
/// </summary>
@ -70,7 +65,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
[TestCase(0.0, 0)]
public void ZipfCreateFailsWithBadParameters(double s, int n)
{
Assert.Throws<ArgumentOutOfRangeException>(() => new Zipf(s, n));
Assert.That(() => new Zipf(s, n), Throws.ArgumentException);
}
/// <summary>
@ -108,7 +103,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
public void SetSFails(double s)
{
var d = new Zipf(1.0, 5);
Assert.Throws<ArgumentOutOfRangeException>(() => d.S = s);
Assert.That(() => d.S = s, Throws.ArgumentException);
}
/// <summary>
@ -135,7 +130,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
public void SetNFails(int n)
{
var d = new Zipf(1.0, 5);
Assert.Throws<ArgumentOutOfRangeException>(() => d.N = n);
Assert.That(() => d.N = n, Throws.ArgumentException);
}
/// <summary>

Loading…
Cancel
Save