From 77fa7053357944801f3abc87f451dfa19152c9a3 Mon Sep 17 00:00:00 2001 From: Christoph Ruegg Date: Sun, 28 Jul 2013 17:09:06 +0200 Subject: [PATCH] Distributions: ctor overloads that accept Random argument --- src/Numerics/Distributions/Continuous/Beta.cs | 16 +++++- .../Distributions/Continuous/Cauchy.cs | 30 ++++++----- src/Numerics/Distributions/Continuous/Chi.cs | 18 +++++-- .../Distributions/Continuous/ChiSquare.cs | 17 ++++-- .../Continuous/ContinuousUniform.cs | 19 +++++-- .../Distributions/Continuous/Erlang.cs | 23 +++++--- .../Distributions/Continuous/Exponential.cs | 18 +++++-- .../Continuous/FisherSnedecor.cs | 25 +++++---- .../Distributions/Continuous/Gamma.cs | 15 +++++- .../Distributions/Continuous/InverseGamma.cs | 23 +++++--- .../Distributions/Continuous/Laplace.cs | 31 ++++++----- .../Distributions/Continuous/LogNormal.cs | 24 ++++++--- .../Distributions/Continuous/Normal.cs | 29 ++++++++-- .../Distributions/Continuous/Pareto.cs | 28 ++++++---- .../Distributions/Continuous/Rayleigh.cs | 23 +++++--- .../Distributions/Continuous/Stable.cs | 33 +++++++----- .../Distributions/Continuous/StudentT.cs | 21 ++++++-- .../Distributions/Continuous/Weibull.cs | 15 +++++- .../Distributions/Discrete/Bernoulli.cs | 15 +++++- .../Distributions/Discrete/Binomial.cs | 17 +++++- .../Distributions/Discrete/Categorical.cs | 18 +++++-- .../Discrete/ConwayMaxwellPoisson.cs | 23 +++++--- .../Distributions/Discrete/DiscreteUniform.cs | 15 +++++- .../Distributions/Discrete/Geometric.cs | 15 +++++- .../Distributions/Discrete/Hypergeometric.cs | 16 +++++- .../Discrete/NegativeBinomial.cs | 17 ++++-- .../Distributions/Discrete/Poisson.cs | 16 ++++-- src/Numerics/Distributions/Discrete/Zipf.cs | 23 +++++--- .../Distributions/Multivariate/Dirichlet.cs | 53 +++++++++++++------ .../Multivariate/InverseWishart.cs | 28 +++++----- .../Multivariate/MatrixNormal.cs | 38 ++++++------- .../Distributions/Multivariate/Multinomial.cs | 23 +++++--- .../Distributions/Multivariate/NormalGamma.cs | 46 ++++++++-------- .../Distributions/Multivariate/Wishart.cs | 28 +++++----- src/Numerics/Numerics.csproj | 2 - src/Numerics/Statistics/MCMC/HybridMC.cs | 5 +- .../Statistics/MCMC/UnivariateHybridMC.cs | 3 +- .../IntegralTransformsTests/FourierTest.cs | 15 +++--- .../IntegralTransformsTests/HartleyTest.cs | 9 ++-- .../InverseTransformTest.cs | 43 +++++++-------- .../MatchingNaiveTransformTest.cs | 9 ++-- .../ParsevalTheoremTest.cs | 13 +++-- .../LinearInterpolationCase.cs | 5 +- .../Complex/MatrixLoader.cs | 30 +++-------- .../Complex/MatrixStructureTheory.cs | 4 +- .../Complex32/MatrixLoader.cs | 30 +++-------- .../Complex32/MatrixStructureTheory.cs | 4 +- .../LinearAlgebraTests/Double/MatrixLoader.cs | 30 +++-------- .../Double/MatrixStructureTheory.cs | 4 +- .../LinearAlgebraTests/Single/MatrixLoader.cs | 30 +++-------- .../Single/MatrixStructureTheory.cs | 4 +- .../MCMCTests/RejectionSamplerTests.cs | 27 ++-------- .../StatisticsTests/StatisticsTests.cs | 7 ++- 53 files changed, 634 insertions(+), 439 deletions(-) diff --git a/src/Numerics/Distributions/Continuous/Beta.cs b/src/Numerics/Distributions/Continuous/Beta.cs index bffd2db1..adb9e0cb 100644 --- a/src/Numerics/Distributions/Continuous/Beta.cs +++ b/src/Numerics/Distributions/Continuous/Beta.cs @@ -71,8 +71,21 @@ namespace MathNet.Numerics.Distributions /// If any of the Beta parameters are negative. public Beta(double a, double b) { + _random = new Random(); + SetParameters(a, b); + } + + /// + /// Initializes a new instance of the Beta class. + /// + /// The a shape parameter of the Beta distribution. + /// The b shape parameter of the Beta distribution. + /// The random number generator which is used to draw random samples. + /// If any of the Beta parameters are negative. + public Beta(double a, double b, Random randomSource) + { + _random = randomSource ?? new Random(); SetParameters(a, b); - RandomSource = new Random(); } /// @@ -143,7 +156,6 @@ namespace MathNet.Numerics.Distributions public Random RandomSource { get { return _random; } - set { if (value == null) diff --git a/src/Numerics/Distributions/Continuous/Cauchy.cs b/src/Numerics/Distributions/Continuous/Cauchy.cs index a8e206b4..a45d6041 100644 --- a/src/Numerics/Distributions/Continuous/Cauchy.cs +++ b/src/Numerics/Distributions/Continuous/Cauchy.cs @@ -54,27 +54,33 @@ namespace MathNet.Numerics.Distributions /// /// Initializes a new instance of the class with the location parameter set to 0 and the scale parameter set to 1 /// - public Cauchy() - : this(0, 1) + public Cauchy() : this(0, 1) { } /// /// Initializes a new instance of the class. /// - /// - /// The location parameter for the distribution. - /// - /// - /// The scale parameter for the distribution. - /// - /// - /// If is negative. - /// + /// The location parameter for the distribution. + /// The scale parameter for the distribution. + /// If is negative. public Cauchy(double location, double scale) { + _random = new Random(); + SetParameters(location, scale); + } + + /// + /// Initializes a new instance of the class. + /// + /// The location parameter for the distribution. + /// The scale parameter for the distribution. + /// The random number generator which is used to draw random samples. + /// If is negative. + public Cauchy(double location, double scale, Random randomSource) + { + _random = randomSource ?? new Random(); SetParameters(location, scale); - RandomSource = new Random(); } /// diff --git a/src/Numerics/Distributions/Continuous/Chi.cs b/src/Numerics/Distributions/Continuous/Chi.cs index 21b7ddd3..8d7550b6 100644 --- a/src/Numerics/Distributions/Continuous/Chi.cs +++ b/src/Numerics/Distributions/Continuous/Chi.cs @@ -57,13 +57,22 @@ namespace MathNet.Numerics.Distributions /// /// Initializes a new instance of the class. /// - /// - /// The degrees of freedom for the Chi distribution. - /// + /// The degrees of freedom for the Chi distribution. public Chi(double dof) { + _random = new Random(); + SetParameters(dof); + } + + /// + /// Initializes a new instance of the class. + /// + /// The degrees of freedom for the Chi distribution. + /// The random number generator which is used to draw random samples. + public Chi(double dof, Random randomSource) + { + _random = randomSource ?? new Random(); SetParameters(dof); - RandomSource = new Random(); } /// @@ -123,7 +132,6 @@ namespace MathNet.Numerics.Distributions public Random RandomSource { get { return _random; } - set { if (value == null) diff --git a/src/Numerics/Distributions/Continuous/ChiSquare.cs b/src/Numerics/Distributions/Continuous/ChiSquare.cs index 1c9a2d0a..4252708b 100644 --- a/src/Numerics/Distributions/Continuous/ChiSquare.cs +++ b/src/Numerics/Distributions/Continuous/ChiSquare.cs @@ -54,13 +54,22 @@ namespace MathNet.Numerics.Distributions /// /// Initializes a new instance of the class. /// - /// - /// The degrees of freedom for the ChiSquare distribution. - /// + /// The degrees of freedom for the ChiSquare distribution. public ChiSquare(double dof) { + _random = new Random(); + SetParameters(dof); + } + + /// + /// Initializes a new instance of the class. + /// + /// The degrees of freedom for the ChiSquare distribution. + /// The random number generator which is used to draw random samples. + public ChiSquare(double dof, Random randomSource) + { + _random = randomSource ?? new Random(); SetParameters(dof); - RandomSource = new Random(); } /// diff --git a/src/Numerics/Distributions/Continuous/ContinuousUniform.cs b/src/Numerics/Distributions/Continuous/ContinuousUniform.cs index b8314a5d..a6dec444 100644 --- a/src/Numerics/Distributions/Continuous/ContinuousUniform.cs +++ b/src/Numerics/Distributions/Continuous/ContinuousUniform.cs @@ -63,8 +63,7 @@ namespace MathNet.Numerics.Distributions /// /// Initializes a new instance of the ContinuousUniform class with lower bound 0 and upper bound 1. /// - public ContinuousUniform() - : this(0.0, 1.0) + public ContinuousUniform() : this(0.0, 1.0) { } @@ -76,8 +75,21 @@ namespace MathNet.Numerics.Distributions /// If the upper bound is smaller than the lower bound. public ContinuousUniform(double lower, double upper) { + _random = new Random(); + SetParameters(lower, upper); + } + + /// + /// Initializes a new instance of the ContinuousUniform class with given lower and upper bounds. + /// + /// Lower bound. + /// Upper bound; must be at least as large as lower. + /// The random number generator which is used to draw random samples. + /// If the upper bound is smaller than the lower bound. + public ContinuousUniform(double lower, double upper, Random randomSource) + { + _random = randomSource ?? new Random(); SetParameters(lower, upper); - RandomSource = new Random(); } /// @@ -155,7 +167,6 @@ namespace MathNet.Numerics.Distributions public Random RandomSource { get { return _random; } - set { if (value == null) diff --git a/src/Numerics/Distributions/Continuous/Erlang.cs b/src/Numerics/Distributions/Continuous/Erlang.cs index bfb220ae..188f9922 100644 --- a/src/Numerics/Distributions/Continuous/Erlang.cs +++ b/src/Numerics/Distributions/Continuous/Erlang.cs @@ -61,16 +61,24 @@ namespace MathNet.Numerics.Distributions /// /// Initializes a new instance of the class. /// - /// - /// The shape of the Erlang distribution. - /// - /// - /// The inverse scale of the Erlang distribution. - /// + /// The shape of the Erlang distribution. + /// The inverse scale of the Erlang distribution. public Erlang(int shape, double invScale) { + _random = new Random(); + SetParameters(shape, invScale); + } + + /// + /// Initializes a new instance of the class. + /// + /// The shape of the Erlang distribution. + /// The inverse scale of the Erlang distribution. + /// The random number generator which is used to draw random samples. + public Erlang(int shape, double invScale, Random randomSource) + { + _random = randomSource ?? new Random(); SetParameters(shape, invScale); - RandomSource = new Random(); } /// @@ -186,7 +194,6 @@ namespace MathNet.Numerics.Distributions public Random RandomSource { get { return _random; } - set { if (value == null) diff --git a/src/Numerics/Distributions/Continuous/Exponential.cs b/src/Numerics/Distributions/Continuous/Exponential.cs index 0e639c65..dd982fd0 100644 --- a/src/Numerics/Distributions/Continuous/Exponential.cs +++ b/src/Numerics/Distributions/Continuous/Exponential.cs @@ -54,13 +54,22 @@ namespace MathNet.Numerics.Distributions /// /// Initializes a new instance of the class. /// - /// - /// The lambda parameter of the Exponential distribution. - /// + /// The lambda parameter of the Exponential distribution. public Exponential(double lambda) { + _random = new Random(); + SetParameters(lambda); + } + + /// + /// Initializes a new instance of the class. + /// + /// The lambda parameter of the Exponential distribution. + /// The random number generator which is used to draw random samples. + public Exponential(double lambda, Random randomSource) + { + _random = randomSource ?? new Random(); SetParameters(lambda); - RandomSource = new Random(); } /// @@ -125,7 +134,6 @@ namespace MathNet.Numerics.Distributions public Random RandomSource { get { return _random; } - set { if (value == null) diff --git a/src/Numerics/Distributions/Continuous/FisherSnedecor.cs b/src/Numerics/Distributions/Continuous/FisherSnedecor.cs index 638889ba..93718b62 100644 --- a/src/Numerics/Distributions/Continuous/FisherSnedecor.cs +++ b/src/Numerics/Distributions/Continuous/FisherSnedecor.cs @@ -59,16 +59,24 @@ namespace MathNet.Numerics.Distributions /// /// Initializes a new instance of the class. /// - /// - /// The first parameter - degree of freedom. - /// - /// - /// The second parameter - degree of freedom. - /// + /// The first parameter - degree of freedom. + /// The second parameter - degree of freedom. public FisherSnedecor(double d1, double d2) { + _random = new Random(); + SetParameters(d1, d2); + } + + /// + /// Initializes a new instance of the class. + /// + /// The first parameter - degree of freedom. + /// The second parameter - degree of freedom. + /// The random number generator which is used to draw random samples. + public FisherSnedecor(double d1, double d2, Random randomSource) + { + _random = randomSource ?? new Random(); SetParameters(d1, d2); - RandomSource = new Random(); } /// @@ -145,12 +153,11 @@ namespace MathNet.Numerics.Distributions public Random RandomSource { get { return _random; } - set { if (value == null) { - throw new ArgumentNullException(Resources.InvalidDistributionParameters); + throw new ArgumentNullException(); } _random = value; diff --git a/src/Numerics/Distributions/Continuous/Gamma.cs b/src/Numerics/Distributions/Continuous/Gamma.cs index 755d4ffb..67e51e31 100644 --- a/src/Numerics/Distributions/Continuous/Gamma.cs +++ b/src/Numerics/Distributions/Continuous/Gamma.cs @@ -71,8 +71,20 @@ namespace MathNet.Numerics.Distributions /// The inverse scale of the Gamma distribution. public Gamma(double shape, double invScale) { + _random = new Random(); + SetParameters(shape, invScale); + } + + /// + /// Initializes a new instance of the Gamma class. + /// + /// The shape of the Gamma distribution. + /// The inverse scale of the Gamma distribution. + /// The random number generator which is used to draw random samples. + public Gamma(double shape, double invScale, Random randomSource) + { + _random = randomSource ?? new Random(); SetParameters(shape, invScale); - RandomSource = new Random(); } /// @@ -189,7 +201,6 @@ namespace MathNet.Numerics.Distributions public Random RandomSource { get { return _random; } - set { if (value == null) diff --git a/src/Numerics/Distributions/Continuous/InverseGamma.cs b/src/Numerics/Distributions/Continuous/InverseGamma.cs index 834b715f..651aa753 100644 --- a/src/Numerics/Distributions/Continuous/InverseGamma.cs +++ b/src/Numerics/Distributions/Continuous/InverseGamma.cs @@ -60,16 +60,24 @@ namespace MathNet.Numerics.Distributions /// /// Initializes a new instance of the class. /// - /// - /// The shape (alpha) parameter of the inverse Gamma distribution. - /// - /// - /// The scale (beta) parameter of the inverse Gamma distribution. - /// + /// The shape (alpha) parameter of the inverse Gamma distribution. + /// The scale (beta) parameter of the inverse Gamma distribution. public InverseGamma(double shape, double scale) { - SetParameters(shape, scale); _random = new Random(); + SetParameters(shape, scale); + } + + /// + /// Initializes a new instance of the class. + /// + /// The shape (alpha) parameter of the inverse Gamma distribution. + /// The scale (beta) parameter of the inverse Gamma distribution. + /// The random number generator which is used to draw random samples. + public InverseGamma(double shape, double scale, Random randomSource) + { + _random = randomSource ?? new Random(); + SetParameters(shape, scale); } /// @@ -155,7 +163,6 @@ namespace MathNet.Numerics.Distributions public Random RandomSource { get { return _random; } - set { if (value == null) diff --git a/src/Numerics/Distributions/Continuous/Laplace.cs b/src/Numerics/Distributions/Continuous/Laplace.cs index a9a41e13..d31972d6 100644 --- a/src/Numerics/Distributions/Continuous/Laplace.cs +++ b/src/Numerics/Distributions/Continuous/Laplace.cs @@ -76,27 +76,33 @@ namespace MathNet.Numerics.Distributions /// /// Initializes a new instance of the class (location = 0, scale = 1). /// - public Laplace() - : this(0.0, 1.0) + public Laplace() : this(0.0, 1.0) { } /// /// Initializes a new instance of the class. /// - /// - /// The location for the Laplace distribution. - /// - /// - /// The scale for the Laplace distribution. - /// - /// - /// If is negative. - /// + /// The location for the Laplace distribution. + /// The scale for the Laplace distribution. + /// If is negative. public Laplace(double location, double scale) { + _random = new Random(); + SetParameters(location, scale); + } + + /// + /// Initializes a new instance of the class. + /// + /// The location for the Laplace distribution. + /// The scale for the Laplace distribution. + /// The random number generator which is used to draw random samples. + /// If is negative. + public Laplace(double location, double scale, Random randomSource) + { + _random = randomSource ?? new Random(); SetParameters(location, scale); - RandomSource = new Random(); } /// @@ -154,7 +160,6 @@ namespace MathNet.Numerics.Distributions public Random RandomSource { get { return _random; } - set { if (value == null) diff --git a/src/Numerics/Distributions/Continuous/LogNormal.cs b/src/Numerics/Distributions/Continuous/LogNormal.cs index 2e4f2b7e..54267679 100644 --- a/src/Numerics/Distributions/Continuous/LogNormal.cs +++ b/src/Numerics/Distributions/Continuous/LogNormal.cs @@ -61,16 +61,26 @@ namespace MathNet.Numerics.Distributions /// The distribution will be initialized with the default /// random number generator. /// - /// - /// The mu of the logarithm of the distribution. - /// - /// - /// The standard deviation of the logarithm of the distribution. - /// + /// The mu of the logarithm of the distribution. + /// The standard deviation of the logarithm of the distribution. public LogNormal(double mu, double sigma) { + _random = new Random(); + SetParameters(mu, sigma); + } + + /// + /// Initializes a new instance of the class. + /// The distribution will be initialized with the default + /// random number generator. + /// + /// The mu of the logarithm of the distribution. + /// The standard deviation of the logarithm of the distribution. + /// The random number generator which is used to draw random samples. + public LogNormal(double mu, double sigma, Random randomSource) + { + _random = randomSource ?? new Random(); SetParameters(mu, sigma); - RandomSource = new Random(); } /// diff --git a/src/Numerics/Distributions/Continuous/Normal.cs b/src/Numerics/Distributions/Continuous/Normal.cs index 2658d4e4..362ba370 100644 --- a/src/Numerics/Distributions/Continuous/Normal.cs +++ b/src/Numerics/Distributions/Continuous/Normal.cs @@ -61,8 +61,17 @@ namespace MathNet.Numerics.Distributions /// and standard deviation 1.0. The distribution will /// be initialized with the default random number generator. /// - public Normal() - : this(0.0, 1.0) + public Normal() : this(0.0, 1.0) + { + } + + /// + /// Initializes a new instance of the Normal class. This is a normal distribution with mean 0.0 + /// and standard deviation 1.0. The distribution will + /// be initialized with the default random number generator. + /// + /// The random number generator which is used to draw random samples. + public Normal(Random randomSource) : this(0.0, 1.0, randomSource) { } @@ -74,8 +83,21 @@ namespace MathNet.Numerics.Distributions /// The standard deviation of the normal distribution. public Normal(double mean, double stddev) { + _random = new Random(); + SetParameters(mean, stddev); + } + + /// + /// Initializes a new instance of the Normal class with a particular mean and standard deviation. The distribution will + /// be initialized with the default random number generator. + /// + /// The mean of the normal distribution. + /// The standard deviation of the normal distribution. + /// The random number generator which is used to draw random samples. + public Normal(double mean, double stddev, Random randomSource) + { + _random = randomSource ?? new Random(); SetParameters(mean, stddev); - RandomSource = new Random(); } /// @@ -185,7 +207,6 @@ namespace MathNet.Numerics.Distributions public Random RandomSource { get { return _random; } - set { if (value == null) diff --git a/src/Numerics/Distributions/Continuous/Pareto.cs b/src/Numerics/Distributions/Continuous/Pareto.cs index 276a20a5..33fda60e 100644 --- a/src/Numerics/Distributions/Continuous/Pareto.cs +++ b/src/Numerics/Distributions/Continuous/Pareto.cs @@ -61,19 +61,26 @@ namespace MathNet.Numerics.Distributions /// /// Initializes a new instance of the class. /// - /// - /// The scale parameter of the distribution. - /// - /// - /// The shape parameter of the distribution. - /// - /// - /// If or are negative. - /// + /// The scale parameter of the distribution. + /// The shape parameter of the distribution. + /// If or are negative. public Pareto(double scale, double shape) { + _random = new Random(); + SetParameters(scale, shape); + } + + /// + /// Initializes a new instance of the class. + /// + /// The scale parameter of the distribution. + /// The shape parameter of the distribution. + /// The random number generator which is used to draw random samples. + /// If or are negative. + public Pareto(double scale, double shape, Random randomSource) + { + _random = randomSource ?? new Random(); SetParameters(scale, shape); - RandomSource = new Random(); } /// @@ -151,7 +158,6 @@ namespace MathNet.Numerics.Distributions public Random RandomSource { get { return _random; } - set { if (value == null) diff --git a/src/Numerics/Distributions/Continuous/Rayleigh.cs b/src/Numerics/Distributions/Continuous/Rayleigh.cs index b5fcfad6..68b296f2 100644 --- a/src/Numerics/Distributions/Continuous/Rayleigh.cs +++ b/src/Numerics/Distributions/Continuous/Rayleigh.cs @@ -57,16 +57,24 @@ namespace MathNet.Numerics.Distributions /// /// Initializes a new instance of the class. /// - /// - /// The scale parameter of the distribution. - /// - /// - /// If is negative. - /// + /// The scale parameter of the distribution. + /// If is negative. public Rayleigh(double scale) { + _random = new Random(); + SetParameters(scale); + } + + /// + /// Initializes a new instance of the class. + /// + /// The scale parameter of the distribution. + /// The random number generator which is used to draw random samples. + /// If is negative. + public Rayleigh(double scale, Random randomSource) + { + _random = randomSource ?? new Random(); SetParameters(scale); - RandomSource = new Random(); } /// @@ -131,7 +139,6 @@ namespace MathNet.Numerics.Distributions public Random RandomSource { get { return _random; } - set { if (value == null) diff --git a/src/Numerics/Distributions/Continuous/Stable.cs b/src/Numerics/Distributions/Continuous/Stable.cs index a2ea6771..e24491b7 100644 --- a/src/Numerics/Distributions/Continuous/Stable.cs +++ b/src/Numerics/Distributions/Continuous/Stable.cs @@ -72,22 +72,28 @@ namespace MathNet.Numerics.Distributions /// /// Initializes a new instance of the class. /// - /// - /// The stability parameter of the distribution. - /// - /// - /// The skewness parameter of the distribution. - /// - /// - /// The scale parameter of the distribution. - /// - /// - /// The location parameter of the distribution. - /// + /// The stability parameter of the distribution. + /// The skewness parameter of the distribution. + /// The scale parameter of the distribution. + /// The location parameter of the distribution. public Stable(double alpha, double beta, double scale, double location) { + _random = new Random(); + SetParameters(alpha, beta, scale, location); + } + + /// + /// Initializes a new instance of the class. + /// + /// The stability parameter of the distribution. + /// The skewness parameter of the distribution. + /// The scale parameter of the distribution. + /// The location parameter of the distribution. + /// The random number generator which is used to draw random samples. + public Stable(double alpha, double beta, double scale, double location, Random randomSource) + { + _random = randomSource ?? new Random(); SetParameters(alpha, beta, scale, location); - RandomSource = new Random(); } /// @@ -200,7 +206,6 @@ namespace MathNet.Numerics.Distributions public Random RandomSource { get { return _random; } - set { if (value == null) diff --git a/src/Numerics/Distributions/Continuous/StudentT.cs b/src/Numerics/Distributions/Continuous/StudentT.cs index 4512e1f3..1a2ef64b 100644 --- a/src/Numerics/Distributions/Continuous/StudentT.cs +++ b/src/Numerics/Distributions/Continuous/StudentT.cs @@ -77,8 +77,7 @@ namespace MathNet.Numerics.Distributions /// scale 1.0 and degrees of freedom 1. The distribution will /// be initialized with the default random number generator. /// - public StudentT() - : this(0.0, 1.0, 1.0) + public StudentT() : this(0.0, 1.0, 1.0) { } @@ -92,8 +91,23 @@ namespace MathNet.Numerics.Distributions /// The degrees of freedom for the Student t-distribution. public StudentT(double location, double scale, double dof) { + _random = new Random(); + SetParameters(location, scale, dof); + } + + /// + /// Initializes a new instance of the StudentT class with a particular location, scale and degrees of + /// freedom. The distribution will + /// be initialized with the default random number generator. + /// + /// The location of the Student t-distribution. + /// The scale of the Student t-distribution. + /// The degrees of freedom for the Student t-distribution. + /// The random number generator which is used to draw random samples. + public StudentT(double location, double scale, double dof, Random randomSource) + { + _random = randomSource ?? new Random(); SetParameters(location, scale, dof); - RandomSource = new Random(); } /// @@ -179,7 +193,6 @@ namespace MathNet.Numerics.Distributions public Random RandomSource { get { return _random; } - set { if (value == null) diff --git a/src/Numerics/Distributions/Continuous/Weibull.cs b/src/Numerics/Distributions/Continuous/Weibull.cs index c3ccd589..86b16e4d 100644 --- a/src/Numerics/Distributions/Continuous/Weibull.cs +++ b/src/Numerics/Distributions/Continuous/Weibull.cs @@ -78,8 +78,20 @@ namespace MathNet.Numerics.Distributions /// The inverse scale of the Weibull distribution. public Weibull(double shape, double scale) { + _random = new Random(); + SetParameters(shape, scale); + } + + /// + /// Initializes a new instance of the Weibull class. + /// + /// The shape of the Weibull distribution. + /// The inverse scale of the Weibull distribution. + /// The random number generator which is used to draw random samples. + public Weibull(double shape, double scale, Random randomSource) + { + _random = randomSource ?? new Random(); SetParameters(shape, scale); - RandomSource = new Random(); } /// @@ -153,7 +165,6 @@ namespace MathNet.Numerics.Distributions public Random RandomSource { get { return _random; } - set { if (value == null) diff --git a/src/Numerics/Distributions/Discrete/Bernoulli.cs b/src/Numerics/Distributions/Discrete/Bernoulli.cs index 941c9f80..112abad8 100644 --- a/src/Numerics/Distributions/Discrete/Bernoulli.cs +++ b/src/Numerics/Distributions/Discrete/Bernoulli.cs @@ -59,8 +59,20 @@ namespace MathNet.Numerics.Distributions /// If the Bernoulli parameter is not in the range [0,1]. public Bernoulli(double p) { + _random = new Random(); + SetParameters(p); + } + + /// + /// Initializes a new instance of the Bernoulli class. + /// + /// The probability of generating one. + /// The random number generator which is used to draw random samples. + /// If the Bernoulli parameter is not in the range [0,1]. + public Bernoulli(double p, Random randomSource) + { + _random = randomSource ?? new Random(); SetParameters(p); - RandomSource = new Random(); } /// @@ -120,7 +132,6 @@ namespace MathNet.Numerics.Distributions public Random RandomSource { get { return _random; } - set { if (value == null) diff --git a/src/Numerics/Distributions/Discrete/Binomial.cs b/src/Numerics/Distributions/Discrete/Binomial.cs index f37a5881..1d8bb3ae 100644 --- a/src/Numerics/Distributions/Discrete/Binomial.cs +++ b/src/Numerics/Distributions/Discrete/Binomial.cs @@ -66,8 +66,22 @@ namespace MathNet.Numerics.Distributions /// If is negative. public Binomial(double p, int n) { + _random = new Random(); + SetParameters(p, n); + } + + /// + /// Initializes a new instance of the Binomial class. + /// + /// The success probability of a trial. + /// The number of trials. + /// The random number generator which is used to draw random samples. + /// If is not in the interval [0.0,1.0]. + /// If is negative. + public Binomial(double p, int n, Random randomSource) + { + _random = randomSource ?? new Random(); SetParameters(p, n); - RandomSource = new Random(); } /// @@ -146,7 +160,6 @@ namespace MathNet.Numerics.Distributions public Random RandomSource { get { return _random; } - set { if (value == null) diff --git a/src/Numerics/Distributions/Discrete/Categorical.cs b/src/Numerics/Distributions/Discrete/Categorical.cs index f69f719e..33bb0370 100644 --- a/src/Numerics/Distributions/Discrete/Categorical.cs +++ b/src/Numerics/Distributions/Discrete/Categorical.cs @@ -63,8 +63,21 @@ namespace MathNet.Numerics.Distributions /// If any of the probabilities are negative or do not sum to one. public Categorical(double[] probabilityMass) { + _random = new Random(); + SetParameters(probabilityMass); + } + + /// + /// Initializes a new instance of the Categorical class. + /// + /// An array of nonnegative ratios: this array does not need to be normalized + /// as this is often impossible using floating point arithmetic. + /// The random number generator which is used to draw random samples. + /// If any of the probabilities are negative or do not sum to one. + public Categorical(double[] probabilityMass, Random randomSource) + { + _random = randomSource ?? new Random(); SetParameters(probabilityMass); - RandomSource = new Random(); } /// @@ -89,8 +102,8 @@ namespace MathNet.Numerics.Distributions p[i] = histogram[i].Count; } + _random = new Random(); SetParameters(p); - RandomSource = new Random(); } /// @@ -196,7 +209,6 @@ namespace MathNet.Numerics.Distributions public Random RandomSource { get { return _random; } - set { if (value == null) diff --git a/src/Numerics/Distributions/Discrete/ConwayMaxwellPoisson.cs b/src/Numerics/Distributions/Discrete/ConwayMaxwellPoisson.cs index 9dcdf47f..122d6cfe 100644 --- a/src/Numerics/Distributions/Discrete/ConwayMaxwellPoisson.cs +++ b/src/Numerics/Distributions/Discrete/ConwayMaxwellPoisson.cs @@ -87,16 +87,24 @@ namespace MathNet.Numerics.Distributions /// /// Initializes a new instance of the class. /// - /// - /// The lambda parameter. - /// - /// - /// The nu parameter. - /// + /// The lambda parameter. + /// The nu parameter. public ConwayMaxwellPoisson(double lambda, double nu) { + _random = new Random(); + SetParameters(lambda, nu); + } + + /// + /// Initializes a new instance of the class. + /// + /// The lambda parameter. + /// The nu parameter. + /// The random number generator which is used to draw random samples. + public ConwayMaxwellPoisson(double lambda, double nu, Random randomSource) + { + _random = randomSource ?? new Random(); SetParameters(lambda, nu); - RandomSource = new Random(); } /// @@ -178,7 +186,6 @@ namespace MathNet.Numerics.Distributions public Random RandomSource { get { return _random; } - set { if (value == null) diff --git a/src/Numerics/Distributions/Discrete/DiscreteUniform.cs b/src/Numerics/Distributions/Discrete/DiscreteUniform.cs index c4d20347..09dc0ba9 100644 --- a/src/Numerics/Distributions/Discrete/DiscreteUniform.cs +++ b/src/Numerics/Distributions/Discrete/DiscreteUniform.cs @@ -64,8 +64,20 @@ namespace MathNet.Numerics.Distributions /// Upper bound; must be at least as large as . public DiscreteUniform(int lower, int upper) { + _random = new Random(); + SetParameters(lower, upper); + } + + /// + /// Initializes a new instance of the DiscreteUniform class. + /// + /// Lower bound. + /// Upper bound; must be at least as large as . + /// The random number generator which is used to draw random samples. + public DiscreteUniform(int lower, int upper, Random randomSource) + { + _random = randomSource ?? new Random(); SetParameters(lower, upper); - RandomSource = new Random(); } /// @@ -140,7 +152,6 @@ namespace MathNet.Numerics.Distributions public Random RandomSource { get { return _random; } - set { if (value == null) diff --git a/src/Numerics/Distributions/Discrete/Geometric.cs b/src/Numerics/Distributions/Discrete/Geometric.cs index a0f01b5a..b5b142c8 100644 --- a/src/Numerics/Distributions/Discrete/Geometric.cs +++ b/src/Numerics/Distributions/Discrete/Geometric.cs @@ -59,8 +59,20 @@ namespace MathNet.Numerics.Distributions /// If the Geometric parameter is not in the range [0,1]. public Geometric(double p) { + _random = new Random(); + SetParameters(p); + } + + /// + /// Initializes a new instance of the Geometric class. + /// + /// The probability of generating one. + /// The random number generator which is used to draw random samples. + /// If the Geometric parameter is not in the range [0,1]. + public Geometric(double p, Random randomSource) + { + _random = randomSource ?? new Random(); SetParameters(p); - RandomSource = new Random(); } /// @@ -122,7 +134,6 @@ namespace MathNet.Numerics.Distributions public Random RandomSource { get { return _random; } - set { if (value == null) diff --git a/src/Numerics/Distributions/Discrete/Hypergeometric.cs b/src/Numerics/Distributions/Discrete/Hypergeometric.cs index 4901135b..f5d0f679 100644 --- a/src/Numerics/Distributions/Discrete/Hypergeometric.cs +++ b/src/Numerics/Distributions/Discrete/Hypergeometric.cs @@ -77,8 +77,21 @@ namespace MathNet.Numerics.Distributions /// The n parameter of the distribution. public Hypergeometric(int populationSize, int m, int n) { + _random = new Random(); + SetParameters(populationSize, m, n); + } + + /// + /// Initializes a new instance of the Hypergeometric class. + /// + /// The population size. + /// The m parameter of the distribution. + /// The n parameter of the distribution. + /// The random number generator which is used to draw random samples. + public Hypergeometric(int populationSize, int m, int n, Random randomSource) + { + _random = randomSource ?? new Random(); SetParameters(populationSize, m, n); - RandomSource = new Random(); } /// @@ -167,7 +180,6 @@ namespace MathNet.Numerics.Distributions public Random RandomSource { get { return _random; } - set { if (value == null) diff --git a/src/Numerics/Distributions/Discrete/NegativeBinomial.cs b/src/Numerics/Distributions/Discrete/NegativeBinomial.cs index c619a974..8de4d9f5 100644 --- a/src/Numerics/Distributions/Discrete/NegativeBinomial.cs +++ b/src/Numerics/Distributions/Discrete/NegativeBinomial.cs @@ -64,7 +64,6 @@ namespace MathNet.Numerics.Distributions public double R { get { return _r; } - set { SetParameters(value, _p); } } @@ -74,7 +73,6 @@ namespace MathNet.Numerics.Distributions public double P { get { return _p; } - set { SetParameters(_r, value); } } @@ -85,8 +83,20 @@ namespace MathNet.Numerics.Distributions /// The probability of a trial resulting in success. public NegativeBinomial(double r, double p) { + _random = new Random(); + SetParameters(r, p); + } + + /// + /// Initializes a new instance of the class. + /// + /// The number of trials. + /// The probability of a trial resulting in success. + /// The random number generator which is used to draw random samples. + public NegativeBinomial(double r, double p, Random randomSource) + { + _random = randomSource ?? new Random(); SetParameters(r, p); - RandomSource = new Random(); } /// @@ -146,7 +156,6 @@ namespace MathNet.Numerics.Distributions public Random RandomSource { get { return _random; } - set { if (value == null) diff --git a/src/Numerics/Distributions/Discrete/Poisson.cs b/src/Numerics/Distributions/Discrete/Poisson.cs index 39b3d432..08669df2 100644 --- a/src/Numerics/Distributions/Discrete/Poisson.cs +++ b/src/Numerics/Distributions/Discrete/Poisson.cs @@ -56,7 +56,6 @@ namespace MathNet.Numerics.Distributions public double Lambda { get { return _lambda; } - set { SetParameters(value); } } @@ -67,8 +66,20 @@ namespace MathNet.Numerics.Distributions /// If is equal or less then 0.0. public Poisson(double lambda) { + _random = new Random(); + SetParameters(lambda); + } + + /// + /// Initializes a new instance of the class. + /// + /// The Poisson distribution parameter λ. + /// The random number generator which is used to draw random samples. + /// If is equal or less then 0.0. + public Poisson(double lambda, Random randomSource) + { + _random = randomSource ?? new Random(); SetParameters(lambda); - RandomSource = new Random(); } /// @@ -115,7 +126,6 @@ namespace MathNet.Numerics.Distributions public Random RandomSource { get { return _random; } - set { if (value == null) diff --git a/src/Numerics/Distributions/Discrete/Zipf.cs b/src/Numerics/Distributions/Discrete/Zipf.cs index 8bd0bc88..fc923684 100644 --- a/src/Numerics/Distributions/Discrete/Zipf.cs +++ b/src/Numerics/Distributions/Discrete/Zipf.cs @@ -62,16 +62,24 @@ namespace MathNet.Numerics.Distributions /// /// Initializes a new instance of the class. /// - /// - /// The s parameter of the distribution. - /// - /// - /// The n parameter of the distribution. - /// + /// The s parameter of the distribution. + /// The n parameter of the distribution. public Zipf(double s, int n) { + _random = new Random(); + SetParameters(s, n); + } + + /// + /// Initializes a new instance of the class. + /// + /// The s parameter of the distribution. + /// The n parameter of the distribution. + /// The random number generator which is used to draw random samples. + public Zipf(double s, int n, Random randomSource) + { + _random = randomSource ?? new Random(); SetParameters(s, n); - RandomSource = new Random(); } /// @@ -143,7 +151,6 @@ namespace MathNet.Numerics.Distributions public Random RandomSource { get { return _random; } - set { if (value == null) diff --git a/src/Numerics/Distributions/Multivariate/Dirichlet.cs b/src/Numerics/Distributions/Multivariate/Dirichlet.cs index 93545201..f9f05849 100644 --- a/src/Numerics/Distributions/Multivariate/Dirichlet.cs +++ b/src/Numerics/Distributions/Multivariate/Dirichlet.cs @@ -62,21 +62,27 @@ namespace MathNet.Numerics.Distributions /// An array with the Dirichlet parameters. public Dirichlet(double[] alpha) { + _random = new Random(); SetParameters(alpha); - RandomSource = new Random(); } /// - /// Initializes a new instance of the class. - /// - /// random number generator. + /// Initializes a new instance of the Dirichlet class. The distribution will + /// be initialized with the default random number generator. /// - /// - /// The value of each parameter of the Dirichlet distribution. - /// - /// - /// The dimension of the Dirichlet distribution. - /// + /// An array with the Dirichlet parameters. + /// The random number generator which is used to draw random samples. + public Dirichlet(double[] alpha, Random randomSource) + { + _random = randomSource ?? new Random(); + SetParameters(alpha); + } + + /// + /// Initializes a new instance of the class. + /// random number generator. + /// The value of each parameter of the Dirichlet distribution. + /// The dimension of the Dirichlet distribution. public Dirichlet(double alpha, int k) { // Create a parameter structure. @@ -86,8 +92,27 @@ namespace MathNet.Numerics.Distributions parm[i] = alpha; } + _random = new Random(); + SetParameters(parm); + } + + /// + /// Initializes a new instance of the class. + /// random number generator. + /// The value of each parameter of the Dirichlet distribution. + /// The dimension of the Dirichlet distribution. + /// The random number generator which is used to draw random samples. + public Dirichlet(double alpha, int k, Random randomSource) + { + // Create a parameter structure. + var parm = new double[k]; + for (var i = 0; i < k; i++) + { + parm[i] = alpha; + } + + _random = randomSource ?? new Random(); SetParameters(parm); - RandomSource = new Random(); } /// @@ -301,11 +326,7 @@ namespace MathNet.Numerics.Distributions /// public Random RandomSource { - get - { - return _random; - } - + get { return _random; } set { if (value == null) diff --git a/src/Numerics/Distributions/Multivariate/InverseWishart.cs b/src/Numerics/Distributions/Multivariate/InverseWishart.cs index 4266af55..86d16785 100644 --- a/src/Numerics/Distributions/Multivariate/InverseWishart.cs +++ b/src/Numerics/Distributions/Multivariate/InverseWishart.cs @@ -67,16 +67,24 @@ namespace MathNet.Numerics.Distributions /// /// Initializes a new instance of the class. /// - /// - /// The degrees of freedom for the inverse Wishart distribution. - /// - /// - /// The scale matrix for the inverse Wishart distribution. - /// + /// The degrees of freedom for the inverse Wishart distribution. + /// The scale matrix for the inverse Wishart distribution. public InverseWishart(double nu, Matrix s) { + _random = new Random(); + SetParameters(nu, s); + } + + /// + /// Initializes a new instance of the class. + /// + /// The degrees of freedom for the inverse Wishart distribution. + /// The scale matrix for the inverse Wishart distribution. + /// The random number generator which is used to draw random samples. + public InverseWishart(double nu, Matrix s, Random randomSource) + { + _random = randomSource ?? new Random(); SetParameters(nu, s); - RandomSource = new Random(); } /// @@ -172,11 +180,7 @@ namespace MathNet.Numerics.Distributions /// public Random RandomSource { - get - { - return _random; - } - + get { return _random; } set { if (value == null) diff --git a/src/Numerics/Distributions/Multivariate/MatrixNormal.cs b/src/Numerics/Distributions/Multivariate/MatrixNormal.cs index d963440a..c152c7a4 100644 --- a/src/Numerics/Distributions/Multivariate/MatrixNormal.cs +++ b/src/Numerics/Distributions/Multivariate/MatrixNormal.cs @@ -68,22 +68,28 @@ namespace MathNet.Numerics.Distributions /// /// Initializes a new instance of the class. /// - /// - /// The mean of the matrix normal. - /// - /// - /// The covariance matrix for the rows. - /// - /// - /// The covariance matrix for the columns. - /// - /// - /// If the dimensions of the mean and two covariance matrices don't match. - /// + /// The mean of the matrix normal. + /// The covariance matrix for the rows. + /// The covariance matrix for the columns. + /// If the dimensions of the mean and two covariance matrices don't match. public MatrixNormal(Matrix m, Matrix v, Matrix k) { + _random = new Random(); + SetParameters(m, v, k); + } + + /// + /// Initializes a new instance of the class. + /// + /// The mean of the matrix normal. + /// The covariance matrix for the rows. + /// The covariance matrix for the columns. + /// The random number generator which is used to draw random samples. + /// If the dimensions of the mean and two covariance matrices don't match. + public MatrixNormal(Matrix m, Matrix v, Matrix k, Random randomSource) + { + _random = randomSource ?? new Random(); SetParameters(m, v, k); - RandomSource = new Random(); } /// @@ -212,11 +218,7 @@ namespace MathNet.Numerics.Distributions /// public Random RandomSource { - get - { - return _random; - } - + get { return _random; } set { if (value == null) diff --git a/src/Numerics/Distributions/Multivariate/Multinomial.cs b/src/Numerics/Distributions/Multivariate/Multinomial.cs index 43d89f24..8db431c6 100644 --- a/src/Numerics/Distributions/Multivariate/Multinomial.cs +++ b/src/Numerics/Distributions/Multivariate/Multinomial.cs @@ -73,8 +73,23 @@ namespace MathNet.Numerics.Distributions /// If is negative. public Multinomial(double[] p, int n) { + _random = new Random(); + SetParameters(p, n); + } + + /// + /// Initializes a new instance of the Multinomial class. + /// + /// An array of nonnegative ratios: this array does not need to be normalized + /// as this is often impossible using floating point arithmetic. + /// The number of trials. + /// The random number generator which is used to draw random samples. + /// If any of the probabilities are negative or do not sum to one. + /// If is negative. + public Multinomial(double[] p, int n, Random randomSource) + { + _random = randomSource ?? new Random(); SetParameters(p, n); - RandomSource = new Random(); } /// @@ -198,11 +213,7 @@ namespace MathNet.Numerics.Distributions /// public Random RandomSource { - get - { - return _random; - } - + get { return _random; } set { if (value == null) diff --git a/src/Numerics/Distributions/Multivariate/NormalGamma.cs b/src/Numerics/Distributions/Multivariate/NormalGamma.cs index e058d755..61121993 100644 --- a/src/Numerics/Distributions/Multivariate/NormalGamma.cs +++ b/src/Numerics/Distributions/Multivariate/NormalGamma.cs @@ -49,12 +49,8 @@ namespace MathNet.Numerics.Distributions /// /// Initializes a new instance of the struct. /// - /// - /// The mean of the pair. - /// - /// - /// The precision of the pair. - /// + /// The mean of the pair. + /// The precision of the pair. public MeanPrecisionPair(double m, double p) { _mean = m; @@ -141,22 +137,28 @@ namespace MathNet.Numerics.Distributions /// /// Initializes a new instance of the class. /// - /// - /// The location of the mean. - /// - /// - /// The scale of the mean. - /// - /// - /// The shape of the precision. - /// - /// - /// The inverse scale of the precision. - /// + /// The location of the mean. + /// The scale of the mean. + /// The shape of the precision. + /// The inverse scale of the precision. public NormalGamma(double meanLocation, double meanScale, double precisionShape, double precisionInverseScale) { - SetParameters(meanLocation, meanScale, precisionShape, precisionInverseScale); _random = new Random(); + SetParameters(meanLocation, meanScale, precisionShape, precisionInverseScale); + } + + /// + /// Initializes a new instance of the class. + /// + /// The location of the mean. + /// The scale of the mean. + /// The shape of the precision. + /// The inverse scale of the precision. + /// The random number generator which is used to draw random samples. + public NormalGamma(double meanLocation, double meanScale, double precisionShape, double precisionInverseScale, Random randomSource) + { + _random = randomSource ?? new Random(); + SetParameters(meanLocation, meanScale, precisionShape, precisionInverseScale); } /// @@ -279,11 +281,7 @@ namespace MathNet.Numerics.Distributions /// public Random RandomSource { - get - { - return _random; - } - + get { return _random; } set { if (value == null) diff --git a/src/Numerics/Distributions/Multivariate/Wishart.cs b/src/Numerics/Distributions/Multivariate/Wishart.cs index 17822975..5d6b553c 100644 --- a/src/Numerics/Distributions/Multivariate/Wishart.cs +++ b/src/Numerics/Distributions/Multivariate/Wishart.cs @@ -69,16 +69,24 @@ namespace MathNet.Numerics.Distributions /// /// Initializes a new instance of the class. /// - /// - /// The degrees of freedom for the Wishart distribution. - /// - /// - /// The scale matrix for the Wishart distribution. - /// + /// The degrees of freedom for the Wishart distribution. + /// The scale matrix for the Wishart distribution. public Wishart(double nu, Matrix s) { + _random = new Random(); + SetParameters(nu, s); + } + + /// + /// Initializes a new instance of the class. + /// + /// The degrees of freedom for the Wishart distribution. + /// The scale matrix for the Wishart distribution. + /// The random number generator which is used to draw random samples. + public Wishart(double nu, Matrix s, Random randomSource) + { + _random = randomSource ?? new Random(); SetParameters(nu, s); - RandomSource = new Random(); } /// @@ -174,11 +182,7 @@ namespace MathNet.Numerics.Distributions /// public Random RandomSource { - get - { - return _random; - } - + get { return _random; } set { if (value == null) diff --git a/src/Numerics/Numerics.csproj b/src/Numerics/Numerics.csproj index 38373921..4ec6f17a 100644 --- a/src/Numerics/Numerics.csproj +++ b/src/Numerics/Numerics.csproj @@ -384,8 +384,6 @@ - - diff --git a/src/Numerics/Statistics/MCMC/HybridMC.cs b/src/Numerics/Statistics/MCMC/HybridMC.cs index 1c25500b..7fdd0bbb 100644 --- a/src/Numerics/Statistics/MCMC/HybridMC.cs +++ b/src/Numerics/Statistics/MCMC/HybridMC.cs @@ -184,10 +184,7 @@ namespace MathNet.Numerics.Statistics.Mcmc private void Initialize(double[] x0) { Current = (double[])x0.Clone(); - _pDistribution = new Normal(0, 1) - { - RandomSource = RandomSource - }; + _pDistribution = new Normal(0.0, 1.0, RandomSource); } /// diff --git a/src/Numerics/Statistics/MCMC/UnivariateHybridMC.cs b/src/Numerics/Statistics/MCMC/UnivariateHybridMC.cs index deb5a834..ab43e84a 100644 --- a/src/Numerics/Statistics/MCMC/UnivariateHybridMC.cs +++ b/src/Numerics/Statistics/MCMC/UnivariateHybridMC.cs @@ -162,9 +162,8 @@ namespace MathNet.Numerics.Statistics.Mcmc : base(x0, pdfLnP, frogLeapSteps, stepSize, burnInterval, randomSource, diff) { MomentumStdDev = pSdv; - _distribution = new Normal(0, MomentumStdDev) {RandomSource = RandomSource}; + _distribution = new Normal(0.0, MomentumStdDev, RandomSource); Burn(BurnInterval); - } /// diff --git a/src/UnitTests/IntegralTransformsTests/FourierTest.cs b/src/UnitTests/IntegralTransformsTests/FourierTest.cs index afbc6d8a..102f210d 100644 --- a/src/UnitTests/IntegralTransformsTests/FourierTest.cs +++ b/src/UnitTests/IntegralTransformsTests/FourierTest.cs @@ -43,12 +43,9 @@ namespace MathNet.Numerics.UnitTests.IntegralTransformsTests /// /// Continuous uniform distribution. /// - private IContinuousDistribution GetUniform(int seed) + IContinuousDistribution GetUniform(int seed) { - return new ContinuousUniform(-1, 1) - { - RandomSource = new Random(seed) - }; + return new ContinuousUniform(-1, 1, new Random(seed)); } /// @@ -98,18 +95,18 @@ namespace MathNet.Numerics.UnitTests.IntegralTransformsTests var dft = new DiscreteFourierTransform(); Assert.Throws( - typeof(ArgumentException), + typeof (ArgumentException), () => dft.Radix2Forward(samples, FourierOptions.Default)); Assert.Throws( - typeof(ArgumentException), + typeof (ArgumentException), () => dft.Radix2Inverse(samples, FourierOptions.Default)); Assert.Throws( - typeof(ArgumentException), + typeof (ArgumentException), () => DiscreteFourierTransform.Radix2(samples, -1)); Assert.Throws( - typeof(ArgumentException), + typeof (ArgumentException), () => DiscreteFourierTransform.Radix2Parallel(samples, -1)); } } diff --git a/src/UnitTests/IntegralTransformsTests/HartleyTest.cs b/src/UnitTests/IntegralTransformsTests/HartleyTest.cs index b21dfe45..be0ec043 100644 --- a/src/UnitTests/IntegralTransformsTests/HartleyTest.cs +++ b/src/UnitTests/IntegralTransformsTests/HartleyTest.cs @@ -43,12 +43,9 @@ namespace MathNet.Numerics.UnitTests.IntegralTransformsTests /// /// Continuous uniform distribution. /// - private IContinuousDistribution GetUniform(int seed) + IContinuousDistribution GetUniform(int seed) { - return new ContinuousUniform(-1, 1) - { - RandomSource = new Random(seed) - }; + return new ContinuousUniform(-1, 1, new Random(seed)); } /// @@ -59,7 +56,7 @@ namespace MathNet.Numerics.UnitTests.IntegralTransformsTests /// Is inverse. /// DFT function delegate. /// Hartley transform delegate. - private static void VerifyMatchesDft( + static void VerifyMatchesDft( double[] samples, double maximumError, bool inverse, diff --git a/src/UnitTests/IntegralTransformsTests/InverseTransformTest.cs b/src/UnitTests/IntegralTransformsTests/InverseTransformTest.cs index 0f9f23dc..ca0fb6f8 100644 --- a/src/UnitTests/IntegralTransformsTests/InverseTransformTest.cs +++ b/src/UnitTests/IntegralTransformsTests/InverseTransformTest.cs @@ -43,12 +43,9 @@ namespace MathNet.Numerics.UnitTests.IntegralTransformsTests /// /// Continuous uniform distribution. /// - private IContinuousDistribution GetUniform(int seed) + IContinuousDistribution GetUniform(int seed) { - return new ContinuousUniform(-1, 1) - { - RandomSource = new Random(seed) - }; + return new ContinuousUniform(-1, 1, new Random(seed)); } /// @@ -58,7 +55,7 @@ namespace MathNet.Numerics.UnitTests.IntegralTransformsTests /// Maximum error value. /// Forward delegate. /// Inverse delegate. - private void VerifyIsReversibleComplex( + void VerifyIsReversibleComplex( int count, double maximumError, Func forward, @@ -84,7 +81,7 @@ namespace MathNet.Numerics.UnitTests.IntegralTransformsTests /// Maximum error value. /// Forward delegate. /// Inverse delegate. - private void VerifyIsReversibleReal( + void VerifyIsReversibleReal( int count, double maximumError, Func forward, @@ -134,15 +131,15 @@ namespace MathNet.Numerics.UnitTests.IntegralTransformsTests 0x8000, 1e-12, s => - { - dft.Radix2Forward(s, options); - return s; - }, + { + dft.Radix2Forward(s, options); + return s; + }, s => - { - dft.Radix2Inverse(s, options); - return s; - }); + { + dft.Radix2Inverse(s, options); + return s; + }); } /// @@ -159,15 +156,15 @@ namespace MathNet.Numerics.UnitTests.IntegralTransformsTests 0x7FFF, 1e-12, s => - { - dft.BluesteinForward(s, options); - return s; - }, + { + dft.BluesteinForward(s, options); + return s; + }, s => - { - dft.BluesteinInverse(s, options); - return s; - }); + { + dft.BluesteinInverse(s, options); + return s; + }); } /// diff --git a/src/UnitTests/IntegralTransformsTests/MatchingNaiveTransformTest.cs b/src/UnitTests/IntegralTransformsTests/MatchingNaiveTransformTest.cs index 6f3aac6c..f4a8af5d 100644 --- a/src/UnitTests/IntegralTransformsTests/MatchingNaiveTransformTest.cs +++ b/src/UnitTests/IntegralTransformsTests/MatchingNaiveTransformTest.cs @@ -43,12 +43,9 @@ namespace MathNet.Numerics.UnitTests.IntegralTransformsTests /// /// Continuous uniform distribution. /// - private IContinuousDistribution GetUniform(int seed) + IContinuousDistribution GetUniform(int seed) { - return new ContinuousUniform(-1, 1) - { - RandomSource = new Random(seed) - }; + return new ContinuousUniform(-1, 1, new Random(seed)); } /// @@ -58,7 +55,7 @@ namespace MathNet.Numerics.UnitTests.IntegralTransformsTests /// Maximum error. /// Naive transform. /// Fast delegate. - private static void VerifyMatchesNaiveComplex( + static void VerifyMatchesNaiveComplex( Complex[] samples, double maximumError, Func naive, diff --git a/src/UnitTests/IntegralTransformsTests/ParsevalTheoremTest.cs b/src/UnitTests/IntegralTransformsTests/ParsevalTheoremTest.cs index 719eff93..2447aa58 100644 --- a/src/UnitTests/IntegralTransformsTests/ParsevalTheoremTest.cs +++ b/src/UnitTests/IntegralTransformsTests/ParsevalTheoremTest.cs @@ -26,6 +26,7 @@ namespace MathNet.Numerics.UnitTests.IntegralTransformsTests { + using System; using System.Linq; using System.Numerics; using Distributions; @@ -44,12 +45,9 @@ namespace MathNet.Numerics.UnitTests.IntegralTransformsTests /// /// Continuous uniform distribution. /// - private IContinuousDistribution GetUniform(int seed) + IContinuousDistribution GetUniform(int seed) { - return new ContinuousUniform(-1, 1) - { - RandomSource = new System.Random(seed) - }; + return new ContinuousUniform(-1, 1, new Random(seed)); } /// @@ -85,7 +83,7 @@ namespace MathNet.Numerics.UnitTests.IntegralTransformsTests { var samples = SignalGenerator.Random(x => x, GetUniform(1), count); - var timeSpaceEnergy = (from s in samples select s * s).Mean(); + var timeSpaceEnergy = (from s in samples select s*s).Mean(); var work = new double[samples.Length]; samples.CopyTo(work, 0); @@ -94,8 +92,9 @@ namespace MathNet.Numerics.UnitTests.IntegralTransformsTests var dht = new DiscreteHartleyTransform(); work = dht.NaiveForward(work, HartleyOptions.Default); - var frequencySpaceEnergy = (from s in work select s * s).Mean(); + var frequencySpaceEnergy = (from s in work select s*s).Mean(); Assert.AreEqual(timeSpaceEnergy, frequencySpaceEnergy, 1e-12); } } } + diff --git a/src/UnitTests/InterpolationTests/LinearInterpolationCase.cs b/src/UnitTests/InterpolationTests/LinearInterpolationCase.cs index 568be8b1..a3d19295 100644 --- a/src/UnitTests/InterpolationTests/LinearInterpolationCase.cs +++ b/src/UnitTests/InterpolationTests/LinearInterpolationCase.cs @@ -52,10 +52,7 @@ namespace MathNet.Numerics.UnitTests.InterpolationTests public static void Build(out double[] x, out double[] y, out double[] xtest, out double[] ytest, int samples = 3, double sampleOffset = -0.5, double slope = 2.0, double intercept = -1.0) { // Fixed-seed "random" distribution to ensure we always test with the same data - var uniform = new ContinuousUniform - { - RandomSource = new MersenneTwister(42) - }; + var uniform = new ContinuousUniform(0.0, 1.0, new MersenneTwister(42)); // build linear samples x = new double[samples]; diff --git a/src/UnitTests/LinearAlgebraTests/Complex/MatrixLoader.cs b/src/UnitTests/LinearAlgebraTests/Complex/MatrixLoader.cs index 5ba28190..ebf817db 100644 --- a/src/UnitTests/LinearAlgebraTests/Complex/MatrixLoader.cs +++ b/src/UnitTests/LinearAlgebraTests/Complex/MatrixLoader.cs @@ -116,10 +116,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex public static Matrix GenerateRandomDenseMatrix(int row, int col) { // Fill a matrix with standard random numbers. - var normal = new Normal - { - RandomSource = new MersenneTwister(1) - }; + var normal = new Normal(new MersenneTwister(1)); var matrixA = new DenseMatrix(row, col); for (var i = 0; i < row; i++) { @@ -140,10 +137,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex public static Matrix GenerateRandomPositiveDefiniteHermitianDenseMatrix(int order) { // Fill a matrix with standard random numbers. - var normal = new Normal - { - RandomSource = new MersenneTwister(1) - }; + var normal = new Normal(new MersenneTwister(1)); var matrixA = new DenseMatrix(order); for (var i = 0; i < order; i++) { @@ -165,10 +159,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex public static Vector GenerateRandomDenseVector(int order) { // Fill a matrix with standard random numbers. - var normal = new Normal - { - RandomSource = new MersenneTwister(1) - }; + var normal = new Normal(new MersenneTwister(1)); var v = new DenseVector(order); for (var i = 0; i < order; i++) { @@ -187,10 +178,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex public static Matrix GenerateRandomUserDefinedMatrix(int row, int col) { // Fill a matrix with standard random numbers. - var normal = new Normal - { - RandomSource = new MersenneTwister(1) - }; + var normal = new Normal(new MersenneTwister(1)); var matrixA = new UserDefinedMatrix(row, col); for (var i = 0; i < row; i++) { @@ -211,10 +199,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex public static Matrix GenerateRandomPositiveDefiniteHermitianUserDefinedMatrix(int order) { // Fill a matrix with standard random numbers. - var normal = new Normal - { - RandomSource = new MersenneTwister(1) - }; + var normal = new Normal(new MersenneTwister(1)); var matrixA = new UserDefinedMatrix(order); for (var i = 0; i < order; i++) { @@ -236,10 +221,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex public static Vector GenerateRandomUserDefinedVector(int order) { // Fill a matrix with standard random numbers. - var normal = new Normal - { - RandomSource = new MersenneTwister(1) - }; + var normal = new Normal(new MersenneTwister(1)); var v = new UserDefinedVector(order); for (var i = 0; i < order; i++) { diff --git a/src/UnitTests/LinearAlgebraTests/Complex/MatrixStructureTheory.cs b/src/UnitTests/LinearAlgebraTests/Complex/MatrixStructureTheory.cs index c50719e3..e63585ab 100644 --- a/src/UnitTests/LinearAlgebraTests/Complex/MatrixStructureTheory.cs +++ b/src/UnitTests/LinearAlgebraTests/Complex/MatrixStructureTheory.cs @@ -77,7 +77,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex protected override Matrix CreateDenseRandom(int rows, int columns, int seed) { - var dist = new Normal {RandomSource = new MersenneTwister(seed)}; + var dist = new Normal(new MersenneTwister(seed)); return new DenseMatrix(rows, columns, Enumerable.Range(0, rows*columns).Select(k => new Complex(dist.Sample(), dist.Sample())).ToArray()); } @@ -93,7 +93,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex protected override Vector CreateVectorRandom(int size, int seed) { - var dist = new Normal {RandomSource = new MersenneTwister(seed)}; + var dist = new Normal(new MersenneTwister(seed)); return new DenseVector(Enumerable.Range(0, size).Select(k => new Complex(dist.Sample(), dist.Sample())).ToArray()); } } diff --git a/src/UnitTests/LinearAlgebraTests/Complex32/MatrixLoader.cs b/src/UnitTests/LinearAlgebraTests/Complex32/MatrixLoader.cs index f05952ba..868246ba 100644 --- a/src/UnitTests/LinearAlgebraTests/Complex32/MatrixLoader.cs +++ b/src/UnitTests/LinearAlgebraTests/Complex32/MatrixLoader.cs @@ -116,10 +116,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32 public static Matrix GenerateRandomDenseMatrix(int row, int col) { // Fill a matrix with standard random numbers. - var normal = new Normal - { - RandomSource = new MersenneTwister(1) - }; + var normal = new Normal(new MersenneTwister(1)); var matrixA = new DenseMatrix(row, col); for (var i = 0; i < row; i++) { @@ -140,10 +137,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32 public static Matrix GenerateRandomPositiveDefiniteHermitianDenseMatrix(int order) { // Fill a matrix with standard random numbers. - var normal = new Normal - { - RandomSource = new MersenneTwister(1) - }; + var normal = new Normal(new MersenneTwister(1)); var matrixA = new DenseMatrix(order); for (var i = 0; i < order; i++) { @@ -165,10 +159,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32 public static Vector GenerateRandomDenseVector(int order) { // Fill a matrix with standard random numbers. - var normal = new Normal - { - RandomSource = new MersenneTwister(1) - }; + var normal = new Normal(new MersenneTwister(1)); var v = new DenseVector(order); for (var i = 0; i < order; i++) { @@ -187,10 +178,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32 public static Matrix GenerateRandomUserDefinedMatrix(int row, int col) { // Fill a matrix with standard random numbers. - var normal = new Normal - { - RandomSource = new MersenneTwister(1) - }; + var normal = new Normal(new MersenneTwister(1)); var matrixA = new UserDefinedMatrix(row, col); for (var i = 0; i < row; i++) { @@ -211,10 +199,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32 public static Matrix GenerateRandomPositiveDefiniteHermitianUserDefinedMatrix(int order) { // Fill a matrix with standard random numbers. - var normal = new Normal - { - RandomSource = new MersenneTwister(1) - }; + var normal = new Normal(new MersenneTwister(1)); var matrixA = new UserDefinedMatrix(order); for (var i = 0; i < order; i++) { @@ -236,10 +221,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32 public static Vector GenerateRandomUserDefinedVector(int order) { // Fill a matrix with standard random numbers. - var normal = new Normal - { - RandomSource = new MersenneTwister(1) - }; + var normal = new Normal(new MersenneTwister(1)); var v = new UserDefinedVector(order); for (var i = 0; i < order; i++) { diff --git a/src/UnitTests/LinearAlgebraTests/Complex32/MatrixStructureTheory.cs b/src/UnitTests/LinearAlgebraTests/Complex32/MatrixStructureTheory.cs index 7ad99f8a..de6c54fe 100644 --- a/src/UnitTests/LinearAlgebraTests/Complex32/MatrixStructureTheory.cs +++ b/src/UnitTests/LinearAlgebraTests/Complex32/MatrixStructureTheory.cs @@ -77,7 +77,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32 protected override Matrix CreateDenseRandom(int rows, int columns, int seed) { - var dist = new Normal {RandomSource = new MersenneTwister(seed)}; + var dist = new Normal(new MersenneTwister(seed)); return new DenseMatrix(rows, columns, Enumerable.Range(0, rows*columns).Select(k => new Complex32((float) dist.Sample(), (float) dist.Sample())).ToArray()); } @@ -93,7 +93,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32 protected override Vector CreateVectorRandom(int size, int seed) { - var dist = new Normal {RandomSource = new MersenneTwister(seed)}; + var dist = new Normal(new MersenneTwister(seed)); return new DenseVector(Enumerable.Range(0, size).Select(k => new Complex32((float) dist.Sample(), (float) dist.Sample())).ToArray()); } } diff --git a/src/UnitTests/LinearAlgebraTests/Double/MatrixLoader.cs b/src/UnitTests/LinearAlgebraTests/Double/MatrixLoader.cs index 882987dc..fee08ac8 100644 --- a/src/UnitTests/LinearAlgebraTests/Double/MatrixLoader.cs +++ b/src/UnitTests/LinearAlgebraTests/Double/MatrixLoader.cs @@ -115,10 +115,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double public static Matrix GenerateRandomDenseMatrix(int row, int col) { // Fill a matrix with standard random numbers. - var normal = new Normal - { - RandomSource = new MersenneTwister(1) - }; + var normal = new Normal(new MersenneTwister(1)); var matrixA = new DenseMatrix(row, col); for (var i = 0; i < row; i++) { @@ -139,10 +136,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double public static Matrix GenerateRandomPositiveDefiniteDenseMatrix(int order) { // Fill a matrix with standard random numbers. - var normal = new Normal - { - RandomSource = new MersenneTwister(1) - }; + var normal = new Normal(new MersenneTwister(1)); var matrixA = new DenseMatrix(order); for (var i = 0; i < order; i++) { @@ -164,10 +158,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double public static Vector GenerateRandomDenseVector(int order) { // Fill a matrix with standard random numbers. - var normal = new Normal - { - RandomSource = new MersenneTwister(1) - }; + var normal = new Normal(new MersenneTwister(1)); var v = new DenseVector(order); for (var i = 0; i < order; i++) { @@ -186,10 +177,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double public static Matrix GenerateRandomUserDefinedMatrix(int row, int col) { // Fill a matrix with standard random numbers. - var normal = new Normal - { - RandomSource = new MersenneTwister(1) - }; + var normal = new Normal(new MersenneTwister(1)); var matrixA = new UserDefinedMatrix(row, col); for (var i = 0; i < row; i++) { @@ -210,10 +198,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double public static Matrix GenerateRandomPositiveDefiniteUserDefinedMatrix(int order) { // Fill a matrix with standard random numbers. - var normal = new Normal - { - RandomSource = new MersenneTwister(1) - }; + var normal = new Normal(new MersenneTwister(1)); var matrixA = new UserDefinedMatrix(order); for (var i = 0; i < order; i++) { @@ -235,10 +220,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double public static Vector GenerateRandomUserDefinedVector(int order) { // Fill a matrix with standard random numbers. - var normal = new Normal - { - RandomSource = new MersenneTwister(1) - }; + var normal = new Normal(new MersenneTwister(1)); var v = new UserDefinedVector(order); for (var i = 0; i < order; i++) { diff --git a/src/UnitTests/LinearAlgebraTests/Double/MatrixStructureTheory.cs b/src/UnitTests/LinearAlgebraTests/Double/MatrixStructureTheory.cs index 77ea7da0..d1e1dd31 100644 --- a/src/UnitTests/LinearAlgebraTests/Double/MatrixStructureTheory.cs +++ b/src/UnitTests/LinearAlgebraTests/Double/MatrixStructureTheory.cs @@ -76,7 +76,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double protected override Matrix CreateDenseRandom(int rows, int columns, int seed) { - var dist = new Normal {RandomSource = new MersenneTwister(seed)}; + var dist = new Normal(new MersenneTwister(seed)); return new DenseMatrix(rows, columns, dist.Samples().Take(rows*columns).ToArray()); } @@ -92,7 +92,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double protected override Vector CreateVectorRandom(int size, int seed) { - var dist = new Normal {RandomSource = new MersenneTwister(seed)}; + var dist = new Normal(new MersenneTwister(seed)); return new DenseVector(dist.Samples().Take(size).ToArray()); } } diff --git a/src/UnitTests/LinearAlgebraTests/Single/MatrixLoader.cs b/src/UnitTests/LinearAlgebraTests/Single/MatrixLoader.cs index 7aa1bd03..53e4a49b 100644 --- a/src/UnitTests/LinearAlgebraTests/Single/MatrixLoader.cs +++ b/src/UnitTests/LinearAlgebraTests/Single/MatrixLoader.cs @@ -115,10 +115,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single public static Matrix GenerateRandomDenseMatrix(int row, int col) { // Fill a matrix with standard random numbers. - var normal = new Normal - { - RandomSource = new MersenneTwister(1) - }; + var normal = new Normal(new MersenneTwister(1)); var matrixA = new DenseMatrix(row, col); for (var i = 0; i < row; i++) { @@ -139,10 +136,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single public static Matrix GenerateRandomPositiveDefiniteDenseMatrix(int order) { // Fill a matrix with standard random numbers. - var normal = new Normal - { - RandomSource = new MersenneTwister(1) - }; + var normal = new Normal(new MersenneTwister(1)); var matrixA = new DenseMatrix(order); for (var i = 0; i < order; i++) { @@ -164,10 +158,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single public static Vector GenerateRandomDenseVector(int order) { // Fill a matrix with standard random numbers. - var normal = new Normal - { - RandomSource = new MersenneTwister(1) - }; + var normal = new Normal(new MersenneTwister(1)); var v = new DenseVector(order); for (var i = 0; i < order; i++) { @@ -186,10 +177,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single public static Matrix GenerateRandomUserDefinedMatrix(int row, int col) { // Fill a matrix with standard random numbers. - var normal = new Normal - { - RandomSource = new MersenneTwister(1) - }; + var normal = new Normal(new MersenneTwister(1)); var matrixA = new UserDefinedMatrix(row, col); for (var i = 0; i < row; i++) { @@ -210,10 +198,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single public static Matrix GenerateRandomPositiveDefiniteUserDefinedMatrix(int order) { // Fill a matrix with standard random numbers. - var normal = new Normal - { - RandomSource = new MersenneTwister(1) - }; + var normal = new Normal(new MersenneTwister(1)); var matrixA = new UserDefinedMatrix(order); for (var i = 0; i < order; i++) { @@ -235,10 +220,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single public static Vector GenerateRandomUserDefinedVector(int order) { // Fill a matrix with standard random numbers. - var normal = new Normal - { - RandomSource = new MersenneTwister(1) - }; + var normal = new Normal(new MersenneTwister(1)); var v = new UserDefinedVector(order); for (var i = 0; i < order; i++) { diff --git a/src/UnitTests/LinearAlgebraTests/Single/MatrixStructureTheory.cs b/src/UnitTests/LinearAlgebraTests/Single/MatrixStructureTheory.cs index 952aa1f8..800d5cb7 100644 --- a/src/UnitTests/LinearAlgebraTests/Single/MatrixStructureTheory.cs +++ b/src/UnitTests/LinearAlgebraTests/Single/MatrixStructureTheory.cs @@ -76,7 +76,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single protected override Matrix CreateDenseRandom(int rows, int columns, int seed) { - var dist = new Normal {RandomSource = new MersenneTwister(seed)}; + var dist = new Normal(new MersenneTwister(seed)); return new DenseMatrix(rows, columns, dist.Samples().Select(d => (float) d).Take(rows*columns).ToArray()); } @@ -92,7 +92,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single protected override Vector CreateVectorRandom(int size, int seed) { - var dist = new Normal {RandomSource = new MersenneTwister(seed)}; + var dist = new Normal(new MersenneTwister(seed)); return new DenseVector(dist.Samples().Select(d => (float) d).Take(size).ToArray()); } } diff --git a/src/UnitTests/StatisticsTests/MCMCTests/RejectionSamplerTests.cs b/src/UnitTests/StatisticsTests/MCMCTests/RejectionSamplerTests.cs index 4659ffc5..199ea215 100644 --- a/src/UnitTests/StatisticsTests/MCMCTests/RejectionSamplerTests.cs +++ b/src/UnitTests/StatisticsTests/MCMCTests/RejectionSamplerTests.cs @@ -48,11 +48,7 @@ namespace MathNet.Numerics.UnitTests.StatisticsTests.McmcTests [Test] public void RejectTest() { - var uniform = new ContinuousUniform(0.0, 1.0) - { - RandomSource = new MersenneTwister() - }; - + var uniform = new ContinuousUniform(0.0, 1.0, new MersenneTwister()); var rs = new RejectionSampler(x => Math.Pow(x, 1.7)*Math.Pow(1.0 - x, 5.3), x => 0.021, uniform.Sample); Assert.IsNotNull(rs.RandomSource); @@ -66,10 +62,7 @@ namespace MathNet.Numerics.UnitTests.StatisticsTests.McmcTests [Test] public void SampleTest() { - var uniform = new ContinuousUniform(0.0, 1.0) - { - RandomSource = new MersenneTwister() - }; + var uniform = new ContinuousUniform(0.0, 1.0, new MersenneTwister()); var rs = new RejectionSampler(x => Math.Pow(x, 1.7)*Math.Pow(1.0 - x, 5.3), x => 0.021, uniform.Sample) { @@ -85,10 +78,7 @@ namespace MathNet.Numerics.UnitTests.StatisticsTests.McmcTests [Test] public void SampleArrayTest() { - var uniform = new ContinuousUniform(0.0, 1.0) - { - RandomSource = new MersenneTwister() - }; + var uniform = new ContinuousUniform(0.0, 1.0, new MersenneTwister()); var rs = new RejectionSampler(x => Math.Pow(x, 1.7)*Math.Pow(1.0 - x, 5.3), x => 0.021, uniform.Sample) { @@ -104,11 +94,7 @@ namespace MathNet.Numerics.UnitTests.StatisticsTests.McmcTests [Test] public void NoUpperBound() { - var uniform = new ContinuousUniform(0.0, 1.0) - { - RandomSource = new MersenneTwister() - }; - + var uniform = new ContinuousUniform(0.0, 1.0, new MersenneTwister()); var rs = new RejectionSampler(x => Math.Pow(x, 1.7)*Math.Pow(1.0 - x, 5.3), x => Double.NegativeInfinity, uniform.Sample); Assert.Throws(() => rs.Sample()); } @@ -119,10 +105,7 @@ namespace MathNet.Numerics.UnitTests.StatisticsTests.McmcTests [Test] public void NullRandomNumberGenerator() { - var uniform = new ContinuousUniform(0.0, 1.0) - { - RandomSource = new MersenneTwister() - }; + var uniform = new ContinuousUniform(0.0, 1.0, new MersenneTwister()); var rs = new RejectionSampler(x => Math.Pow(x, 1.7)*Math.Pow(1.0 - x, 5.3), x => Double.NegativeInfinity, uniform.Sample); Assert.Throws(() => rs.RandomSource = null); } diff --git a/src/UnitTests/StatisticsTests/StatisticsTests.cs b/src/UnitTests/StatisticsTests/StatisticsTests.cs index a9f51ed3..d491d48e 100644 --- a/src/UnitTests/StatisticsTests/StatisticsTests.cs +++ b/src/UnitTests/StatisticsTests/StatisticsTests.cs @@ -28,6 +28,8 @@ // OTHER DEALINGS IN THE SOFTWARE. // +using MathNet.Numerics.Random; + namespace MathNet.Numerics.UnitTests.StatisticsTests { using System; @@ -557,10 +559,7 @@ namespace MathNet.Numerics.UnitTests.StatisticsTests public void StabilityMeanVariance() { // Test around 10^9, potential stability issues - var gaussian = new Distributions.Normal(1e+9, 2) - { - RandomSource = new Numerics.Random.MersenneTwister(100) - }; + var gaussian = new Distributions.Normal(1e+9, 2, new MersenneTwister(100)); AssertHelpers.AlmostEqual(1e+9, Statistics.Mean(gaussian.Samples().Take(10000)), 11); AssertHelpers.AlmostEqual(4d, Statistics.Variance(gaussian.Samples().Take(10000)), 1);