diff --git a/src/Numerics/Distributions/Discrete/Bernoulli.cs b/src/Numerics/Distributions/Bernoulli.cs similarity index 91% rename from src/Numerics/Distributions/Discrete/Bernoulli.cs rename to src/Numerics/Distributions/Bernoulli.cs index 7f2ee52d..c94b13b1 100644 --- a/src/Numerics/Distributions/Discrete/Bernoulli.cs +++ b/src/Numerics/Distributions/Bernoulli.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-2013 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 @@ -24,13 +28,14 @@ // OTHER DEALINGS IN THE SOFTWARE. // +using System; +using System.Collections.Generic; +using MathNet.Numerics.Properties; + namespace MathNet.Numerics.Distributions { - using System; - using System.Collections.Generic; - using Properties; - /// + /// Discrete Univariate Bernoulli distribution. /// The Bernoulli distribution is a distribution over bits. The parameter /// p specifies the probability that a 1 is generated. /// Wikipedia - Bernoulli distribution. @@ -50,7 +55,7 @@ namespace MathNet.Numerics.Distributions /// /// The distribution's random number generator. /// - Random _random; + System.Random _random; /// /// Initializes a new instance of the Bernoulli class. @@ -59,7 +64,7 @@ namespace MathNet.Numerics.Distributions /// If the Bernoulli parameter is not in the range [0,1]. public Bernoulli(double p) { - _random = new Random(); + _random = new System.Random(); SetParameters(p); } @@ -69,9 +74,9 @@ namespace MathNet.Numerics.Distributions /// 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) + public Bernoulli(double p, System.Random randomSource) { - _random = randomSource ?? new Random(); + _random = randomSource ?? new System.Random(); SetParameters(p); } @@ -118,12 +123,10 @@ namespace MathNet.Numerics.Distributions set { SetParameters(value); } } - #region IDistribution Members - /// /// Gets or sets the random number generator which is used to draw random samples. /// - public Random RandomSource + public System.Random RandomSource { get { return _random; } set @@ -193,30 +196,6 @@ namespace MathNet.Numerics.Distributions get { return 1; } } - /// - /// Computes the cumulative distribution function of the Bernoulli distribution. - /// - /// The location at which to compute the cumulative density. - /// the cumulative density at . - public double CumulativeDistribution(double x) - { - if (x < 0.0) - { - return 0.0; - } - - if (x < 1.0) - { - return 1.0 - _p; - } - - return 1.0; - } - - #endregion - - #region IDiscreteDistribution Members - /// /// Gets the mode of the distribution. /// @@ -234,7 +213,7 @@ namespace MathNet.Numerics.Distributions } /// - /// Computes values of the probability mass function. + /// Computes the probability mass (PMF), i.e. P(X = x). /// /// The location in the domain where we want to evaluate the probability mass function. /// the probability mass at location . @@ -254,7 +233,7 @@ namespace MathNet.Numerics.Distributions } /// - /// Computes values of the log probability mass function. + /// Computes the log probability mass (lnPMF), i.e. ln(P(X = x)). /// /// The location in the domain where we want to evaluate the log probability mass function. /// the log probability mass at location . @@ -268,7 +247,25 @@ namespace MathNet.Numerics.Distributions return k == 1 ? Math.Log(_p) : Double.NegativeInfinity; } - #endregion + /// + /// Computes the cumulative distribution (CDF) of the distribution, i.e. P(X <= x). + /// + /// The location at which to compute the cumulative distribution function. + /// the cumulative distribution at location . + public double CumulativeDistribution(double x) + { + if (x < 0.0) + { + return 0.0; + } + + if (x < 1.0) + { + return 1.0 - _p; + } + + return 1.0; + } /// /// Generates one sample from the Bernoulli distribution. @@ -276,7 +273,7 @@ namespace MathNet.Numerics.Distributions /// The random source to use. /// The probability of generating a one. /// A random sample from the Bernoulli distribution. - internal static int SampleUnchecked(Random rnd, double p) + internal static int SampleUnchecked(System.Random rnd, double p) { if (rnd.NextDouble() < p) { @@ -313,7 +310,7 @@ namespace MathNet.Numerics.Distributions /// The random number generator to use. /// The probability of generating a 1. /// A sample from the Bernoulli distribution. - public static int Sample(Random rnd, double p) + public static int Sample(System.Random rnd, double p) { if (Control.CheckDistributionParameters && !IsValidParameterSet(p)) { @@ -329,7 +326,7 @@ namespace MathNet.Numerics.Distributions /// The random number generator to use. /// The probability of generating a 1. /// a sequence of samples from the distribution. - public static IEnumerable Samples(Random rnd, double p) + public static IEnumerable Samples(System.Random rnd, double p) { if (Control.CheckDistributionParameters && !IsValidParameterSet(p)) { diff --git a/src/Numerics/Distributions/Continuous/Beta.cs b/src/Numerics/Distributions/Beta.cs similarity index 92% rename from src/Numerics/Distributions/Continuous/Beta.cs rename to src/Numerics/Distributions/Beta.cs index b7f1e95e..5e823b49 100644 --- a/src/Numerics/Distributions/Continuous/Beta.cs +++ b/src/Numerics/Distributions/Beta.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-2013 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 @@ -24,14 +28,15 @@ // OTHER DEALINGS IN THE SOFTWARE. // +using System; +using System.Collections.Generic; +using MathNet.Numerics.Properties; + namespace MathNet.Numerics.Distributions { - using System; - using System.Collections.Generic; - using Properties; - /// - /// Implements the Beta distribution. For details about this distribution, see + /// Continuous Univariate Beta distribution. + /// For details about this distribution, see /// Wikipedia - Beta distribution. /// /// @@ -61,7 +66,7 @@ namespace MathNet.Numerics.Distributions /// /// The distribution's random number generator. /// - Random _random; + System.Random _random; /// /// Initializes a new instance of the Beta class. @@ -71,7 +76,7 @@ namespace MathNet.Numerics.Distributions /// If any of the Beta parameters are negative. public Beta(double a, double b) { - _random = new Random(); + _random = new System.Random(); SetParameters(a, b); } @@ -82,9 +87,9 @@ namespace MathNet.Numerics.Distributions /// 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) + public Beta(double a, double b, System.Random randomSource) { - _random = randomSource ?? new Random(); + _random = randomSource ?? new System.Random(); SetParameters(a, b); } @@ -143,12 +148,10 @@ namespace MathNet.Numerics.Distributions set { SetParameters(_shapeA, value); } } - #region IDistribution implementation - /// /// Gets or sets the random number generator which is used to draw random samples. /// - public Random RandomSource + public System.Random RandomSource { get { return _random; } set @@ -242,9 +245,9 @@ namespace MathNet.Numerics.Distributions } return SpecialFunctions.BetaLn(_shapeA, _shapeB) - - ((_shapeA - 1.0)*SpecialFunctions.DiGamma(_shapeA)) - - ((_shapeB - 1.0)*SpecialFunctions.DiGamma(_shapeB)) - + ((_shapeA + _shapeB - 2.0)*SpecialFunctions.DiGamma(_shapeA + _shapeB)); + - ((_shapeA - 1.0)*SpecialFunctions.DiGamma(_shapeA)) + - ((_shapeB - 1.0)*SpecialFunctions.DiGamma(_shapeB)) + + ((_shapeA + _shapeB - 2.0)*SpecialFunctions.DiGamma(_shapeA + _shapeB)); } } @@ -286,14 +289,10 @@ namespace MathNet.Numerics.Distributions } return 2.0*(_shapeB - _shapeA)*Math.Sqrt(_shapeA + _shapeB + 1.0) - /((_shapeA + _shapeB + 2.0)*Math.Sqrt(_shapeA*_shapeB)); + /((_shapeA + _shapeB + 2.0)*Math.Sqrt(_shapeA*_shapeB)); } } - #endregion - - #region IContinuousDistribution implementation - /// /// Gets the mode of the Beta distribution; when there are multiple answers, this routine will return 0.5. /// @@ -365,7 +364,7 @@ namespace MathNet.Numerics.Distributions } /// - /// Computes the density of the Beta distribution. + /// Computes the density of the distribution (PDF), i.e. dP(X <= x)/dx. /// /// The location at which to compute the density. /// the density at . @@ -421,7 +420,7 @@ namespace MathNet.Numerics.Distributions } /// - /// Computes the log density of the Beta distribution. + /// Computes the log density of the distribution (lnPDF), i.e. ln(dP(X <= x)/dx). /// /// The location at which to compute the log density. /// the log density at . @@ -480,10 +479,10 @@ namespace MathNet.Numerics.Distributions } /// - /// Computes the cumulative distribution function of the Beta distribution. + /// Computes the cumulative distribution (CDF) of the distribution, i.e. P(X <= x). /// - /// The location at which to compute the cumulative density. - /// the cumulative density at . + /// The location at which to compute the cumulative distribution function. + /// the cumulative distribution at location . public double CumulativeDistribution(double x) { if (x < 0.0) @@ -539,8 +538,6 @@ namespace MathNet.Numerics.Distributions return SpecialFunctions.BetaRegularized(_shapeA, _shapeB, x); } - #endregion - /// /// Samples Beta distributed random variables by sampling two Gamma variables and normalizing. /// @@ -548,7 +545,7 @@ namespace MathNet.Numerics.Distributions /// The A shape parameter. /// The B shape parameter. /// a random number from the Beta distribution. - internal static double SampleUnchecked(Random rnd, double a, double b) + internal static double SampleUnchecked(System.Random rnd, double a, double b) { var x = Gamma.SampleUnchecked(rnd, a, 1.0); var y = Gamma.SampleUnchecked(rnd, b, 1.0); @@ -583,7 +580,7 @@ namespace MathNet.Numerics.Distributions /// The a shape parameter of the Beta distribution. /// The b shape parameter of the Beta distribution. /// a sample from the distribution. - public static double Sample(Random rnd, double a, double b) + public static double Sample(System.Random rnd, double a, double b) { if (Control.CheckDistributionParameters && !IsValidParameterSet(a, b)) { @@ -600,7 +597,7 @@ namespace MathNet.Numerics.Distributions /// The a shape parameter of the Beta distribution. /// The b shape parameter of the Beta distribution. /// a sequence of samples from the distribution. - public static IEnumerable Samples(Random rnd, double a, double b) + public static IEnumerable Samples(System.Random rnd, double a, double b) { if (Control.CheckDistributionParameters && !IsValidParameterSet(a, b)) { diff --git a/src/Numerics/Distributions/Discrete/Binomial.cs b/src/Numerics/Distributions/Binomial.cs similarity index 92% rename from src/Numerics/Distributions/Discrete/Binomial.cs rename to src/Numerics/Distributions/Binomial.cs index fed6eb37..43131d9a 100644 --- a/src/Numerics/Distributions/Discrete/Binomial.cs +++ b/src/Numerics/Distributions/Binomial.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-2013 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 @@ -24,14 +28,15 @@ // OTHER DEALINGS IN THE SOFTWARE. // +using System; +using System.Collections.Generic; +using MathNet.Numerics.Properties; + namespace MathNet.Numerics.Distributions { - using System; - using System.Collections.Generic; - using Properties; - /// - /// Implements the binomial distribution. For details about this distribution, see + /// Discrete Univariate Binomial distribution. + /// For details about this distribution, see /// Wikipedia - Binomial distribution. /// /// The distribution is parameterized by a probability (between 0.0 and 1.0). @@ -55,7 +60,7 @@ namespace MathNet.Numerics.Distributions /// /// The distribution's random number generator. /// - Random _random; + System.Random _random; /// /// Initializes a new instance of the Binomial class. @@ -66,7 +71,7 @@ namespace MathNet.Numerics.Distributions /// If is negative. public Binomial(double p, int n) { - _random = new Random(); + _random = new System.Random(); SetParameters(p, n); } @@ -78,9 +83,9 @@ namespace MathNet.Numerics.Distributions /// 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) + public Binomial(double p, int n, System.Random randomSource) { - _random = randomSource ?? new Random(); + _random = randomSource ?? new System.Random(); SetParameters(p, n); } @@ -140,12 +145,10 @@ namespace MathNet.Numerics.Distributions set { SetParameters(_p, value); } } - #region IDistribution Members - /// /// Gets or sets the random number generator which is used to draw random samples. /// - public Random RandomSource + public System.Random RandomSource { get { return _random; } set @@ -230,36 +233,6 @@ namespace MathNet.Numerics.Distributions get { return _n; } } - /// - /// Computes the cumulative distribution function of the Binomial distribution. - /// - /// The location at which to compute the cumulative density. - /// the cumulative density at . - public double CumulativeDistribution(double x) - { - if (x < 0.0) - { - return 0.0; - } - - if (x > _n) - { - return 1.0; - } - - var cdf = 0.0; - for (var i = 0; i <= (int) Math.Floor(x); i++) - { - cdf += Combinatorics.Combinations(_n, i)*Math.Pow(_p, i)*Math.Pow(1.0 - _p, _n - i); - } - - return cdf; - } - - #endregion - - #region IDiscreteDistribution Members - /// /// Gets the mode of the distribution. /// @@ -290,7 +263,7 @@ namespace MathNet.Numerics.Distributions } /// - /// Computes values of the probability mass function. + /// Computes the probability mass (PMF), i.e. P(X = x). /// /// The location in the domain where we want to evaluate the probability mass function. /// the probability mass at location . @@ -330,7 +303,7 @@ namespace MathNet.Numerics.Distributions } /// - /// Computes values of the log probability mass function. + /// Computes the log probability mass (lnPMF), i.e. ln(P(X = x)). /// /// The location in the domain where we want to evaluate the log probability mass function. /// the log probability mass at location . @@ -369,7 +342,31 @@ namespace MathNet.Numerics.Distributions return SpecialFunctions.BinomialLn(_n, k) + (k*Math.Log(_p)) + ((_n - k)*Math.Log(1.0 - _p)); } - #endregion + /// + /// Computes the cumulative distribution (CDF) of the distribution, i.e. P(X <= x). + /// + /// The location at which to compute the cumulative distribution function. + /// the cumulative distribution at location . + public double CumulativeDistribution(double x) + { + if (x < 0.0) + { + return 0.0; + } + + if (x > _n) + { + return 1.0; + } + + var cdf = 0.0; + for (var i = 0; i <= (int) Math.Floor(x); i++) + { + cdf += Combinatorics.Combinations(_n, i)*Math.Pow(_p, i)*Math.Pow(1.0 - _p, _n - i); + } + + return cdf; + } /// /// Generates a sample from the Binomial distribution without doing parameter checking. @@ -378,7 +375,7 @@ namespace MathNet.Numerics.Distributions /// The success probability of a trial; must be in the interval [0.0, 1.0]. /// The number of trials; must be positive. /// The number of successful trials. - internal static int SampleUnchecked(Random rnd, double p, int n) + internal static int SampleUnchecked(System.Random rnd, double p, int n) { var k = 0; for (var i = 0; i < n; i++) @@ -417,7 +414,7 @@ namespace MathNet.Numerics.Distributions /// The success probability of a trial; must be in the interval [0.0, 1.0]. /// The number of trials; must be positive. /// The number of successes in trials. - public static int Sample(Random rnd, double p, int n) + public static int Sample(System.Random rnd, double p, int n) { if (Control.CheckDistributionParameters && !IsValidParameterSet(p, n)) { @@ -434,7 +431,7 @@ namespace MathNet.Numerics.Distributions /// The success probability of a trial; must be in the interval [0.0, 1.0]. /// The number of trials; must be positive. /// a sequence of successes in trials. - public static IEnumerable Samples(Random rnd, double p, int n) + public static IEnumerable Samples(System.Random rnd, double p, int n) { if (Control.CheckDistributionParameters && !IsValidParameterSet(p, n)) { diff --git a/src/Numerics/Distributions/Discrete/Categorical.cs b/src/Numerics/Distributions/Categorical.cs similarity index 93% rename from src/Numerics/Distributions/Discrete/Categorical.cs rename to src/Numerics/Distributions/Categorical.cs index 17cebe1e..281584e1 100644 --- a/src/Numerics/Distributions/Discrete/Categorical.cs +++ b/src/Numerics/Distributions/Categorical.cs @@ -28,16 +28,17 @@ // OTHER DEALINGS IN THE SOFTWARE. // +using System; +using System.Collections.Generic; +using System.Linq; +using MathNet.Numerics.Properties; +using MathNet.Numerics.Statistics; + namespace MathNet.Numerics.Distributions { - using System; - using System.Collections.Generic; - using System.Linq; - using Properties; - using Statistics; - /// - /// Implements the categorical distribution. For details about this distribution, see + /// Discrete Univariate Categorical distribution. + /// For details about this distribution, see /// Wikipedia - Categorical distribution. This /// distribution is sometimes called the Discrete distribution. /// @@ -51,7 +52,7 @@ namespace MathNet.Numerics.Distributions /// to false, all parameter checks can be turned off. public class Categorical : IDiscreteDistribution { - Random _random; + System.Random _random; double[] _pmfNormalized; double[] _cdfUnnormalized; @@ -63,7 +64,7 @@ namespace MathNet.Numerics.Distributions /// If any of the probabilities are negative or do not sum to one. public Categorical(double[] probabilityMass) { - _random = new Random(); + _random = new System.Random(); SetParameters(probabilityMass); } @@ -74,9 +75,9 @@ namespace MathNet.Numerics.Distributions /// 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) + public Categorical(double[] probabilityMass, System.Random randomSource) { - _random = randomSource ?? new Random(); + _random = randomSource ?? new System.Random(); SetParameters(probabilityMass); } @@ -102,7 +103,7 @@ namespace MathNet.Numerics.Distributions p[i] = histogram[i].Count; } - _random = new Random(); + _random = new System.Random(); SetParameters(p); } @@ -201,12 +202,10 @@ namespace MathNet.Numerics.Distributions set { SetParameters(value); } } - #region IDistribution Members - /// /// Gets or sets the random number generator which is used to draw random samples. /// - public Random RandomSource + public System.Random RandomSource { get { return _random; } set @@ -277,30 +276,6 @@ namespace MathNet.Numerics.Distributions get { return _pmfNormalized.Length - 1; } } - /// - /// Computes the cumulative distribution function of the Binomial distribution. - /// - /// The location at which to compute the cumulative density. - /// the cumulative density at . - public double CumulativeDistribution(double x) - { - if (x < 0.0) - { - return 0.0; - } - - if (x >= _cdfUnnormalized.Length) - { - return 1.0; - } - - return _cdfUnnormalized[(int) Math.Floor(x)]/_cdfUnnormalized[_cdfUnnormalized.Length - 1]; - } - - #endregion - - #region IDiscreteDistribution Members - /// /// Gets he mode of the distribution. /// @@ -319,7 +294,7 @@ namespace MathNet.Numerics.Distributions } /// - /// Computes values of the probability mass function. + /// Computes the probability mass (PMF), i.e. P(X = x). /// /// The location in the domain where we want to evaluate the probability mass function. /// the probability mass at location . @@ -339,7 +314,7 @@ namespace MathNet.Numerics.Distributions } /// - /// Computes values of the log probability mass function. + /// Computes the log probability mass (lnPMF), i.e. ln(P(X = x)). /// /// The location in the domain where we want to evaluate the log probability mass function. /// the log probability mass at location . @@ -358,7 +333,25 @@ namespace MathNet.Numerics.Distributions return Math.Log(_pmfNormalized[k]); } - #endregion + /// + /// Computes the cumulative distribution (CDF) of the distribution, i.e. P(X <= x). + /// + /// The location at which to compute the cumulative distribution function. + /// the cumulative distribution at location . + public double CumulativeDistribution(double x) + { + if (x < 0.0) + { + return 0.0; + } + + if (x >= _cdfUnnormalized.Length) + { + return 1.0; + } + + return _cdfUnnormalized[(int) Math.Floor(x)]/_cdfUnnormalized[_cdfUnnormalized.Length - 1]; + } /// /// Computes the cumulative distribution function. This method performs no parameter checking. @@ -385,7 +378,7 @@ namespace MathNet.Numerics.Distributions /// The random number generator to use. /// The (unnormalized) cumulative distribution of the probability distribution. /// One sample from the categorical distribution implied by . - internal static int SampleUnchecked(Random rnd, double[] cdfUnnormalized) + internal static int SampleUnchecked(System.Random rnd, double[] cdfUnnormalized) { // TODO : use binary search to speed up this procedure. var u = rnd.NextDouble()*cdfUnnormalized[cdfUnnormalized.Length - 1]; @@ -426,7 +419,7 @@ namespace MathNet.Numerics.Distributions /// The random number generator to use. /// An array of the cumulative distribution. Not assumed to be normalized. /// One random integer between 0 and the size of the categorical (exclusive). - public static int SampleWithCumulativeDistribution(Random rnd, double[] cdfUnnormalized) + public static int SampleWithCumulativeDistribution(System.Random rnd, double[] cdfUnnormalized) { if (Control.CheckDistributionParameters && !IsValidCumulativeDistribution(cdfUnnormalized)) { @@ -442,7 +435,7 @@ namespace MathNet.Numerics.Distributions /// The random number generator to use. /// An array of nonnegative ratios. Not assumed to be normalized. /// One random integer between 0 and the size of the categorical (exclusive). - public static int SampleWithProbabilityMass(Random rnd, double[] pmfUnnormalized) + public static int SampleWithProbabilityMass(System.Random rnd, double[] pmfUnnormalized) { if (Control.CheckDistributionParameters && !IsValidProbabilityMass(pmfUnnormalized)) { @@ -459,7 +452,7 @@ namespace MathNet.Numerics.Distributions /// The random number generator to use. /// An array of the cumulative distribution. Not assumed to be normalized. /// random integers between 0 and the size of the categorical (exclusive). - public static IEnumerable SamplesWithCumulativeDistribution(Random rnd, double[] cdfUnnormalized) + public static IEnumerable SamplesWithCumulativeDistribution(System.Random rnd, double[] cdfUnnormalized) { if (Control.CheckDistributionParameters && !IsValidCumulativeDistribution(cdfUnnormalized)) { @@ -478,7 +471,7 @@ namespace MathNet.Numerics.Distributions /// The random number generator to use. /// An array of nonnegative ratios. Not assumed to be normalized. /// random integers between 0 and the size of the categorical (exclusive). - public static IEnumerable SamplesWithProbabilityMass(Random rnd, double[] pmfUnnormalized) + public static IEnumerable SamplesWithProbabilityMass(System.Random rnd, double[] pmfUnnormalized) { if (Control.CheckDistributionParameters && !IsValidProbabilityMass(pmfUnnormalized)) { diff --git a/src/Numerics/Distributions/Continuous/Cauchy.cs b/src/Numerics/Distributions/Cauchy.cs similarity index 91% rename from src/Numerics/Distributions/Continuous/Cauchy.cs rename to src/Numerics/Distributions/Cauchy.cs index 9f6213c4..bfdc0404 100644 --- a/src/Numerics/Distributions/Continuous/Cauchy.cs +++ b/src/Numerics/Distributions/Cauchy.cs @@ -24,13 +24,14 @@ // OTHER DEALINGS IN THE SOFTWARE. // +using System; +using System.Collections.Generic; +using MathNet.Numerics.Properties; + namespace MathNet.Numerics.Distributions { - using System; - using System.Collections.Generic; - using Properties; - /// + /// Continuous Univariate Cauchy distribution. /// The Cauchy distribution is a symmetric continuous probability distribution. For details about this distribution, see /// Wikipedia - Cauchy distribution. /// @@ -49,7 +50,7 @@ namespace MathNet.Numerics.Distributions /// /// The distribution's random number generator. /// - Random _random; + System.Random _random; /// /// Initializes a new instance of the class with the location parameter set to 0 and the scale parameter set to 1 @@ -66,7 +67,7 @@ namespace MathNet.Numerics.Distributions /// If is negative. public Cauchy(double location, double scale) { - _random = new Random(); + _random = new System.Random(); SetParameters(location, scale); } @@ -77,9 +78,9 @@ namespace MathNet.Numerics.Distributions /// 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) + public Cauchy(double location, double scale, System.Random randomSource) { - _random = randomSource ?? new Random(); + _random = randomSource ?? new System.Random(); SetParameters(location, scale); } @@ -138,12 +139,10 @@ namespace MathNet.Numerics.Distributions return "Cauchy(Location = " + Median + ", Scale = " + _scale + ")"; } - #region IDistribution Members - /// /// Gets or sets the random number generator which is used to draw random samples. /// - public Random RandomSource + public System.Random RandomSource { get { return _random; } set @@ -197,20 +196,6 @@ namespace MathNet.Numerics.Distributions get { throw new NotSupportedException(); } } - /// - /// Computes the cumulative distribution function of the distribution. - /// - /// The location at which to compute the cumulative density. - /// the cumulative density at . - public double CumulativeDistribution(double x) - { - return ((1.0/Constants.Pi)*Math.Atan((x - Median)/_scale)) + 0.5; - } - - #endregion - - #region IContinuousDistribution Members - /// /// Gets the mode of the distribution. /// @@ -241,7 +226,7 @@ namespace MathNet.Numerics.Distributions } /// - /// Computes the density of the distribution. + /// Computes the density of the distribution (PDF), i.e. dP(X <= x)/dx. /// /// The location at which to compute the density. /// the density at . @@ -251,7 +236,7 @@ namespace MathNet.Numerics.Distributions } /// - /// Computes the log density of the distribution. + /// Computes the log density of the distribution (lnPDF), i.e. ln(dP(X <= x)/dx). /// /// The location at which to compute the log density. /// the log density at . @@ -260,7 +245,15 @@ namespace MathNet.Numerics.Distributions return -Math.Log(Constants.Pi*_scale*(1.0 + (((x - Median)/_scale)*((x - Median)/_scale)))); } - #endregion + /// + /// Computes the cumulative distribution (CDF) of the distribution, i.e. P(X <= x). + /// + /// The location at which to compute the cumulative distribution function. + /// the cumulative distribution at location . + public double CumulativeDistribution(double x) + { + return ((1.0/Constants.Pi)*Math.Atan((x - Median)/_scale)) + 0.5; + } /// /// Samples the distribution. @@ -269,7 +262,7 @@ namespace MathNet.Numerics.Distributions /// The location shape parameter. /// The scale parameter. /// a random number from the distribution. - internal static double SampleUnchecked(Random rnd, double location, double scale) + internal static double SampleUnchecked(System.Random rnd, double location, double scale) { var u = rnd.NextDouble(); return location + (scale*Math.Tan(Constants.Pi*(u - 0.5))); @@ -303,7 +296,7 @@ namespace MathNet.Numerics.Distributions /// The location shape parameter. /// The scale parameter. /// a sample from the distribution. - public static double Sample(Random rnd, double location, double scale) + public static double Sample(System.Random rnd, double location, double scale) { if (Control.CheckDistributionParameters && !IsValidParameterSet(location, scale)) { @@ -320,7 +313,7 @@ namespace MathNet.Numerics.Distributions /// The location shape parameter. /// The scale parameter. /// a sequence of samples from the distribution. - public static IEnumerable Samples(Random rnd, double location, double scale) + public static IEnumerable Samples(System.Random rnd, double location, double scale) { if (Control.CheckDistributionParameters && !IsValidParameterSet(location, scale)) { diff --git a/src/Numerics/Distributions/Continuous/Chi.cs b/src/Numerics/Distributions/Chi.cs similarity index 90% rename from src/Numerics/Distributions/Continuous/Chi.cs rename to src/Numerics/Distributions/Chi.cs index 0a915c06..676a2a77 100644 --- a/src/Numerics/Distributions/Continuous/Chi.cs +++ b/src/Numerics/Distributions/Chi.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-2013 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 @@ -24,15 +28,15 @@ // OTHER DEALINGS IN THE SOFTWARE. // +using System; +using System.Collections.Generic; +using MathNet.Numerics.Properties; + namespace MathNet.Numerics.Distributions { - using System; - using System.Collections.Generic; - using Properties; - /// - /// This class implements functionality for the Chi distribution. This distribution is - /// a continuous probability distribution. The distribution usually arises when a k-dimensional vector's orthogonal + /// Continuous Univariate Chi distribution. + /// This distribution is a continuous probability distribution. The distribution usually arises when a k-dimensional vector's orthogonal /// components are independent and each follow a standard normal distribution. The length of the vector will /// then have a chi distribution. /// Wikipedia - Chi distribution. @@ -52,7 +56,7 @@ namespace MathNet.Numerics.Distributions /// /// The distribution's random number generator. /// - Random _random; + System.Random _random; /// /// Initializes a new instance of the class. @@ -60,7 +64,7 @@ namespace MathNet.Numerics.Distributions /// The degrees of freedom for the Chi distribution. public Chi(double dof) { - _random = new Random(); + _random = new System.Random(); SetParameters(dof); } @@ -69,9 +73,9 @@ namespace MathNet.Numerics.Distributions /// /// 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) + public Chi(double dof, System.Random randomSource) { - _random = randomSource ?? new Random(); + _random = randomSource ?? new System.Random(); SetParameters(dof); } @@ -118,12 +122,10 @@ namespace MathNet.Numerics.Distributions return "Chi(DoF = " + _dof + ")"; } - #region IDistribution Members - /// /// Gets or sets the distribution's random number generator. /// - public Random RandomSource + public System.Random RandomSource { get { return _random; } set @@ -181,20 +183,6 @@ namespace MathNet.Numerics.Distributions } } - /// - /// Computes the cumulative distribution function of the distribution. - /// - /// The location at which to compute the cumulative density. - /// the cumulative density at . - public double CumulativeDistribution(double x) - { - return SpecialFunctions.GammaLowerIncomplete(_dof/2.0, x*x/2.0)/SpecialFunctions.Gamma(_dof/2.0); - } - - #endregion - - #region IContinuousDistribution Members - /// /// Gets the mode of the distribution. /// @@ -236,7 +224,7 @@ namespace MathNet.Numerics.Distributions } /// - /// Computes the density of the distribution. + /// Computes the density of the distribution (PDF), i.e. dP(X <= x)/dx. /// /// The location at which to compute the density. /// the density at . @@ -246,7 +234,7 @@ namespace MathNet.Numerics.Distributions } /// - /// Computes the log density of the distribution. + /// Computes the log density of the distribution (lnPDF), i.e. ln(dP(X <= x)/dx). /// /// The location at which to compute the log density. /// the log density at . @@ -255,7 +243,15 @@ namespace MathNet.Numerics.Distributions return ((1.0 - (_dof/2.0))*Math.Log(2.0)) + ((_dof - 1.0)*Math.Log(x)) - (x*x/2.0) - SpecialFunctions.GammaLn(_dof/2.0); } - #endregion + /// + /// Computes the cumulative distribution (CDF) of the distribution, i.e. P(X <= x). + /// + /// The location at which to compute the cumulative distribution function. + /// the cumulative distribution at location . + public double CumulativeDistribution(double x) + { + return SpecialFunctions.GammaLowerIncomplete(_dof/2.0, x*x/2.0)/SpecialFunctions.Gamma(_dof/2.0); + } /// /// Samples the distribution. @@ -263,7 +259,7 @@ namespace MathNet.Numerics.Distributions /// The random number generator to use. /// Degrees of Freedom /// a random number from the distribution. - internal static double SampleUnchecked(Random rnd, int dof) + internal static double SampleUnchecked(System.Random rnd, int dof) { double sum = 0; for (var i = 0; i < dof; i++) @@ -302,7 +298,7 @@ namespace MathNet.Numerics.Distributions /// The random number generator to use. /// Degrees of Freedom /// a sample from the distribution. - public static double Sample(Random rnd, int dof) + public static double Sample(System.Random rnd, int dof) { if (Control.CheckDistributionParameters && !IsValidParameterSet(dof)) { @@ -318,7 +314,7 @@ namespace MathNet.Numerics.Distributions /// The random number generator to use. /// Degrees of Freedom /// a sequence of samples from the distribution. - public static IEnumerable Samples(Random rnd, int dof) + public static IEnumerable Samples(System.Random rnd, int dof) { if (Control.CheckDistributionParameters && !IsValidParameterSet(dof)) { diff --git a/src/Numerics/Distributions/Continuous/ChiSquare.cs b/src/Numerics/Distributions/ChiSquare.cs similarity index 90% rename from src/Numerics/Distributions/Continuous/ChiSquare.cs rename to src/Numerics/Distributions/ChiSquare.cs index 5cd2f70a..560867dc 100644 --- a/src/Numerics/Distributions/Continuous/ChiSquare.cs +++ b/src/Numerics/Distributions/ChiSquare.cs @@ -4,7 +4,7 @@ // http://github.com/mathnet/mathnet-numerics // http://mathnetnumerics.codeplex.com // -// Copyright (c) 2009-2010 Math.NET +// Copyright (c) 2009-2013 Math.NET // // Permission is hereby granted, free of charge, to any person // obtaining a copy of this software and associated documentation @@ -28,15 +28,15 @@ // OTHER DEALINGS IN THE SOFTWARE. // +using System; +using System.Collections.Generic; +using MathNet.Numerics.Properties; + namespace MathNet.Numerics.Distributions { - using System; - using System.Collections.Generic; - using Properties; - /// - /// This class implements functionality for the ChiSquare distribution. This distribution is - /// a sum of the squares of k independent standard normal random variables. + /// Continuous Univariate ChiSquare distribution. + /// This distribution is a sum of the squares of k independent standard normal random variables. /// Wikipedia - ChiSquare distribution. /// /// The distribution will use the by default. @@ -49,7 +49,7 @@ namespace MathNet.Numerics.Distributions /// /// The distribution's random number generator. /// - Random _random; + System.Random _random; /// /// Initializes a new instance of the class. @@ -57,7 +57,7 @@ namespace MathNet.Numerics.Distributions /// The degrees of freedom for the ChiSquare distribution. public ChiSquare(double dof) { - _random = new Random(); + _random = new System.Random(); SetParameters(dof); } @@ -66,9 +66,9 @@ namespace MathNet.Numerics.Distributions /// /// 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) + public ChiSquare(double dof, System.Random randomSource) { - _random = randomSource ?? new Random(); + _random = randomSource ?? new System.Random(); SetParameters(dof); } @@ -115,12 +115,10 @@ namespace MathNet.Numerics.Distributions return "ChiSquare(DoF = " + Mean + ")"; } - #region IDistribution Members - /// /// Gets or sets the distribution's random number generator. /// - public Random RandomSource + public System.Random RandomSource { get { return _random; } set @@ -171,20 +169,6 @@ namespace MathNet.Numerics.Distributions get { return Math.Sqrt(8.0/Mean); } } - /// - /// Computes the cumulative distribution function of the distribution. - /// - /// The location at which to compute the cumulative density. - /// the cumulative density at . - public double CumulativeDistribution(double x) - { - return SpecialFunctions.GammaLowerIncomplete(Mean/2.0, x/2.0)/SpecialFunctions.Gamma(Mean/2.0); - } - - #endregion - - #region IContinuousDistribution Members - /// /// Gets the mode of the distribution. /// @@ -218,7 +202,7 @@ namespace MathNet.Numerics.Distributions } /// - /// Computes the density of the distribution. + /// Computes the density of the distribution (PDF), i.e. dP(X <= x)/dx. /// /// The location at which to compute the density. /// the density at . @@ -228,7 +212,7 @@ namespace MathNet.Numerics.Distributions } /// - /// Computes the log density of the distribution. + /// Computes the log density of the distribution (lnPDF), i.e. ln(dP(X <= x)/dx). /// /// The location at which to compute the log density. /// the log density at . @@ -237,7 +221,15 @@ namespace MathNet.Numerics.Distributions return (-x/2.0) + (((Mean/2.0) - 1.0)*Math.Log(x)) - ((Mean/2.0)*Math.Log(2)) - SpecialFunctions.GammaLn(Mean/2.0); } - #endregion + /// + /// Computes the cumulative distribution (CDF) of the distribution, i.e. P(X <= x). + /// + /// The location at which to compute the cumulative distribution function. + /// the cumulative distribution at location . + public double CumulativeDistribution(double x) + { + return SpecialFunctions.GammaLowerIncomplete(Mean/2.0, x/2.0)/SpecialFunctions.Gamma(Mean/2.0); + } /// /// Samples the distribution. @@ -245,7 +237,7 @@ namespace MathNet.Numerics.Distributions /// The random number generator to use. /// The degrees of freedom. /// a random number from the distribution. - internal static double SampleUnchecked(Random rnd, double dof) + internal static double SampleUnchecked(System.Random rnd, double dof) { //Use the simple method if the dof is an integer anyway if (Math.Floor(dof) == dof && dof < Int32.MaxValue) @@ -290,7 +282,7 @@ namespace MathNet.Numerics.Distributions /// The random number generator to use. /// The degrees of freedom. /// a sample from the distribution. - public static double Sample(Random rnd, double dof) + public static double Sample(System.Random rnd, double dof) { if (Control.CheckDistributionParameters && !IsValidParameterSet(dof)) { @@ -306,7 +298,7 @@ namespace MathNet.Numerics.Distributions /// The random number generator to use. /// The degrees of freedom. /// a sample from the distribution. - public static IEnumerable Samples(Random rnd, double dof) + public static IEnumerable Samples(System.Random rnd, double dof) { if (Control.CheckDistributionParameters && !IsValidParameterSet(dof)) { diff --git a/src/Numerics/Distributions/Continuous/ContinuousUniform.cs b/src/Numerics/Distributions/ContinuousUniform.cs similarity index 91% rename from src/Numerics/Distributions/Continuous/ContinuousUniform.cs rename to src/Numerics/Distributions/ContinuousUniform.cs index b5048a33..7f3285d6 100644 --- a/src/Numerics/Distributions/Continuous/ContinuousUniform.cs +++ b/src/Numerics/Distributions/ContinuousUniform.cs @@ -4,7 +4,7 @@ // http://github.com/mathnet/mathnet-numerics // http://mathnetnumerics.codeplex.com // -// Copyright (c) 2009-2010 Math.NET +// Copyright (c) 2009-2013 Math.NET // // Permission is hereby granted, free of charge, to any person // obtaining a copy of this software and associated documentation @@ -28,13 +28,14 @@ // OTHER DEALINGS IN THE SOFTWARE. // +using System; +using System.Collections.Generic; +using MathNet.Numerics.Properties; + namespace MathNet.Numerics.Distributions { - using System; - using System.Collections.Generic; - using Properties; - /// + /// Continuous Univariate Uniform distribution. /// The continuous uniform distribution is a distribution over real numbers. For details about this distribution, see /// Wikipedia - Continuous uniform distribution. /// @@ -58,7 +59,7 @@ namespace MathNet.Numerics.Distributions /// /// The distribution's random number generator. /// - Random _random; + System.Random _random; /// /// Initializes a new instance of the ContinuousUniform class with lower bound 0 and upper bound 1. @@ -75,7 +76,7 @@ namespace MathNet.Numerics.Distributions /// If the upper bound is smaller than the lower bound. public ContinuousUniform(double lower, double upper) { - _random = new Random(); + _random = new System.Random(); SetParameters(lower, upper); } @@ -86,9 +87,9 @@ namespace MathNet.Numerics.Distributions /// 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) + public ContinuousUniform(double lower, double upper, System.Random randomSource) { - _random = randomSource ?? new Random(); + _random = randomSource ?? new System.Random(); SetParameters(lower, upper); } @@ -147,12 +148,10 @@ namespace MathNet.Numerics.Distributions set { SetParameters(_lower, value); } } - #region IDistribution Members - /// /// Gets or sets the random number generator which is used to draw random samples. /// - public Random RandomSource + public System.Random RandomSource { get { return _random; } set @@ -207,10 +206,6 @@ namespace MathNet.Numerics.Distributions get { return 0.0; } } - #endregion - - #region IContinuousDistribution Members - /// /// Gets the mode of the distribution. /// @@ -246,7 +241,7 @@ namespace MathNet.Numerics.Distributions } /// - /// Computes the density of the distribution. + /// Computes the density of the distribution (PDF), i.e. dP(X <= x)/dx. /// /// The location at which to compute the density. /// the density at . @@ -261,7 +256,7 @@ namespace MathNet.Numerics.Distributions } /// - /// Computes the log density of the distribution. + /// Computes the log density of the distribution (lnPDF), i.e. ln(dP(X <= x)/dx). /// /// The location at which to compute the log density. /// the log density at . @@ -276,10 +271,10 @@ namespace MathNet.Numerics.Distributions } /// - /// Computes the cumulative distribution function of the distribution. + /// Computes the cumulative distribution (CDF) of the distribution, i.e. P(X <= x). /// - /// The location at which to compute the cumulative density. - /// the cumulative density at . + /// The location at which to compute the cumulative distribution function. + /// the cumulative distribution at location . public double CumulativeDistribution(double x) { if (x <= _lower) @@ -295,8 +290,6 @@ namespace MathNet.Numerics.Distributions return (x - _lower)/(_upper - _lower); } - #endregion - /// /// Generates one sample from the ContinuousUniform distribution without parameter checking. /// @@ -304,7 +297,7 @@ namespace MathNet.Numerics.Distributions /// The lower bound of the uniform random variable. /// The upper bound of the uniform random variable. /// a uniformly distributed random number. - internal static double SampleUnchecked(Random rnd, double lower, double upper) + internal static double SampleUnchecked(System.Random rnd, double lower, double upper) { return lower + (rnd.NextDouble()*(upper - lower)); } @@ -337,7 +330,7 @@ namespace MathNet.Numerics.Distributions /// The lower bound of the uniform random variable. /// The upper bound of the uniform random variable. /// a uniformly distributed sample. - public static double Sample(Random rnd, double lower, double upper) + public static double Sample(System.Random rnd, double lower, double upper) { if (Control.CheckDistributionParameters && !IsValidParameterSet(lower, upper)) { @@ -354,7 +347,7 @@ namespace MathNet.Numerics.Distributions /// The lower bound of the uniform random variable. /// The upper bound of the uniform random variable. /// a sequence of uniformly distributed samples. - public static IEnumerable Samples(Random rnd, double lower, double upper) + public static IEnumerable Samples(System.Random rnd, double lower, double upper) { if (Control.CheckDistributionParameters && !IsValidParameterSet(lower, upper)) { diff --git a/src/Numerics/Distributions/Discrete/ConwayMaxwellPoisson.cs b/src/Numerics/Distributions/ConwayMaxwellPoisson.cs similarity index 93% rename from src/Numerics/Distributions/Discrete/ConwayMaxwellPoisson.cs rename to src/Numerics/Distributions/ConwayMaxwellPoisson.cs index b771b8cf..e5a9dec2 100644 --- a/src/Numerics/Distributions/Discrete/ConwayMaxwellPoisson.cs +++ b/src/Numerics/Distributions/ConwayMaxwellPoisson.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-2013 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 @@ -24,13 +28,14 @@ // OTHER DEALINGS IN THE SOFTWARE. // +using System; +using System.Collections.Generic; +using MathNet.Numerics.Properties; + namespace MathNet.Numerics.Distributions { - using System; - using System.Collections.Generic; - using Properties; - /// + /// Discrete Univariate Conway-Maxwell-Poisson distribution. /// The Conway-Maxwell-Poisson distribution is a generalization of the Poisson, Geometric and Bernoulli /// distributions. It is parameterized by two real numbers "lambda" and "nu". For /// @@ -82,7 +87,7 @@ namespace MathNet.Numerics.Distributions /// /// The distribution's random number generator. /// - Random _random; + System.Random _random; /// /// Initializes a new instance of the class. @@ -91,7 +96,7 @@ namespace MathNet.Numerics.Distributions /// The nu parameter. public ConwayMaxwellPoisson(double lambda, double nu) { - _random = new Random(); + _random = new System.Random(); SetParameters(lambda, nu); } @@ -101,9 +106,9 @@ namespace MathNet.Numerics.Distributions /// 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) + public ConwayMaxwellPoisson(double lambda, double nu, System.Random randomSource) { - _random = randomSource ?? new Random(); + _random = randomSource ?? new System.Random(); SetParameters(lambda, nu); } @@ -166,12 +171,10 @@ namespace MathNet.Numerics.Distributions return "ConwayMaxwellPoisson(Lambda = " + _lambda + ", Nu = " + _nu + ")"; } - #region IDistribution Members - /// /// Gets or sets the random number generator which is used to draw random samples. /// - public Random RandomSource + public System.Random RandomSource { get { return _random; } set @@ -332,26 +335,6 @@ namespace MathNet.Numerics.Distributions get { throw new NotSupportedException(); } } - /// - /// Computes the cumulative distribution function of the ConwayMaxwellPoisson distribution. - /// - /// The location at which to compute the cumulative density. - /// the cumulative density at . - public double CumulativeDistribution(double x) - { - double sum = 0; - for (var i = 0; i < x + 1; i++) - { - sum += Probability(i); - } - - return sum; - } - - #endregion - - #region IDiscreteDistribution Members - /// /// Gets the mode of the distribution /// @@ -385,30 +368,40 @@ namespace MathNet.Numerics.Distributions } /// - /// Computes the probability of a specific value. + /// Computes the probability mass (PMF), i.e. P(X = x). /// /// The location in the domain where we want to evaluate the probability mass function. - /// - /// the probability mass at location . - /// + /// the probability mass at location . public double Probability(int k) { return Math.Pow(_lambda, k)/Math.Pow(SpecialFunctions.Factorial(k), _nu)/Z; } /// - /// Computes the log probability of a specific value. + /// Computes the log probability mass (lnPMF), i.e. ln(P(X = x)). /// /// The location in the domain where we want to evaluate the log probability mass function. - /// - /// the log probability mass at location . - /// + /// the log probability mass at location . public double ProbabilityLn(int k) { return Math.Log(Probability(k)); } - #endregion + /// + /// Computes the cumulative distribution (CDF) of the distribution, i.e. P(X <= x). + /// + /// The location at which to compute the cumulative distribution function. + /// the cumulative distribution at location . + public double CumulativeDistribution(double x) + { + double sum = 0; + for (var i = 0; i < x + 1; i++) + { + sum += Probability(i); + } + + return sum; + } /// /// Gets the normalization constant of the Conway-Maxwell-Poisson distribution. @@ -478,7 +471,7 @@ namespace MathNet.Numerics.Distributions /// /// One sample from the distribution implied by , , and . /// - internal static int SampleUnchecked(Random rnd, double lambda, double nu, double z) + internal static int SampleUnchecked(System.Random rnd, double lambda, double nu, double z) { var u = rnd.NextDouble(); var p = 1.0/z; @@ -524,7 +517,7 @@ namespace MathNet.Numerics.Distributions /// The random number generator to use. /// The lambda parameter /// The nu parameter. - public static int Sample(Random rnd, double lambda, double nu) + public static int Sample(System.Random rnd, double lambda, double nu) { if (Control.CheckDistributionParameters && !IsValidParameterSet(lambda, nu)) { @@ -541,7 +534,7 @@ namespace MathNet.Numerics.Distributions /// The random number generator to use. /// The lambda parameter /// The nu parameter. - public static IEnumerable Samples(Random rnd, double lambda, double nu) + public static IEnumerable Samples(System.Random rnd, double lambda, double nu) { if (Control.CheckDistributionParameters && !IsValidParameterSet(lambda, nu)) { diff --git a/src/Numerics/Distributions/Multivariate/Dirichlet.cs b/src/Numerics/Distributions/Dirichlet.cs similarity index 95% rename from src/Numerics/Distributions/Multivariate/Dirichlet.cs rename to src/Numerics/Distributions/Dirichlet.cs index fb730b9c..19cbefed 100644 --- a/src/Numerics/Distributions/Multivariate/Dirichlet.cs +++ b/src/Numerics/Distributions/Dirichlet.cs @@ -28,14 +28,14 @@ // OTHER DEALINGS IN THE SOFTWARE. // +using System; +using System.Linq; +using MathNet.Numerics.Properties; + namespace MathNet.Numerics.Distributions { - using System; - using System.Linq; - using Properties; - /// - /// Implements the multivariate Dirichlet distribution. For details about this distribution, see + /// Multivariate Dirichlet distribution. For details about this distribution, see /// Wikipedia - Dirichlet distribution. /// /// The distribution will use the by default. @@ -53,7 +53,7 @@ namespace MathNet.Numerics.Distributions /// /// The distribution's random number generator. /// - Random _random; + System.Random _random; /// /// Initializes a new instance of the Dirichlet class. The distribution will @@ -62,7 +62,7 @@ namespace MathNet.Numerics.Distributions /// An array with the Dirichlet parameters. public Dirichlet(double[] alpha) { - _random = new Random(); + _random = new System.Random(); SetParameters(alpha); } @@ -72,9 +72,9 @@ namespace MathNet.Numerics.Distributions /// /// An array with the Dirichlet parameters. /// The random number generator which is used to draw random samples. - public Dirichlet(double[] alpha, Random randomSource) + public Dirichlet(double[] alpha, System.Random randomSource) { - _random = randomSource ?? new Random(); + _random = randomSource ?? new System.Random(); SetParameters(alpha); } @@ -92,7 +92,7 @@ namespace MathNet.Numerics.Distributions parm[i] = alpha; } - _random = new Random(); + _random = new System.Random(); SetParameters(parm); } @@ -102,7 +102,7 @@ namespace MathNet.Numerics.Distributions /// 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) + public Dirichlet(double alpha, int k, System.Random randomSource) { // Create a parameter structure. var parm = new double[k]; @@ -111,7 +111,7 @@ namespace MathNet.Numerics.Distributions parm[i] = alpha; } - _random = randomSource ?? new Random(); + _random = randomSource ?? new System.Random(); SetParameters(parm); } @@ -311,7 +311,7 @@ namespace MathNet.Numerics.Distributions /// /// Gets or sets the random number generator which is used to draw random samples. /// - public Random RandomSource + public System.Random RandomSource { get { return _random; } set @@ -340,7 +340,7 @@ namespace MathNet.Numerics.Distributions /// The random number generator to use. /// The Dirichlet distribution parameter. /// a sample from the distribution. - public static double[] Sample(Random rnd, double[] alpha) + public static double[] Sample(System.Random rnd, double[] alpha) { if (Control.CheckDistributionParameters && !IsValidParameterSet(alpha)) { diff --git a/src/Numerics/Distributions/Discrete/DiscreteUniform.cs b/src/Numerics/Distributions/DiscreteUniform.cs similarity index 90% rename from src/Numerics/Distributions/Discrete/DiscreteUniform.cs rename to src/Numerics/Distributions/DiscreteUniform.cs index 74f4f5d8..b66b1926 100644 --- a/src/Numerics/Distributions/Discrete/DiscreteUniform.cs +++ b/src/Numerics/Distributions/DiscreteUniform.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-2013 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 @@ -24,13 +28,14 @@ // OTHER DEALINGS IN THE SOFTWARE. // +using System; +using System.Collections.Generic; +using MathNet.Numerics.Properties; + namespace MathNet.Numerics.Distributions { - using System; - using System.Collections.Generic; - using Properties; - /// + /// Discrete Univariate Uniform distribution. /// The discrete uniform distribution is a distribution over integers. The distribution /// is parameterized by a lower and upper bound (both inclusive). /// Wikipedia - Discrete uniform distribution. @@ -55,7 +60,7 @@ namespace MathNet.Numerics.Distributions /// /// The distribution's random number generator. /// - Random _random; + System.Random _random; /// /// Initializes a new instance of the DiscreteUniform class. @@ -64,7 +69,7 @@ namespace MathNet.Numerics.Distributions /// Upper bound; must be at least as large as . public DiscreteUniform(int lower, int upper) { - _random = new Random(); + _random = new System.Random(); SetParameters(lower, upper); } @@ -74,9 +79,9 @@ namespace MathNet.Numerics.Distributions /// 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) + public DiscreteUniform(int lower, int upper, System.Random randomSource) { - _random = randomSource ?? new Random(); + _random = randomSource ?? new System.Random(); SetParameters(lower, upper); } @@ -137,12 +142,10 @@ namespace MathNet.Numerics.Distributions set { SetParameters(_lower, value); } } - #region IDistribution Members - /// /// Gets or sets the random number generator which is used to draw random samples. /// - public Random RandomSource + public System.Random RandomSource { get { return _random; } set @@ -212,30 +215,6 @@ namespace MathNet.Numerics.Distributions get { return _upper; } } - /// - /// Computes the cumulative distribution function of the Bernoulli distribution. - /// - /// The location at which to compute the cumulative density. - /// the cumulative density at . - public double CumulativeDistribution(double x) - { - if (x < _lower) - { - return 0.0; - } - - if (x >= _upper) - { - return 1.0; - } - - return Math.Min(1.0, (Math.Floor(x) - _lower + 1)/(_upper - _lower + 1)); - } - - #endregion - - #region IDiscreteDistribution Members - /// /// Gets the mode of the distribution; since every element in the domain has the same probability this method returns the middle one. /// @@ -253,12 +232,10 @@ namespace MathNet.Numerics.Distributions } /// - /// Computes values of the probability mass function. + /// Computes the probability mass (PMF), i.e. P(X = x). /// /// The location in the domain where we want to evaluate the probability mass function. - /// - /// the probability mass at location . - /// + /// the probability mass at location . public double Probability(int k) { if (k >= _lower && k <= _upper) @@ -270,12 +247,10 @@ namespace MathNet.Numerics.Distributions } /// - /// Computes the probability of a specific value. + /// Computes the log probability mass (lnPMF), i.e. ln(P(X = x)). /// /// The location in the domain where we want to evaluate the log probability mass function. - /// - /// the log probability mass at location . - /// + /// the log probability mass at location . public double ProbabilityLn(int k) { if (k >= _lower && k <= _upper) @@ -286,7 +261,25 @@ namespace MathNet.Numerics.Distributions return Double.NegativeInfinity; } - #endregion + /// + /// Computes the cumulative distribution (CDF) of the distribution, i.e. P(X <= x). + /// + /// The location at which to compute the cumulative distribution function. + /// the cumulative distribution at location . + public double CumulativeDistribution(double x) + { + if (x < _lower) + { + return 0.0; + } + + if (x >= _upper) + { + return 1.0; + } + + return Math.Min(1.0, (Math.Floor(x) - _lower + 1)/(_upper - _lower + 1)); + } /// /// Generates one sample from the discrete uniform distribution. This method does not do any parameter checking. @@ -295,7 +288,7 @@ namespace MathNet.Numerics.Distributions /// The lower bound of the uniform random variable. /// The upper bound of the uniform random variable. /// A random sample from the discrete uniform distribution. - internal static int SampleUnchecked(Random rnd, int lower, int upper) + internal static int SampleUnchecked(System.Random rnd, int lower, int upper) { return (rnd.Next()%(upper - lower + 1)) + lower; } @@ -328,7 +321,7 @@ namespace MathNet.Numerics.Distributions /// The lower bound of the uniform random variable. /// The upper bound of the uniform random variable. /// A sample from the discrete uniform distribution. - public static int Sample(Random rnd, int lower, int upper) + public static int Sample(System.Random rnd, int lower, int upper) { if (Control.CheckDistributionParameters && !IsValidParameterSet(lower, upper)) { @@ -345,7 +338,7 @@ namespace MathNet.Numerics.Distributions /// The lower bound of the uniform random variable. /// The upper bound of the uniform random variable. /// a sequence of samples from the discrete uniform distribution. - public static IEnumerable Samples(Random rnd, int lower, int upper) + public static IEnumerable Samples(System.Random rnd, int lower, int upper) { if (Control.CheckDistributionParameters && !IsValidParameterSet(lower, upper)) { diff --git a/src/Numerics/Distributions/Continuous/Erlang.cs b/src/Numerics/Distributions/Erlang.cs similarity index 92% rename from src/Numerics/Distributions/Continuous/Erlang.cs rename to src/Numerics/Distributions/Erlang.cs index 73b38b90..074d1b31 100644 --- a/src/Numerics/Distributions/Continuous/Erlang.cs +++ b/src/Numerics/Distributions/Erlang.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-2013 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 @@ -24,15 +28,15 @@ // OTHER DEALINGS IN THE SOFTWARE. // +using System; +using System.Collections.Generic; +using MathNet.Numerics.Properties; + namespace MathNet.Numerics.Distributions { - using System; - using System.Collections.Generic; - using Properties; - /// - /// This class implements functionality for the Erlang distribution. This distribution is - /// is a continuous probability distribution with wide applicability primarily due to its + /// Continuous Univariate Erlang distribution. + /// This distribution is is a continuous probability distribution with wide applicability primarily due to its /// relation to the exponential and Gamma distributions. /// Wikipedia - Erlang distribution. /// @@ -56,7 +60,7 @@ namespace MathNet.Numerics.Distributions /// /// The distribution's random number generator. /// - Random _random; + System.Random _random; /// /// Initializes a new instance of the class. @@ -65,7 +69,7 @@ namespace MathNet.Numerics.Distributions /// The inverse scale of the Erlang distribution. public Erlang(int shape, double invScale) { - _random = new Random(); + _random = new System.Random(); SetParameters(shape, invScale); } @@ -75,9 +79,9 @@ namespace MathNet.Numerics.Distributions /// 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) + public Erlang(int shape, double invScale, System.Random randomSource) { - _random = randomSource ?? new Random(); + _random = randomSource ?? new System.Random(); SetParameters(shape, invScale); } @@ -178,12 +182,10 @@ namespace MathNet.Numerics.Distributions return "Erlang(Shape = " + _shape + ", Inverse Scale = " + _invScale + ")"; } - #region IDistribution Members - /// /// Gets or sets the random number generator which is used to draw random samples. /// - public Random RandomSource + public System.Random RandomSource { get { return _random; } set @@ -302,30 +304,6 @@ namespace MathNet.Numerics.Distributions } } - /// - /// Computes the cumulative distribution function of the Erlang distribution. - /// - /// The location at which to compute the cumulative density. - /// the cumulative density at . - public double CumulativeDistribution(double x) - { - if (Double.IsPositiveInfinity(_invScale)) - { - return x >= _shape ? 1.0 : 0.0; - } - - if (_shape == 0.0 && _invScale == 0.0) - { - return 0.0; - } - - return SpecialFunctions.GammaLowerRegularized(_shape, x*_invScale); - } - - #endregion - - #region IContinuousDistribution Members - /// /// Gets the mode of the distribution. /// @@ -377,7 +355,7 @@ namespace MathNet.Numerics.Distributions } /// - /// Computes the density of the distribution. + /// Computes the density of the distribution (PDF), i.e. dP(X <= x)/dx. /// /// The location at which to compute the density. /// the density at . @@ -402,10 +380,10 @@ namespace MathNet.Numerics.Distributions } /// - /// Computes the log density of the distribution. + /// Computes the log density of the distribution (lnPDF), i.e. ln(dP(X <= x)/dx). /// - /// The location at which to compute the density. - /// the density at . + /// The location at which to compute the log density. + /// the log density at . public double DensityLn(double x) { if (Double.IsPositiveInfinity(_invScale)) @@ -426,7 +404,25 @@ namespace MathNet.Numerics.Distributions return (_shape*Math.Log(_invScale)) + ((_shape - 1.0)*Math.Log(x)) - (_invScale*x) - SpecialFunctions.GammaLn(_shape); } - #endregion + /// + /// Computes the cumulative distribution (CDF) of the distribution, i.e. P(X <= x). + /// + /// The location at which to compute the cumulative distribution function. + /// the cumulative distribution at location . + public double CumulativeDistribution(double x) + { + if (Double.IsPositiveInfinity(_invScale)) + { + return x >= _shape ? 1.0 : 0.0; + } + + if (_shape == 0.0 && _invScale == 0.0) + { + return 0.0; + } + + return SpecialFunctions.GammaLowerRegularized(_shape, x*_invScale); + } /// /// Sampling implementation based on: @@ -438,7 +434,7 @@ namespace MathNet.Numerics.Distributions /// The shape of the Gamma distribution. /// The inverse scale of the Gamma distribution. /// A sample from a Erlang distributed random variable. - internal static double SampleUnchecked(Random rnd, double shape, double invScale) + internal static double SampleUnchecked(System.Random rnd, double shape, double invScale) { if (Double.IsPositiveInfinity(invScale)) { @@ -510,7 +506,7 @@ namespace MathNet.Numerics.Distributions /// The shape of the Gamma distribution. /// The inverse scale of the Gamma distribution. /// a sample from the distribution. - public static double Sample(Random rnd, double shape, double invScale) + public static double Sample(System.Random rnd, double shape, double invScale) { if (Control.CheckDistributionParameters && !IsValidParameterSet(shape, invScale)) { @@ -527,7 +523,7 @@ namespace MathNet.Numerics.Distributions /// The shape of the Gamma distribution. /// The inverse scale of the Gamma distribution. /// a sequence of samples from the distribution. - public static IEnumerable Samples(Random rnd, double shape, double invScale) + public static IEnumerable Samples(System.Random rnd, double shape, double invScale) { if (Control.CheckDistributionParameters && !IsValidParameterSet(shape, invScale)) { diff --git a/src/Numerics/Distributions/Continuous/Exponential.cs b/src/Numerics/Distributions/Exponential.cs similarity index 90% rename from src/Numerics/Distributions/Continuous/Exponential.cs rename to src/Numerics/Distributions/Exponential.cs index b95017d1..5b5bbf6a 100644 --- a/src/Numerics/Distributions/Continuous/Exponential.cs +++ b/src/Numerics/Distributions/Exponential.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-2013 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 @@ -24,13 +28,14 @@ // OTHER DEALINGS IN THE SOFTWARE. // +using System; +using System.Collections.Generic; +using MathNet.Numerics.Properties; + namespace MathNet.Numerics.Distributions { - using System; - using System.Collections.Generic; - using Properties; - /// + /// Continuous Univariate Exponential distribution. /// The exponential distribution is a distribution over the real numbers parameterized by one non-negative parameter. /// Wikipedia - exponential distribution. /// @@ -49,7 +54,7 @@ namespace MathNet.Numerics.Distributions /// /// The distribution's random number generator. /// - Random _random; + System.Random _random; /// /// Initializes a new instance of the class. @@ -57,7 +62,7 @@ namespace MathNet.Numerics.Distributions /// The lambda parameter of the Exponential distribution. public Exponential(double lambda) { - _random = new Random(); + _random = new System.Random(); SetParameters(lambda); } @@ -66,9 +71,9 @@ namespace MathNet.Numerics.Distributions /// /// The lambda parameter of the Exponential distribution. /// The random number generator which is used to draw random samples. - public Exponential(double lambda, Random randomSource) + public Exponential(double lambda, System.Random randomSource) { - _random = randomSource ?? new Random(); + _random = randomSource ?? new System.Random(); SetParameters(lambda); } @@ -115,12 +120,10 @@ namespace MathNet.Numerics.Distributions return "Exponential(Lambda = " + _lambda + ")"; } - #region IDistribution Members - /// /// Gets or sets the random number generator which is used to draw random samples. /// - public Random RandomSource + public System.Random RandomSource { get { return _random; } set @@ -174,25 +177,6 @@ namespace MathNet.Numerics.Distributions get { return 2.0; } } - /// - /// Computes the cumulative distribution function of the distribution. - /// - /// The location at which to compute the cumulative density. - /// the cumulative density at . - public double CumulativeDistribution(double x) - { - if (x >= 0.0) - { - return 1.0 - Math.Exp(-_lambda*x); - } - - return 0.0; - } - - #endregion - - #region IContinuousDistribution Members - /// /// Gets the mode of the distribution. /// @@ -226,7 +210,7 @@ namespace MathNet.Numerics.Distributions } /// - /// Computes the density of the distribution. + /// Computes the density of the distribution (PDF), i.e. dP(X <= x)/dx. /// /// The location at which to compute the density. /// the density at . @@ -241,7 +225,7 @@ namespace MathNet.Numerics.Distributions } /// - /// Computes the log density of the distribution. + /// Computes the log density of the distribution (lnPDF), i.e. ln(dP(X <= x)/dx). /// /// The location at which to compute the log density. /// the log density at . @@ -250,7 +234,20 @@ namespace MathNet.Numerics.Distributions return Math.Log(_lambda) - (_lambda*x); } - #endregion + /// + /// Computes the cumulative distribution (CDF) of the distribution, i.e. P(X <= x). + /// + /// The location at which to compute the cumulative distribution function. + /// the cumulative distribution at location . + public double CumulativeDistribution(double x) + { + if (x >= 0.0) + { + return 1.0 - Math.Exp(-_lambda*x); + } + + return 0.0; + } /// /// Samples the distribution. @@ -258,7 +255,7 @@ namespace MathNet.Numerics.Distributions /// The random number generator to use. /// The lambda parameter of the Exponential distribution. /// a random number from the distribution. - internal static double SampleUnchecked(Random rnd, double lambda) + internal static double SampleUnchecked(System.Random rnd, double lambda) { var r = rnd.NextDouble(); while (r == 0.0) @@ -296,7 +293,7 @@ namespace MathNet.Numerics.Distributions /// The random number generator to use. /// The lambda parameter of the Exponential distribution. /// A random number from this distribution. - public static double Sample(Random rnd, double lambda) + public static double Sample(System.Random rnd, double lambda) { if (Control.CheckDistributionParameters && !IsValidParameterSet(lambda)) { @@ -312,7 +309,7 @@ namespace MathNet.Numerics.Distributions /// The random number generator to use. /// The lambda parameter of the Exponential distribution. /// a sequence of samples from the distribution. - public static IEnumerable Samples(Random rnd, double lambda) + public static IEnumerable Samples(System.Random rnd, double lambda) { if (Control.CheckDistributionParameters && !IsValidParameterSet(lambda)) { diff --git a/src/Numerics/Distributions/Continuous/FisherSnedecor.cs b/src/Numerics/Distributions/FisherSnedecor.cs similarity index 91% rename from src/Numerics/Distributions/Continuous/FisherSnedecor.cs rename to src/Numerics/Distributions/FisherSnedecor.cs index d1ea2039..9e7f4ee4 100644 --- a/src/Numerics/Distributions/Continuous/FisherSnedecor.cs +++ b/src/Numerics/Distributions/FisherSnedecor.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-2013 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 @@ -24,14 +28,15 @@ // OTHER DEALINGS IN THE SOFTWARE. // +using System; +using System.Collections.Generic; +using MathNet.Numerics.Properties; + namespace MathNet.Numerics.Distributions { - using System; - using System.Collections.Generic; - using Properties; - /// - /// Implements the FisherSnedecor distribution. For details about this distribution, see + /// Continuous Univariate FisherSnedecor distribution. + /// For details about this distribution, see /// Wikipedia - FisherSnedecor distribution. /// /// The distribution will use the by default. @@ -54,7 +59,7 @@ namespace MathNet.Numerics.Distributions /// /// The distribution's random number generator. /// - Random _random; + System.Random _random; /// /// Initializes a new instance of the class. @@ -63,7 +68,7 @@ namespace MathNet.Numerics.Distributions /// The second parameter - degree of freedom. public FisherSnedecor(double d1, double d2) { - _random = new Random(); + _random = new System.Random(); SetParameters(d1, d2); } @@ -73,9 +78,9 @@ namespace MathNet.Numerics.Distributions /// 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) + public FisherSnedecor(double d1, double d2, System.Random randomSource) { - _random = randomSource ?? new Random(); + _random = randomSource ?? new System.Random(); SetParameters(d1, d2); } @@ -133,12 +138,10 @@ namespace MathNet.Numerics.Distributions return "FisherSnedecor(DegreeOfFreedom1 = " + _d1 + ", DegreeOfFreedom2 = " + _d2 + ")"; } - #region IDistribution Members - /// /// Gets or sets the distribution's random number generator. /// - public Random RandomSource + public System.Random RandomSource { get { return _random; } set @@ -216,20 +219,6 @@ namespace MathNet.Numerics.Distributions } } - /// - /// Computes the cumulative distribution function of the distribution. - /// - /// The location at which to compute the cumulative density. - /// the cumulative density at . - public double CumulativeDistribution(double x) - { - return SpecialFunctions.BetaRegularized(_d1/2.0, _d2/2.0, _d1*x/((_d1*x) + _d2)); - } - - #endregion - - #region IContinuousDistribution Members - /// /// Gets the mode of the distribution. /// @@ -271,7 +260,7 @@ namespace MathNet.Numerics.Distributions } /// - /// Computes the density of the distribution. + /// Computes the density of the distribution (PDF), i.e. dP(X <= x)/dx. /// /// The location at which to compute the density. /// the density at . @@ -281,7 +270,7 @@ namespace MathNet.Numerics.Distributions } /// - /// Computes the log density of the distribution. + /// Computes the log density of the distribution (lnPDF), i.e. ln(dP(X <= x)/dx). /// /// The location at which to compute the log density. /// the log density at . @@ -290,7 +279,15 @@ namespace MathNet.Numerics.Distributions return Math.Log(Density(x)); } - #endregion + /// + /// Computes the cumulative distribution (CDF) of the distribution, i.e. P(X <= x). + /// + /// The location at which to compute the cumulative distribution function. + /// the cumulative distribution at location . + public double CumulativeDistribution(double x) + { + return SpecialFunctions.BetaRegularized(_d1/2.0, _d2/2.0, _d1*x/((_d1*x) + _d2)); + } /// /// Generates one sample from the FisherSnedecor distribution without parameter checking. @@ -299,7 +296,7 @@ namespace MathNet.Numerics.Distributions /// The first parameter - degree of freedom. /// The second parameter - degree of freedom. /// a FisherSnedecor distributed random number. - internal static double SampleUnchecked(Random rnd, double d1, double d2) + internal static double SampleUnchecked(System.Random rnd, double d1, double d2) { return (ChiSquare.Sample(rnd, d1)/d1)/(ChiSquare.Sample(rnd, d2)/d2); } @@ -332,7 +329,7 @@ namespace MathNet.Numerics.Distributions /// The first parameter - degree of freedom. /// The second parameter - degree of freedom. /// a sample from the distribution. - public static double Sample(Random rnd, double d1, double d2) + public static double Sample(System.Random rnd, double d1, double d2) { if (Control.CheckDistributionParameters && !IsValidParameterSet(d1, d2)) { @@ -349,7 +346,7 @@ namespace MathNet.Numerics.Distributions /// The first parameter - degree of freedom. /// The second parameter - degree of freedom. /// a sequence of samples from the distribution. - public static IEnumerable Samples(Random rnd, double d1, double d2) + public static IEnumerable Samples(System.Random rnd, double d1, double d2) { if (Control.CheckDistributionParameters && !IsValidParameterSet(d1, d2)) { diff --git a/src/Numerics/Distributions/Continuous/Gamma.cs b/src/Numerics/Distributions/Gamma.cs similarity index 93% rename from src/Numerics/Distributions/Continuous/Gamma.cs rename to src/Numerics/Distributions/Gamma.cs index 9dec6982..c8c944fd 100644 --- a/src/Numerics/Distributions/Continuous/Gamma.cs +++ b/src/Numerics/Distributions/Gamma.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-2013 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 @@ -24,14 +28,15 @@ // OTHER DEALINGS IN THE SOFTWARE. // +using System; +using System.Collections.Generic; +using MathNet.Numerics.Properties; + namespace MathNet.Numerics.Distributions { - using System; - using System.Collections.Generic; - using Properties; - /// - /// Implements the univariate Gamma distribution. For details about this distribution, see + /// Continuous Univariate Gamma distribution. + /// For details about this distribution, see /// Wikipedia - Gamma distribution. /// /// @@ -62,7 +67,7 @@ namespace MathNet.Numerics.Distributions /// /// The distribution's random number generator. /// - Random _random; + System.Random _random; /// /// Initializes a new instance of the Gamma class. @@ -71,7 +76,7 @@ namespace MathNet.Numerics.Distributions /// The inverse scale of the Gamma distribution. public Gamma(double shape, double invScale) { - _random = new Random(); + _random = new System.Random(); SetParameters(shape, invScale); } @@ -81,9 +86,9 @@ namespace MathNet.Numerics.Distributions /// 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) + public Gamma(double shape, double invScale, System.Random randomSource) { - _random = randomSource ?? new Random(); + _random = randomSource ?? new System.Random(); SetParameters(shape, invScale); } @@ -185,12 +190,10 @@ namespace MathNet.Numerics.Distributions set { SetParameters(_shape, value); } } - #region IDistribution implementation - /// /// Gets or sets the random number generator which is used to draw random samples. /// - public Random RandomSource + public System.Random RandomSource { get { return _random; } set @@ -309,10 +312,6 @@ namespace MathNet.Numerics.Distributions } } - #endregion - - #region IContinuousDistribution implementation - /// /// Gets the mode of the Gamma distribution. /// @@ -359,7 +358,7 @@ namespace MathNet.Numerics.Distributions } /// - /// Computes the density of the Gamma distribution. + /// Computes the density of the distribution (PDF), i.e. dP(X <= x)/dx. /// /// The location at which to compute the density. /// the density at . @@ -384,7 +383,7 @@ namespace MathNet.Numerics.Distributions } /// - /// Computes the log density of the Gamma distribution. + /// Computes the log density of the distribution (lnPDF), i.e. ln(dP(X <= x)/dx). /// /// The location at which to compute the log density. /// the log density at . @@ -409,10 +408,10 @@ namespace MathNet.Numerics.Distributions } /// - /// Computes the cumulative distribution function of the Gamma distribution. + /// Computes the cumulative distribution (CDF) of the distribution, i.e. P(X <= x). /// - /// The location at which to compute the cumulative density. - /// the cumulative density at . + /// The location at which to compute the cumulative distribution function. + /// the cumulative distribution at location . public double CumulativeDistribution(double x) { if (Double.IsPositiveInfinity(_invScale)) @@ -428,8 +427,6 @@ namespace MathNet.Numerics.Distributions return SpecialFunctions.GammaLowerRegularized(_shape, x*_invScale); } - #endregion - /// /// Sampling implementation based on: /// "A Simple Method for Generating Gamma Variables" - Marsaglia & Tsang @@ -440,7 +437,7 @@ namespace MathNet.Numerics.Distributions /// The shape of the Gamma distribution. /// The inverse scale of the Gamma distribution. /// A sample from a Gamma distributed random variable. - internal static double SampleUnchecked(Random rnd, double shape, double invScale) + internal static double SampleUnchecked(System.Random rnd, double shape, double invScale) { if (Double.IsPositiveInfinity(invScale)) { @@ -512,7 +509,7 @@ namespace MathNet.Numerics.Distributions /// The shape of the Gamma distribution from which to generate samples. /// The inverse scale of the Gamma distribution from which to generate samples. /// a sample from the distribution. - public static double Sample(Random rng, double shape, double invScale) + public static double Sample(System.Random rng, double shape, double invScale) { if (Control.CheckDistributionParameters && !IsValidParameterSet(shape, invScale)) { @@ -529,7 +526,7 @@ namespace MathNet.Numerics.Distributions /// The shape of the Gamma distribution from which to generate samples. /// The inverse scale of the Gamma distribution from which to generate samples. /// a sequence of samples from the distribution. - public static IEnumerable Samples(Random rng, double shape, double invScale) + public static IEnumerable Samples(System.Random rng, double shape, double invScale) { if (Control.CheckDistributionParameters && !IsValidParameterSet(shape, invScale)) { diff --git a/src/Numerics/Distributions/Discrete/Geometric.cs b/src/Numerics/Distributions/Geometric.cs similarity index 89% rename from src/Numerics/Distributions/Discrete/Geometric.cs rename to src/Numerics/Distributions/Geometric.cs index 6167a290..7c5a10d1 100644 --- a/src/Numerics/Distributions/Discrete/Geometric.cs +++ b/src/Numerics/Distributions/Geometric.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-2013 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 @@ -24,13 +28,14 @@ // OTHER DEALINGS IN THE SOFTWARE. // +using System; +using System.Collections.Generic; +using MathNet.Numerics.Properties; + namespace MathNet.Numerics.Distributions { - using System; - using System.Collections.Generic; - using Properties; - /// + /// Discrete Univariate Geometric distribution. /// The Geometric distribution is a distribution over positive integers parameterized by one positive real number. /// This implementation of the Geometric distribution will never generate 0's. /// Wikipedia - geometric distribution. @@ -50,7 +55,7 @@ namespace MathNet.Numerics.Distributions /// /// The distribution's random number generator. /// - Random _random; + System.Random _random; /// /// Initializes a new instance of the Geometric class. @@ -59,7 +64,7 @@ namespace MathNet.Numerics.Distributions /// If the Geometric parameter is not in the range [0,1]. public Geometric(double p) { - _random = new Random(); + _random = new System.Random(); SetParameters(p); } @@ -69,9 +74,9 @@ namespace MathNet.Numerics.Distributions /// 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) + public Geometric(double p, System.Random randomSource) { - _random = randomSource ?? new Random(); + _random = randomSource ?? new System.Random(); SetParameters(p); } @@ -121,12 +126,10 @@ namespace MathNet.Numerics.Distributions return "Geometric(P = " + _p + ")"; } - #region IDistribution Members - /// /// Gets or sets the random number generator which is used to draw random samples. /// - public Random RandomSource + public System.Random RandomSource { get { return _random; } set @@ -181,20 +184,6 @@ namespace MathNet.Numerics.Distributions get { return (2.0 - _p)/Math.Sqrt(1.0 - _p); } } - /// - /// Computes the cumulative distribution function of the Bernoulli distribution. - /// - /// The location at which to compute the cumulative density. - /// the cumulative density at . - public double CumulativeDistribution(double x) - { - return 1.0 - Math.Pow(1.0 - _p, x); - } - - #endregion - - #region IDiscreteDistribution Members - /// /// Gets the mode of the distribution. /// @@ -228,12 +217,10 @@ namespace MathNet.Numerics.Distributions } /// - /// Computes values of the probability mass function. + /// Computes the probability mass (PMF), i.e. P(X = x). /// /// The location in the domain where we want to evaluate the probability mass function. - /// - /// the probability mass at location . - /// + /// the probability mass at location . public double Probability(int k) { if (k <= 0) @@ -245,12 +232,10 @@ namespace MathNet.Numerics.Distributions } /// - /// Computes values of the log probability mass function. + /// Computes the log probability mass (lnPMF), i.e. ln(P(X = x)). /// /// The location in the domain where we want to evaluate the log probability mass function. - /// - /// the log probability mass at location . - /// + /// the log probability mass at location . public double ProbabilityLn(int k) { if (k <= 0) @@ -261,7 +246,15 @@ namespace MathNet.Numerics.Distributions return ((k - 1)*Math.Log(1.0 - _p)) + Math.Log(_p); } - #endregion + /// + /// Computes the cumulative distribution (CDF) of the distribution, i.e. P(X <= x). + /// + /// The location at which to compute the cumulative distribution function. + /// the cumulative distribution at location . + public double CumulativeDistribution(double x) + { + return 1.0 - Math.Pow(1.0 - _p, x); + } /// /// Returns one sample from the distribution. @@ -271,7 +264,7 @@ namespace MathNet.Numerics.Distributions /// /// One sample from the distribution implied by . /// - internal static int SampleUnchecked(Random rnd, double p) + internal static int SampleUnchecked(System.Random rnd, double p) { return p == 1.0 ? 1 : (int) Math.Ceiling(-Math.Log(1.0 - rnd.NextDouble(), 1.0 - p)); } @@ -302,7 +295,7 @@ namespace MathNet.Numerics.Distributions /// /// The random number generator to use. /// The p parameter - public static int Sample(Random rnd, double p) + public static int Sample(System.Random rnd, double p) { if (Control.CheckDistributionParameters && !IsValidParameterSet(p)) { @@ -317,7 +310,7 @@ namespace MathNet.Numerics.Distributions /// /// The random number generator to use. /// The p parameter - public static IEnumerable Samples(Random rnd, double p) + public static IEnumerable Samples(System.Random rnd, double p) { if (Control.CheckDistributionParameters && !IsValidParameterSet(p)) { diff --git a/src/Numerics/Distributions/Discrete/Hypergeometric.cs b/src/Numerics/Distributions/Hypergeometric.cs similarity index 91% rename from src/Numerics/Distributions/Discrete/Hypergeometric.cs rename to src/Numerics/Distributions/Hypergeometric.cs index 76d41578..d038039d 100644 --- a/src/Numerics/Distributions/Discrete/Hypergeometric.cs +++ b/src/Numerics/Distributions/Hypergeometric.cs @@ -28,16 +28,15 @@ // OTHER DEALINGS IN THE SOFTWARE. // -using MathNet.Numerics.Properties; +using System; using System.Collections.Generic; +using MathNet.Numerics.Properties; namespace MathNet.Numerics.Distributions { - using System; - /// - /// This class implements functionality for the Hypergeometric distribution. This distribution is - /// a discrete probability distribution that describes the number of successes in a sequence + /// Discrete Univariate Hypergeometric distribution. + /// This distribution is a discrete probability distribution that describes the number of successes in a sequence /// of n draws from a finite population without replacement, just as the binomial distribution /// describes the number of successes for draws with replacement /// Wikipedia - Hypergeometric distribution. @@ -68,7 +67,7 @@ namespace MathNet.Numerics.Distributions /// /// The distribution's random number generator. /// - Random _random; + System.Random _random; /// /// Initializes a new instance of the Hypergeometric class. @@ -78,7 +77,7 @@ namespace MathNet.Numerics.Distributions /// The number of draws without replacement (n). public Hypergeometric(int population, int success, int draws) { - _random = new Random(); + _random = new System.Random(); SetParameters(population, success, draws); } @@ -89,9 +88,9 @@ namespace MathNet.Numerics.Distributions /// The number successes within the population (K, M). /// The number of draws without replacement (n). /// The random number generator which is used to draw random samples. - public Hypergeometric(int population, int success, int draws, Random randomSource) + public Hypergeometric(int population, int success, int draws, System.Random randomSource) { - _random = randomSource ?? new Random(); + _random = randomSource ?? new System.Random(); SetParameters(population, success, draws); } @@ -196,7 +195,7 @@ namespace MathNet.Numerics.Distributions /// /// Gets or sets the random number generator which is used to draw random samples. /// - public Random RandomSource + public System.Random RandomSource { get { return _random; } set @@ -283,34 +282,30 @@ namespace MathNet.Numerics.Distributions } /// - /// Computes values of the probability mass function (PMF), i.e. P(X = x). + /// Computes the probability mass (PMF), i.e. P(X = x). /// /// The location in the domain where we want to evaluate the probability mass function. - /// - /// the probability mass at location . - /// + /// the probability mass at location . public double Probability(int k) { return SpecialFunctions.Binomial(_success, k)*SpecialFunctions.Binomial(_population - _success, _draws - k)/SpecialFunctions.Binomial(_population, _draws); } /// - /// Computes values of the log probability mass function (lnPMF), i.e. ln(P(X = x)). + /// Computes the log probability mass (lnPMF), i.e. ln(P(X = x)). /// /// The location in the domain where we want to evaluate the log probability mass function. - /// - /// the log probability mass at location . - /// + /// the log probability mass at location . public double ProbabilityLn(int k) { return Math.Log(Probability(k)); } /// - /// Computes the cumulative distribution function (CDF) of the distribution, i.e. P(X <= x). + /// Computes the cumulative distribution (CDF) of the distribution, i.e. P(X <= x). /// - /// The location at which to compute the cumulative density. - /// the cumulative density at . + /// The location at which to compute the cumulative distribution function. + /// the cumulative distribution at location . public double CumulativeDistribution(double x) { if (x < Minimum) @@ -340,7 +335,7 @@ namespace MathNet.Numerics.Distributions /// The number successes within the population (K, M). /// The n parameter of the distribution. /// a random number from the Hypergeometric distribution. - internal static int SampleUnchecked(Random rnd, int population, int success, int draws) + internal static int SampleUnchecked(System.Random rnd, int population, int success, int draws) { var x = 0; @@ -389,7 +384,7 @@ namespace MathNet.Numerics.Distributions /// The size of the population (N). /// The number successes within the population (K, M). /// The number of draws without replacement (n). - public static int Sample(Random rnd, int population, int success, int draws) + public static int Sample(System.Random rnd, int population, int success, int draws) { if (Control.CheckDistributionParameters && !IsValidParameterSet(population, success, draws)) { @@ -406,7 +401,7 @@ namespace MathNet.Numerics.Distributions /// The size of the population (N). /// The number successes within the population (K, M). /// The number of draws without replacement (n). - public static IEnumerable Samples(Random rnd, int population, int success, int draws) + public static IEnumerable Samples(System.Random rnd, int population, int success, int draws) { if (Control.CheckDistributionParameters && !IsValidParameterSet(population, success, draws)) { diff --git a/src/Numerics/Distributions/IContinuousDistribution.cs b/src/Numerics/Distributions/IContinuousDistribution.cs index 09bcd9c1..419612da 100644 --- a/src/Numerics/Distributions/IContinuousDistribution.cs +++ b/src/Numerics/Distributions/IContinuousDistribution.cs @@ -4,7 +4,7 @@ // http://github.com/mathnet/mathnet-numerics // http://mathnetnumerics.codeplex.com // -// Copyright (c) 2009-2010 Math.NET +// Copyright (c) 2009-2013 Math.NET // // Permission is hereby granted, free of charge, to any person // obtaining a copy of this software and associated documentation @@ -58,14 +58,14 @@ namespace MathNet.Numerics.Distributions double Maximum { get; } /// - /// The probability density of the distribution. + /// Computes the density of the distribution (PDF), i.e. dP(X <= x)/dx. /// /// The location at which to compute the density. /// the density at . double Density(double x); /// - /// The log probability density of the distribution. + /// Computes the log density of the distribution (lnPDF), i.e. ln(dP(X <= x)/dx). /// /// The location at which to compute the log density. /// the log density at . diff --git a/src/Numerics/Distributions/IDiscreteDistribution.cs b/src/Numerics/Distributions/IDiscreteDistribution.cs index f77aa937..2baa34ba 100644 --- a/src/Numerics/Distributions/IDiscreteDistribution.cs +++ b/src/Numerics/Distributions/IDiscreteDistribution.cs @@ -4,7 +4,7 @@ // http://github.com/mathnet/mathnet-numerics // http://mathnetnumerics.codeplex.com // -// Copyright (c) 2009-2010 Math.NET +// Copyright (c) 2009-2013 Math.NET // // Permission is hereby granted, free of charge, to any person // obtaining a copy of this software and associated documentation @@ -58,14 +58,14 @@ namespace MathNet.Numerics.Distributions int Maximum { get; } /// - /// Computes values of the probability mass function. + /// Computes the probability mass (PMF), i.e. P(X = x). /// /// The location in the domain where we want to evaluate the probability mass function. /// the probability mass at location . double Probability(int k); /// - /// Computes values of the log probability mass function. + /// Computes the log probability mass (lnPMF), i.e. ln(P(X = x)). /// /// The location in the domain where we want to evaluate the log probability mass function. /// the log probability mass at location . diff --git a/src/Numerics/Distributions/IDistribution.cs b/src/Numerics/Distributions/IDistribution.cs index 439221b5..c42b4ef3 100644 --- a/src/Numerics/Distributions/IDistribution.cs +++ b/src/Numerics/Distributions/IDistribution.cs @@ -4,7 +4,7 @@ // http://github.com/mathnet/mathnet-numerics // http://mathnetnumerics.codeplex.com // -// Copyright (c) 2009-2010 Math.NET +// Copyright (c) 2009-2013 Math.NET // // Permission is hereby granted, free of charge, to any person // obtaining a copy of this software and associated documentation @@ -68,7 +68,7 @@ namespace MathNet.Numerics.Distributions double Skewness { get; } /// - /// Computes the cumulative distribution function (cdf) for this probability distribution. + /// Computes the cumulative distribution (CDF) of the distribution, i.e. P(X <= x). /// /// The location at which to compute the cumulative distribution function. /// the cumulative distribution at location . diff --git a/src/Numerics/Distributions/Continuous/InverseGamma.cs b/src/Numerics/Distributions/InverseGamma.cs similarity index 91% rename from src/Numerics/Distributions/Continuous/InverseGamma.cs rename to src/Numerics/Distributions/InverseGamma.cs index 246a3240..d7213eb3 100644 --- a/src/Numerics/Distributions/Continuous/InverseGamma.cs +++ b/src/Numerics/Distributions/InverseGamma.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-2013 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 @@ -24,13 +28,14 @@ // OTHER DEALINGS IN THE SOFTWARE. // +using System; +using System.Collections.Generic; +using MathNet.Numerics.Properties; + namespace MathNet.Numerics.Distributions { - using System; - using System.Collections.Generic; - using Properties; - /// + /// Continuous Univariate Inverse Gamma distribution. /// The inverse Gamma distribution is a distribution over the positive real numbers parameterized by /// two positive parameters. /// Wikipedia - InverseGamma distribution. @@ -55,7 +60,7 @@ namespace MathNet.Numerics.Distributions /// /// The distribution's random number generator. /// - Random _random; + System.Random _random; /// /// Initializes a new instance of the class. @@ -64,7 +69,7 @@ namespace MathNet.Numerics.Distributions /// The scale (beta) parameter of the inverse Gamma distribution. public InverseGamma(double shape, double scale) { - _random = new Random(); + _random = new System.Random(); SetParameters(shape, scale); } @@ -74,9 +79,9 @@ namespace MathNet.Numerics.Distributions /// 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) + public InverseGamma(double shape, double scale, System.Random randomSource) { - _random = randomSource ?? new Random(); + _random = randomSource ?? new System.Random(); SetParameters(shape, scale); } @@ -139,12 +144,10 @@ namespace MathNet.Numerics.Distributions return "InverseGamma(Shape = " + _shape + ", Inverse Scale = " + _scale + ")"; } - #region IDistribution Members - /// /// Gets or sets the random number generator which is used to draw random samples. /// - public Random RandomSource + public System.Random RandomSource { get { return _random; } set @@ -222,20 +225,6 @@ namespace MathNet.Numerics.Distributions } } - /// - /// Computes the cumulative distribution function of the distribution. - /// - /// The location at which to compute the cumulative density. - /// the cumulative density at . - public double CumulativeDistribution(double x) - { - return SpecialFunctions.GammaUpperRegularized(_shape, _scale/x); - } - - #endregion - - #region IContinuousDistribution Members - /// /// Gets the mode of the distribution. /// @@ -270,7 +259,7 @@ namespace MathNet.Numerics.Distributions } /// - /// Computes the density of the distribution. + /// Computes the density of the distribution (PDF), i.e. dP(X <= x)/dx. /// /// The location at which to compute the density. /// the density at . @@ -285,7 +274,7 @@ namespace MathNet.Numerics.Distributions } /// - /// Computes the log density of the distribution. + /// Computes the log density of the distribution (lnPDF), i.e. ln(dP(X <= x)/dx). /// /// The location at which to compute the log density. /// the log density at . @@ -294,7 +283,15 @@ namespace MathNet.Numerics.Distributions return Math.Log(Density(x)); } - #endregion + /// + /// Computes the cumulative distribution (CDF) of the distribution, i.e. P(X <= x). + /// + /// The location at which to compute the cumulative distribution function. + /// the cumulative distribution at location . + public double CumulativeDistribution(double x) + { + return SpecialFunctions.GammaUpperRegularized(_shape, _scale/x); + } /// /// Samples the distribution. @@ -303,7 +300,7 @@ namespace MathNet.Numerics.Distributions /// The shape (alpha) parameter of the inverse Gamma distribution. /// The scale (beta) parameter of the inverse Gamma distribution. /// a random number from the distribution. - internal static double SampleUnchecked(Random rnd, double shape, double scale) + internal static double SampleUnchecked(System.Random rnd, double shape, double scale) { return 1.0/Gamma.Sample(rnd, shape, scale); } @@ -336,7 +333,7 @@ namespace MathNet.Numerics.Distributions /// The shape (alpha) parameter of the inverse Gamma distribution. /// The scale (beta) parameter of the inverse Gamma distribution. /// a sample from the distribution. - public static double Sample(Random rnd, double shape, double scale) + public static double Sample(System.Random rnd, double shape, double scale) { if (Control.CheckDistributionParameters && !IsValidParameterSet(shape, scale)) { @@ -353,7 +350,7 @@ namespace MathNet.Numerics.Distributions /// The shape (alpha) parameter of the inverse Gamma distribution. /// The scale (beta) parameter of the inverse Gamma distribution. /// a sequence of samples from the distribution. - public static IEnumerable Samples(Random rnd, double shape, double scale) + public static IEnumerable Samples(System.Random rnd, double shape, double scale) { if (Control.CheckDistributionParameters && !IsValidParameterSet(shape, scale)) { diff --git a/src/Numerics/Distributions/Multivariate/InverseWishart.cs b/src/Numerics/Distributions/InverseWishart.cs similarity index 94% rename from src/Numerics/Distributions/Multivariate/InverseWishart.cs rename to src/Numerics/Distributions/InverseWishart.cs index ce95ab23..902b94a5 100644 --- a/src/Numerics/Distributions/Multivariate/InverseWishart.cs +++ b/src/Numerics/Distributions/InverseWishart.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-2013 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 @@ -24,16 +28,15 @@ // OTHER DEALINGS IN THE SOFTWARE. // +using System; using MathNet.Numerics.LinearAlgebra; using MathNet.Numerics.LinearAlgebra.Factorization; using MathNet.Numerics.Properties; namespace MathNet.Numerics.Distributions { - using System; - /// - /// This class implements functionality for the inverse Wishart distribution. This distribution is + /// Multivariate Inverse Wishart distribution. This distribution is /// parameterized by the degrees of freedom nu and the scale matrix S. The inverse Wishart distribution /// is the conjugate prior for the covariance matrix of a multivariate normal distribution. /// Wikipedia - Inverse-Wishart distribution. @@ -63,7 +66,7 @@ namespace MathNet.Numerics.Distributions /// /// The distribution's random number generator. /// - Random _random; + System.Random _random; /// /// Initializes a new instance of the class. @@ -72,7 +75,7 @@ namespace MathNet.Numerics.Distributions /// The scale matrix for the inverse Wishart distribution. public InverseWishart(double nu, Matrix s) { - _random = new Random(); + _random = new System.Random(); SetParameters(nu, s); } @@ -82,9 +85,9 @@ namespace MathNet.Numerics.Distributions /// 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) + public InverseWishart(double nu, Matrix s, System.Random randomSource) { - _random = randomSource ?? new Random(); + _random = randomSource ?? new System.Random(); SetParameters(nu, s); } @@ -160,7 +163,7 @@ namespace MathNet.Numerics.Distributions /// /// Gets or sets the random number generator which is used to draw random samples. /// - public Random RandomSource + public System.Random RandomSource { get { return _random; } set @@ -244,10 +247,10 @@ namespace MathNet.Numerics.Distributions } return Math.Pow(dX, -(_nu + p + 1.0)/2.0) - *Math.Exp(-0.5*sXi.Trace()) - *Math.Pow(_chol.Determinant, _nu/2.0) - /Math.Pow(2.0, _nu*p/2.0) - /gp; + *Math.Exp(-0.5*sXi.Trace()) + *Math.Pow(_chol.Determinant, _nu/2.0) + /Math.Pow(2.0, _nu*p/2.0) + /gp; } /// @@ -268,7 +271,7 @@ namespace MathNet.Numerics.Distributions /// The degrees of freedom. /// The scale matrix. /// a sample from the distribution. - public static Matrix Sample(Random rnd, double nu, Matrix s) + public static Matrix Sample(System.Random rnd, double nu, Matrix s) { if (Control.CheckDistributionParameters && !IsValidParameterSet(nu, s)) { diff --git a/src/Numerics/Distributions/Continuous/Laplace.cs b/src/Numerics/Distributions/Laplace.cs similarity index 90% rename from src/Numerics/Distributions/Continuous/Laplace.cs rename to src/Numerics/Distributions/Laplace.cs index e88855fe..0cd45648 100644 --- a/src/Numerics/Distributions/Continuous/Laplace.cs +++ b/src/Numerics/Distributions/Laplace.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-2013 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 @@ -24,13 +28,14 @@ // OTHER DEALINGS IN THE SOFTWARE. // +using System; +using System.Collections.Generic; +using MathNet.Numerics.Properties; + namespace MathNet.Numerics.Distributions { - using System; - using System.Collections.Generic; - using Properties; - /// + /// Continuous Univariate Laplace distribution. /// The Laplace distribution is a distribution over the real numbers parameterized by a mean and /// scale parameter. The PDF is: /// p(x) = \frac{1}{2 * scale} \exp{- |x - mean| / scale}. @@ -51,7 +56,7 @@ namespace MathNet.Numerics.Distributions /// /// The distribution's random number generator. /// - Random _random; + System.Random _random; /// /// Gets or sets the location of the Laplace distribution. @@ -87,7 +92,7 @@ namespace MathNet.Numerics.Distributions /// If is negative. public Laplace(double location, double scale) { - _random = new Random(); + _random = new System.Random(); SetParameters(location, scale); } @@ -98,9 +103,9 @@ namespace MathNet.Numerics.Distributions /// 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) + public Laplace(double location, double scale, System.Random randomSource) { - _random = randomSource ?? new Random(); + _random = randomSource ?? new System.Random(); SetParameters(location, scale); } @@ -141,12 +146,10 @@ namespace MathNet.Numerics.Distributions return "Laplace(Location = " + Mean + ", Scale = " + _scale + ")"; } - #region IDistribution Members - /// /// Gets or sets the random number generator which is used to draw random samples. /// - public Random RandomSource + public System.Random RandomSource { get { return _random; } set @@ -197,20 +200,6 @@ namespace MathNet.Numerics.Distributions get { return 0.0; } } - /// - /// Computes the cumulative distribution function of the distribution. - /// - /// The location at which to compute the cumulative density. - /// the cumulative density at . - public double CumulativeDistribution(double x) - { - return 0.5*(1.0 + (Math.Sign(x - Mean)*(1.0 - Math.Exp(-Math.Abs(x - Mean)/_scale)))); - } - - #endregion - - #region IContinuousDistribution Members - /// /// Gets the mode of the distribution. /// @@ -244,17 +233,17 @@ namespace MathNet.Numerics.Distributions } /// - /// Computes the density of the distribution. + /// Computes the density of the distribution (PDF), i.e. dP(X <= x)/dx. /// /// The location at which to compute the density. - /// the density at . + /// the density at . public double Density(double x) { return Math.Exp(-Math.Abs(x - Mean)/_scale)/(2.0*_scale); } /// - /// Computes the log density of the distribution. + /// Computes the log density of the distribution (lnPDF), i.e. ln(dP(X <= x)/dx). /// /// The location at which to compute the log density. /// the log density at . @@ -263,7 +252,15 @@ namespace MathNet.Numerics.Distributions return Math.Log(Density(x)); } - #endregion + /// + /// Computes the cumulative distribution (CDF) of the distribution, i.e. P(X <= x). + /// + /// The location at which to compute the cumulative distribution function. + /// the cumulative distribution at location . + public double CumulativeDistribution(double x) + { + return 0.5*(1.0 + (Math.Sign(x - Mean)*(1.0 - Math.Exp(-Math.Abs(x - Mean)/_scale)))); + } /// /// Samples the distribution. @@ -272,7 +269,7 @@ namespace MathNet.Numerics.Distributions /// The location shape parameter. /// The scale parameter. /// a random number from the distribution. - internal static double SampleUnchecked(Random rnd, double location, double scale) + internal static double SampleUnchecked(System.Random rnd, double location, double scale) { var u = rnd.NextDouble() - 0.5; return location - (scale*Math.Sign(u)*Math.Log(1.0 - (2.0*Math.Abs(u)))); @@ -306,7 +303,7 @@ namespace MathNet.Numerics.Distributions /// The location shape parameter. /// The scale parameter. /// a sample from the distribution. - public static double Sample(Random rnd, double location, double scale) + public static double Sample(System.Random rnd, double location, double scale) { if (Control.CheckDistributionParameters && !IsValidParameterSet(location, scale)) { @@ -323,7 +320,7 @@ namespace MathNet.Numerics.Distributions /// The location shape parameter. /// The scale parameter. /// a sequence of samples from the distribution. - public static IEnumerable Samples(Random rnd, double location, double scale) + public static IEnumerable Samples(System.Random rnd, double location, double scale) { if (Control.CheckDistributionParameters && !IsValidParameterSet(location, scale)) { diff --git a/src/Numerics/Distributions/Continuous/LogNormal.cs b/src/Numerics/Distributions/LogNormal.cs similarity index 92% rename from src/Numerics/Distributions/Continuous/LogNormal.cs rename to src/Numerics/Distributions/LogNormal.cs index 227b758b..3e08ed6f 100644 --- a/src/Numerics/Distributions/Continuous/LogNormal.cs +++ b/src/Numerics/Distributions/LogNormal.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-2013 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 @@ -24,17 +28,17 @@ // OTHER DEALINGS IN THE SOFTWARE. // +using System; +using System.Collections.Generic; using System.Linq; using MathNet.Numerics.Properties; using MathNet.Numerics.Statistics; -using System.Collections.Generic; namespace MathNet.Numerics.Distributions { - using System; - /// - /// Implements the univariate Log-Normal distribution. For details about this distribution, see + /// Continuous Univariate Log-Normal distribution. + /// For details about this distribution, see /// Wikipedia - Log-Normal distribution. /// /// The distribution will use the by default. @@ -57,7 +61,7 @@ namespace MathNet.Numerics.Distributions /// /// The distribution's random number generator. /// - Random _random; + System.Random _random; /// /// Initializes a new instance of the class. @@ -68,7 +72,7 @@ namespace MathNet.Numerics.Distributions /// The standard deviation of the logarithm of the distribution. public LogNormal(double mu, double sigma) { - _random = new Random(); + _random = new System.Random(); SetParameters(mu, sigma); } @@ -80,9 +84,9 @@ namespace MathNet.Numerics.Distributions /// 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) + public LogNormal(double mu, double sigma, System.Random randomSource) { - _random = randomSource ?? new Random(); + _random = randomSource ?? new System.Random(); SetParameters(mu, sigma); } @@ -95,8 +99,8 @@ namespace MathNet.Numerics.Distributions /// a log-normal distribution. public static LogNormal WithMeanVariance(double mean, double var) { - var sigma2 = Math.Log(var / (mean * mean) + 1.0); - return new LogNormal(Math.Log(mean) - sigma2 / 2.0, Math.Sqrt(sigma2)); + var sigma2 = Math.Log(var/(mean*mean) + 1.0); + return new LogNormal(Math.Log(mean) - sigma2/2.0, Math.Sqrt(sigma2)); } /// @@ -163,12 +167,10 @@ namespace MathNet.Numerics.Distributions set { SetParameters(_mu, value); } } - #region IDistribution implementation - /// /// Gets or sets the random number generator which is used to draw random samples. /// - public Random RandomSource + public System.Random RandomSource { get { return _random; } set @@ -234,10 +236,6 @@ namespace MathNet.Numerics.Distributions } } - #endregion - - #region IContinuousDistribution implementation - /// /// Gets the mode of the log-normal distribution. /// @@ -271,7 +269,7 @@ namespace MathNet.Numerics.Distributions } /// - /// Computes the density of the log-normal distribution. + /// Computes the density of the distribution (PDF), i.e. dP(X <= x)/dx. /// /// The location at which to compute the density. /// the density at . @@ -287,7 +285,7 @@ namespace MathNet.Numerics.Distributions } /// - /// Computes the log density of the log-normal distribution. + /// Computes the log density of the distribution (lnPDF), i.e. ln(dP(X <= x)/dx). /// /// The location at which to compute the log density. /// the log density at . @@ -303,10 +301,10 @@ namespace MathNet.Numerics.Distributions } /// - /// Computes the cumulative distribution function of the log-normal distribution. + /// Computes the cumulative distribution (CDF) of the distribution, i.e. P(X <= x). /// - /// The location at which to compute the cumulative density. - /// the cumulative density at . + /// The location at which to compute the cumulative distribution function. + /// the cumulative distribution at location . public double CumulativeDistribution(double x) { if (x < 0.0) @@ -317,8 +315,6 @@ namespace MathNet.Numerics.Distributions return 0.5*(1.0 + SpecialFunctions.Erf((Math.Log(x) - _mu)/(_sigma*Constants.Sqrt2))); } - #endregion - /// /// Generates a sample from the log-normal distribution using the Box-Muller algorithm. /// @@ -349,7 +345,7 @@ namespace MathNet.Numerics.Distributions /// The mu of the logarithm of the distribution. /// The standard deviation of the logarithm of the distribution. /// a sample from the distribution. - public static double Sample(Random rng, double mu, double sigma) + public static double Sample(System.Random rng, double mu, double sigma) { if (Control.CheckDistributionParameters && !IsValidParameterSet(mu, sigma)) { @@ -366,7 +362,7 @@ namespace MathNet.Numerics.Distributions /// The mu of the logarithm of the distribution. /// The standard deviation of the logarithm of the distribution. /// a sequence of samples from the distribution. - public static IEnumerable Samples(Random rng, double mu, double sigma) + public static IEnumerable Samples(System.Random rng, double mu, double sigma) { if (Control.CheckDistributionParameters && !IsValidParameterSet(mu, sigma)) { diff --git a/src/Numerics/Distributions/Multivariate/MatrixNormal.cs b/src/Numerics/Distributions/MatrixNormal.cs similarity index 93% rename from src/Numerics/Distributions/Multivariate/MatrixNormal.cs rename to src/Numerics/Distributions/MatrixNormal.cs index 2f7702f1..68243253 100644 --- a/src/Numerics/Distributions/Multivariate/MatrixNormal.cs +++ b/src/Numerics/Distributions/MatrixNormal.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-2013 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 @@ -24,6 +28,7 @@ // OTHER DEALINGS IN THE SOFTWARE. // +using System; using MathNet.Numerics.LinearAlgebra; using MathNet.Numerics.LinearAlgebra.Double; using MathNet.Numerics.LinearAlgebra.Factorization; @@ -31,10 +36,8 @@ using MathNet.Numerics.Properties; namespace MathNet.Numerics.Distributions { - using System; - /// - /// This class implements functionality for matrix valued normal distributions. The distribution + /// Multivariate Matrix-valued Normal distributions. The distribution /// is parameterized by a mean matrix (M), a covariance matrix for the rows (V) and a covariance matrix /// for the columns (K). If the dimension of M is d-by-m then V is d-by-d and K is m-by-m. /// Wikipedia - MatrixNormal distribution. @@ -64,7 +67,7 @@ namespace MathNet.Numerics.Distributions /// /// The distribution's random number generator. /// - Random _random; + System.Random _random; /// /// Initializes a new instance of the class. @@ -75,7 +78,7 @@ namespace MathNet.Numerics.Distributions /// If the dimensions of the mean and two covariance matrices don't match. public MatrixNormal(Matrix m, Matrix v, Matrix k) { - _random = new Random(); + _random = new System.Random(); SetParameters(m, v, k); } @@ -87,9 +90,9 @@ namespace MathNet.Numerics.Distributions /// 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) + public MatrixNormal(Matrix m, Matrix v, Matrix k, System.Random randomSource) { - _random = randomSource ?? new Random(); + _random = randomSource ?? new System.Random(); SetParameters(m, v, k); } @@ -196,7 +199,7 @@ namespace MathNet.Numerics.Distributions /// /// Gets or sets the random number generator which is used to draw random samples. /// - public Random RandomSource + public System.Random RandomSource { get { return _random; } set @@ -228,9 +231,9 @@ namespace MathNet.Numerics.Distributions var cholK = Cholesky.Create(_k); return Math.Exp(-0.5*cholV.Solve(a.Transpose()*cholK.Solve(a)).Trace()) - /Math.Pow(2.0*Constants.Pi, x.RowCount*x.ColumnCount/2.0) - /Math.Pow(cholV.Determinant, x.RowCount/2.0) - /Math.Pow(cholK.Determinant, x.ColumnCount/2.0); + /Math.Pow(2.0*Constants.Pi, x.RowCount*x.ColumnCount/2.0) + /Math.Pow(cholV.Determinant, x.RowCount/2.0) + /Math.Pow(cholK.Determinant, x.ColumnCount/2.0); } /// @@ -251,7 +254,7 @@ namespace MathNet.Numerics.Distributions /// The covariance matrix for the columns. /// If the dimensions of the mean and two covariance matrices don't match. /// a sequence of samples from the distribution. - public static Matrix Sample(Random rnd, Matrix m, Matrix v, Matrix k) + public static Matrix Sample(System.Random rnd, Matrix m, Matrix v, Matrix k) { if (Control.CheckDistributionParameters && !IsValidParameterSet(m, v, k)) { @@ -287,7 +290,7 @@ namespace MathNet.Numerics.Distributions /// The mean of the vector normal distribution. /// The covariance matrix of the vector normal distribution. /// a sequence of samples from defined distribution. - static Vector SampleVectorNormal(Random rnd, Vector mean, Matrix covariance) + static Vector SampleVectorNormal(System.Random rnd, Vector mean, Matrix covariance) { var chol = Cholesky.Create(covariance); return SampleVectorNormal(rnd, mean, chol); @@ -300,7 +303,7 @@ namespace MathNet.Numerics.Distributions /// The mean of the vector normal distribution. /// The Cholesky factorization of the covariance matrix. /// a sequence of samples from defined distribution. - static Vector SampleVectorNormal(Random rnd, Vector mean, Cholesky cholesky) + static Vector SampleVectorNormal(System.Random rnd, Vector mean, Cholesky cholesky) { var count = mean.Count; diff --git a/src/Numerics/Distributions/Multivariate/Multinomial.cs b/src/Numerics/Distributions/Multinomial.cs similarity index 94% rename from src/Numerics/Distributions/Multivariate/Multinomial.cs rename to src/Numerics/Distributions/Multinomial.cs index 8ba2263b..05f1a713 100644 --- a/src/Numerics/Distributions/Multivariate/Multinomial.cs +++ b/src/Numerics/Distributions/Multinomial.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-2013 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 @@ -24,18 +28,18 @@ // OTHER DEALINGS IN THE SOFTWARE. // +using System; +using System.Collections.Generic; +using System.Linq; +using MathNet.Numerics.LinearAlgebra; +using MathNet.Numerics.LinearAlgebra.Double; +using MathNet.Numerics.Properties; +using MathNet.Numerics.Statistics; + namespace MathNet.Numerics.Distributions { - using LinearAlgebra; - using LinearAlgebra.Double; - using Properties; - using Statistics; - using System; - using System.Collections.Generic; - using System.Linq; - /// - /// Implements the multinomial distribution. For details about this distribution, see + /// Multivariate Multinomial distribution. For details about this distribution, see /// Wikipedia - Multinomial distribution. /// /// The distribution is parameterized by a vector of ratios: in other words, the parameter @@ -61,7 +65,7 @@ namespace MathNet.Numerics.Distributions /// /// The distribution's random number generator. /// - Random _random; + System.Random _random; /// /// Initializes a new instance of the Multinomial class. @@ -73,7 +77,7 @@ namespace MathNet.Numerics.Distributions /// If is negative. public Multinomial(double[] p, int n) { - _random = new Random(); + _random = new System.Random(); SetParameters(p, n); } @@ -86,9 +90,9 @@ namespace MathNet.Numerics.Distributions /// 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) + public Multinomial(double[] p, int n, System.Random randomSource) { - _random = randomSource ?? new Random(); + _random = randomSource ?? new System.Random(); SetParameters(p, n); } @@ -117,7 +121,7 @@ namespace MathNet.Numerics.Distributions } SetParameters(p, n); - RandomSource = new Random(); + RandomSource = new System.Random(); } /// @@ -197,7 +201,7 @@ namespace MathNet.Numerics.Distributions /// /// Gets or sets the random number generator which is used to draw random samples. /// - public Random RandomSource + public System.Random RandomSource { get { return _random; } set @@ -347,7 +351,7 @@ namespace MathNet.Numerics.Distributions /// as this is often impossible using floating point arithmetic. /// The number of trials. /// the counts for each of the different possible values. - public static int[] Sample(Random rnd, double[] p, int n) + public static int[] Sample(System.Random rnd, double[] p, int n) { if (Control.CheckDistributionParameters && !IsValidParameterSet(p, n)) { @@ -376,7 +380,7 @@ namespace MathNet.Numerics.Distributions /// as this is often impossible using floating point arithmetic. /// The number of variables needed. /// a sequence of counts for each of the different possible values. - public static IEnumerable Samples(Random rnd, double[] p, int n) + public static IEnumerable Samples(System.Random rnd, double[] p, int n) { if (Control.CheckDistributionParameters && !IsValidParameterSet(p, n)) { diff --git a/src/Numerics/Distributions/Discrete/NegativeBinomial.cs b/src/Numerics/Distributions/NegativeBinomial.cs similarity index 87% rename from src/Numerics/Distributions/Discrete/NegativeBinomial.cs rename to src/Numerics/Distributions/NegativeBinomial.cs index 1ed3c658..a657b7ed 100644 --- a/src/Numerics/Distributions/Discrete/NegativeBinomial.cs +++ b/src/Numerics/Distributions/NegativeBinomial.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-2013 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 @@ -24,13 +28,14 @@ // OTHER DEALINGS IN THE SOFTWARE. // +using System; +using System.Collections.Generic; +using MathNet.Numerics.Properties; + namespace MathNet.Numerics.Distributions { - using System; - using System.Collections.Generic; - using Properties; - /// + /// Discrete Univariate Negative Binomial distribution. /// The negative binomial is a distribution over the natural numbers with two parameters r,p. For the special /// case that r is an integer one can interpret the distribution as the number of tails before the r'th head /// when the probability of head is p. @@ -56,7 +61,7 @@ namespace MathNet.Numerics.Distributions /// /// The distribution's random number generator. /// - Random _random; + System.Random _random; /// /// Gets or sets the number of trials. @@ -83,7 +88,7 @@ namespace MathNet.Numerics.Distributions /// The probability of a trial resulting in success. public NegativeBinomial(double r, double p) { - _random = new Random(); + _random = new System.Random(); SetParameters(r, p); } @@ -93,9 +98,9 @@ namespace MathNet.Numerics.Distributions /// 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) + public NegativeBinomial(double r, double p, System.Random randomSource) { - _random = randomSource ?? new Random(); + _random = randomSource ?? new System.Random(); SetParameters(r, p); } @@ -138,12 +143,10 @@ namespace MathNet.Numerics.Distributions return "NegativeBinomial(R = " + _r + ", P = " + _p + ")"; } - #region IDistribution Members - /// /// Gets or sets the distribution's random number generator. /// - public Random RandomSource + public System.Random RandomSource { get { return _random; } set @@ -197,20 +200,6 @@ namespace MathNet.Numerics.Distributions get { return (2.0 - _p)/Math.Sqrt(_r*(1.0 - _p)); } } - /// - /// Computes the cumulative distribution function of the NegativeBinomial distribution. - /// - /// The location at which to compute the cumulative density. - /// the cumulative density at . - public double CumulativeDistribution(double x) - { - return 1 - SpecialFunctions.BetaRegularized(x + 1, _r, 1 - _p); - } - - #endregion - - #region IDiscreteDistribution Members - /// /// Gets the mode of the distribution /// @@ -244,40 +233,44 @@ namespace MathNet.Numerics.Distributions } /// - /// Computes values of the probability mass function. + /// Computes the probability mass (PMF), i.e. P(X = x). /// /// The location in the domain where we want to evaluate the probability mass function. - /// - /// the probability mass at location . - /// + /// the probability mass at location . public double Probability(int k) { var ln = SpecialFunctions.GammaLn(_r + k) - - SpecialFunctions.GammaLn(_r) - - SpecialFunctions.GammaLn(k + 1.0) - + (_r*Math.Log(_p)) - + (k*Math.Log(1.0 - _p)); + - SpecialFunctions.GammaLn(_r) + - SpecialFunctions.GammaLn(k + 1.0) + + (_r*Math.Log(_p)) + + (k*Math.Log(1.0 - _p)); return Math.Exp(ln); } /// - /// Computes values of the log probability mass function. + /// Computes the log probability mass (lnPMF), i.e. ln(P(X = x)). /// /// The location in the domain where we want to evaluate the log probability mass function. - /// - /// the log probability mass at location . - /// + /// the log probability mass at location . public double ProbabilityLn(int k) { var ln = SpecialFunctions.GammaLn(_r + k) - - SpecialFunctions.GammaLn(_r) - - SpecialFunctions.GammaLn(k + 1.0) - + (_r*Math.Log(_p)) - + (k*Math.Log(1.0 - _p)); + - SpecialFunctions.GammaLn(_r) + - SpecialFunctions.GammaLn(k + 1.0) + + (_r*Math.Log(_p)) + + (k*Math.Log(1.0 - _p)); return ln; } - #endregion + /// + /// Computes the cumulative distribution (CDF) of the distribution, i.e. P(X <= x). + /// + /// The location at which to compute the cumulative distribution function. + /// the cumulative distribution at location . + public double CumulativeDistribution(double x) + { + return 1 - SpecialFunctions.BetaRegularized(x + 1, _r, 1 - _p); + } /// /// Samples a negative binomial distributed random variable. @@ -286,7 +279,7 @@ namespace MathNet.Numerics.Distributions /// The r parameter. /// The p parameter. /// a sample from the distribution. - internal static int SampleUnchecked(Random rnd, double r, double p) + internal static int SampleUnchecked(System.Random rnd, double r, double p) { var lambda = Gamma.SampleUnchecked(rnd, r, p); var c = Math.Exp(-lambda); @@ -327,7 +320,7 @@ namespace MathNet.Numerics.Distributions /// The random number generator to use. /// The r parameter. /// The p parameter. - public static int Sample(Random rnd, double r, double p) + public static int Sample(System.Random rnd, double r, double p) { if (Control.CheckDistributionParameters && !IsValidParameterSet(r, p)) { @@ -343,7 +336,7 @@ namespace MathNet.Numerics.Distributions /// The random number generator to use. /// The r parameter. /// The p parameter. - public static IEnumerable Samples(Random rnd, double r, double p) + public static IEnumerable Samples(System.Random rnd, double r, double p) { if (Control.CheckDistributionParameters && !IsValidParameterSet(r, p)) { diff --git a/src/Numerics/Distributions/Continuous/Normal.cs b/src/Numerics/Distributions/Normal.cs similarity index 93% rename from src/Numerics/Distributions/Continuous/Normal.cs rename to src/Numerics/Distributions/Normal.cs index 5dcf90cf..a465b9c0 100644 --- a/src/Numerics/Distributions/Continuous/Normal.cs +++ b/src/Numerics/Distributions/Normal.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-2013 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 @@ -24,16 +28,16 @@ // OTHER DEALINGS IN THE SOFTWARE. // +using System; +using System.Collections.Generic; using MathNet.Numerics.Properties; using MathNet.Numerics.Statistics; -using System.Collections.Generic; namespace MathNet.Numerics.Distributions { - using System; - /// - /// Implements the univariate Normal (or Gaussian) distribution. For details about this distribution, see + /// Continuous Univariate Normal distribution, also known as Gaussian distribution. + /// For details about this distribution, see /// Wikipedia - Normal distribution. /// /// The distribution will use the by default. @@ -56,7 +60,7 @@ namespace MathNet.Numerics.Distributions /// /// The distribution's random number generator. /// - Random _random; + System.Random _random; /// /// Initializes a new instance of the Normal class. This is a normal distribution with mean 0.0 @@ -74,7 +78,7 @@ namespace MathNet.Numerics.Distributions /// be initialized with the default random number generator. /// /// The random number generator which is used to draw random samples. - public Normal(Random randomSource) + public Normal(System.Random randomSource) : this(0.0, 1.0, randomSource) { } @@ -87,7 +91,7 @@ namespace MathNet.Numerics.Distributions /// The standard deviation of the normal distribution. public Normal(double mean, double stddev) { - _random = new Random(); + _random = new System.Random(); SetParameters(mean, stddev); } @@ -98,9 +102,9 @@ namespace MathNet.Numerics.Distributions /// 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) + public Normal(double mean, double stddev, System.Random randomSource) { - _random = randomSource ?? new Random(); + _random = randomSource ?? new System.Random(); SetParameters(mean, stddev); } @@ -210,7 +214,7 @@ namespace MathNet.Numerics.Distributions /// /// Gets or sets the random number generator which is used to draw random samples. /// - public Random RandomSource + public System.Random RandomSource { get { return _random; } set @@ -326,7 +330,7 @@ namespace MathNet.Numerics.Distributions } /// - /// Computes the density of the normal distribution (PDF), i.e. dP(X <= x)/dx. + /// Computes the density of the distribution (PDF), i.e. dP(X <= x)/dx. /// /// The location at which to compute the density. /// the density at . @@ -336,7 +340,7 @@ namespace MathNet.Numerics.Distributions } /// - /// Computes the log density of the normal distribution (lnPDF), i.e. ln(dP(X <= x)/dx). + /// Computes the log density of the distribution (lnPDF), i.e. ln(dP(X <= x)/dx). /// /// The location at which to compute the log density. /// the log density at . @@ -358,10 +362,10 @@ namespace MathNet.Numerics.Distributions } /// - /// Computes the cumulative distribution function (CDF) of the normal distribution, i.e. P(X <= x). + /// Computes the cumulative distribution (CDF) of the distribution, i.e. P(X <= x). /// - /// The location at which to compute the cumulative density. - /// the cumulative density at . + /// The location at which to compute the cumulative distribution function. + /// the cumulative distribution at location . public double CumulativeDistribution(double x) { return CumulativeDistribution(_mean, _stdDev, x); @@ -382,7 +386,7 @@ namespace MathNet.Numerics.Distributions /// /// The random number generator to use. /// a pair of random numbers from the standard normal distribution. - internal static Tuple SampleUncheckedBoxMuller(Random rnd) + internal static Tuple SampleUncheckedBoxMuller(System.Random rnd) { var v1 = (2.0*rnd.NextDouble()) - 1.0; var v2 = (2.0*rnd.NextDouble()) - 1.0; @@ -405,7 +409,7 @@ namespace MathNet.Numerics.Distributions /// The mean of the normal distribution from which to generate samples. /// The standard deviation of the normal distribution from which to generate samples. /// a random number from the distribution. - internal static double SampleUnchecked(Random rnd, double mean, double stddev) + internal static double SampleUnchecked(System.Random rnd, double mean, double stddev) { return mean + (stddev*SampleUncheckedBoxMuller(rnd).Item1); } @@ -440,7 +444,7 @@ namespace MathNet.Numerics.Distributions /// The mean of the normal distribution from which to generate samples. /// The standard deviation of the normal distribution from which to generate samples. /// a sample from the distribution. - public static double Sample(Random rnd, double mean, double stddev) + public static double Sample(System.Random rnd, double mean, double stddev) { if (Control.CheckDistributionParameters && !IsValidParameterSet(mean, stddev)) { @@ -457,7 +461,7 @@ namespace MathNet.Numerics.Distributions /// The mean of the normal distribution from which to generate samples. /// The standard deviation of the normal distribution from which to generate samples. /// a sequence of samples from the distribution. - public static IEnumerable Samples(Random rnd, double mean, double stddev) + public static IEnumerable Samples(System.Random rnd, double mean, double stddev) { if (Control.CheckDistributionParameters && !IsValidParameterSet(mean, stddev)) { diff --git a/src/Numerics/Distributions/Multivariate/NormalGamma.cs b/src/Numerics/Distributions/NormalGamma.cs similarity index 95% rename from src/Numerics/Distributions/Multivariate/NormalGamma.cs rename to src/Numerics/Distributions/NormalGamma.cs index c2d5f137..1f13c115 100644 --- a/src/Numerics/Distributions/Multivariate/NormalGamma.cs +++ b/src/Numerics/Distributions/NormalGamma.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-2013 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 @@ -24,12 +28,12 @@ // OTHER DEALINGS IN THE SOFTWARE. // +using System; +using System.Collections.Generic; +using MathNet.Numerics.Properties; + namespace MathNet.Numerics.Distributions { - using System; - using System.Collections.Generic; - using Properties; - /// /// This structure represents the type over which the distribution /// is defined. @@ -79,6 +83,7 @@ namespace MathNet.Numerics.Distributions } /// + /// Multivariate Normal-Gamma Distribution. /// The distribution is the conjugate prior distribution for the /// distribution. It specifies a prior over the mean and precision of the distribution. /// It is parameterized by four numbers: the mean location, the mean scale, the precision shape and the @@ -120,7 +125,7 @@ namespace MathNet.Numerics.Distributions /// /// The distribution's random number generator. /// - Random _random; + System.Random _random; /// /// Initializes a new instance of the class. @@ -131,7 +136,7 @@ namespace MathNet.Numerics.Distributions /// The inverse scale of the precision. public NormalGamma(double meanLocation, double meanScale, double precisionShape, double precisionInverseScale) { - _random = new Random(); + _random = new System.Random(); SetParameters(meanLocation, meanScale, precisionShape, precisionInverseScale); } @@ -143,9 +148,9 @@ namespace MathNet.Numerics.Distributions /// 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) + public NormalGamma(double meanLocation, double meanScale, double precisionShape, double precisionInverseScale, System.Random randomSource) { - _random = randomSource ?? new Random(); + _random = randomSource ?? new System.Random(); SetParameters(meanLocation, meanScale, precisionShape, precisionInverseScale); } @@ -190,7 +195,7 @@ namespace MathNet.Numerics.Distributions public override string ToString() { return "NormalGamma(Mean Location = " + _meanLocation + ", Mean Scale = " + _meanScale + - ", Precision Shape = " + _precisionShape + ", Precision Inverse Scale = " + _precisionInvScale + ")"; + ", Precision Shape = " + _precisionShape + ", Precision Inverse Scale = " + _precisionInvScale + ")"; } /// @@ -232,7 +237,7 @@ namespace MathNet.Numerics.Distributions /// /// Gets or sets the random number generator which is used to draw random samples. /// - public Random RandomSource + public System.Random RandomSource { get { return _random; } set @@ -324,7 +329,7 @@ namespace MathNet.Numerics.Distributions // return Math.Pow(prec * _precisionInvScale, _precisionShape) * Math.Exp(e) / (Constants.Sqrt2Pi * Math.Sqrt(prec) * SpecialFunctions.Gamma(_precisionShape)); double e = -(0.5*prec*_meanScale*(mean - _meanLocation)*(mean - _meanLocation)) - (prec*_precisionInvScale); return Math.Pow(prec*_precisionInvScale, _precisionShape)*Math.Exp(e)*Math.Sqrt(_meanScale) - /(Constants.Sqrt2Pi*Math.Sqrt(prec)*SpecialFunctions.Gamma(_precisionShape)); + /(Constants.Sqrt2Pi*Math.Sqrt(prec)*SpecialFunctions.Gamma(_precisionShape)); } /// @@ -396,7 +401,7 @@ namespace MathNet.Numerics.Distributions /// The shape of the precision. /// The inverse scale of the precision. /// a sample from the distribution. - public static MeanPrecisionPair Sample(Random rnd, double meanLocation, double meanScale, double precisionShape, double precisionInverseScale) + public static MeanPrecisionPair Sample(System.Random rnd, double meanLocation, double meanScale, double precisionShape, double precisionInverseScale) { if (Control.CheckDistributionParameters && !IsValidParameterSet(meanLocation, meanScale, precisionShape, precisionInverseScale)) { @@ -423,7 +428,7 @@ namespace MathNet.Numerics.Distributions /// The shape of the precision. /// The inverse scale of the precision. /// a sequence of samples from the distribution. - public static IEnumerable Samples(Random rnd, double meanLocation, double meanScale, double precisionShape, double precisionInvScale) + public static IEnumerable Samples(System.Random rnd, double meanLocation, double meanScale, double precisionShape, double precisionInvScale) { if (Control.CheckDistributionParameters && !IsValidParameterSet(meanLocation, meanScale, precisionShape, precisionInvScale)) { diff --git a/src/Numerics/Distributions/Continuous/Pareto.cs b/src/Numerics/Distributions/Pareto.cs similarity index 91% rename from src/Numerics/Distributions/Continuous/Pareto.cs rename to src/Numerics/Distributions/Pareto.cs index 092c62c8..4d514356 100644 --- a/src/Numerics/Distributions/Continuous/Pareto.cs +++ b/src/Numerics/Distributions/Pareto.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-2013 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 @@ -24,13 +28,14 @@ // OTHER DEALINGS IN THE SOFTWARE. // +using System; +using System.Collections.Generic; +using MathNet.Numerics.Properties; + namespace MathNet.Numerics.Distributions { - using System; - using System.Collections.Generic; - using Properties; - /// + /// Continuous Univariate Pareto distribution. /// The Pareto distribution is a power law probability distribution that coincides with social, /// scientific, geophysical, actuarial, and many other types of observable phenomena. /// For details about this distribution, see @@ -56,7 +61,7 @@ namespace MathNet.Numerics.Distributions /// /// The distribution's random number generator. /// - Random _random; + System.Random _random; /// /// Initializes a new instance of the class. @@ -66,7 +71,7 @@ namespace MathNet.Numerics.Distributions /// If or are negative. public Pareto(double scale, double shape) { - _random = new Random(); + _random = new System.Random(); SetParameters(scale, shape); } @@ -77,9 +82,9 @@ namespace MathNet.Numerics.Distributions /// 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) + public Pareto(double scale, double shape, System.Random randomSource) { - _random = randomSource ?? new Random(); + _random = randomSource ?? new System.Random(); SetParameters(scale, shape); } @@ -138,12 +143,10 @@ namespace MathNet.Numerics.Distributions return "Pareto(Scale = " + _scale + ", Shape = " + _shape + ")"; } - #region IDistribution Members - /// /// Gets or sets the random number generator which is used to draw random samples. /// - public Random RandomSource + public System.Random RandomSource { get { return _random; } set @@ -213,20 +216,6 @@ namespace MathNet.Numerics.Distributions get { return (2.0*(_shape + 1.0)/(_shape - 3.0))*Math.Sqrt((_shape - 2.0)/_shape); } } - /// - /// Computes the cumulative distribution function of the distribution. - /// - /// The location at which to compute the cumulative density. - /// the cumulative density at . - public double CumulativeDistribution(double x) - { - return 1.0 - Math.Pow(_scale/x, _shape); - } - - #endregion - - #region IContinuousDistribution Members - /// /// Gets the mode of the distribution. /// @@ -260,7 +249,7 @@ namespace MathNet.Numerics.Distributions } /// - /// Computes the density of the distribution. + /// Computes the density of the distribution (PDF), i.e. dP(X <= x)/dx. /// /// The location at which to compute the density. /// the density at . @@ -270,7 +259,7 @@ namespace MathNet.Numerics.Distributions } /// - /// Computes the log density of the distribution. + /// Computes the log density of the distribution (lnPDF), i.e. ln(dP(X <= x)/dx). /// /// The location at which to compute the log density. /// the log density at . @@ -279,7 +268,15 @@ namespace MathNet.Numerics.Distributions return Math.Log(Density(x)); } - #endregion + /// + /// Computes the cumulative distribution (CDF) of the distribution, i.e. P(X <= x). + /// + /// The location at which to compute the cumulative distribution function. + /// the cumulative distribution at location . + public double CumulativeDistribution(double x) + { + return 1.0 - Math.Pow(_scale/x, _shape); + } /// /// Generates a sample from the Pareto distribution without doing parameter checking. @@ -288,7 +285,7 @@ namespace MathNet.Numerics.Distributions /// The scale parameter. /// The shape parameter. /// a random number from the Pareto distribution. - internal static double SampleUnchecked(Random rnd, double scale, double shape) + internal static double SampleUnchecked(System.Random rnd, double scale, double shape) { return scale*Math.Pow(rnd.NextDouble(), -1.0/shape); } @@ -321,7 +318,7 @@ namespace MathNet.Numerics.Distributions /// The scale parameter. /// The shape parameter. /// a sample from the distribution. - public static double Sample(Random rnd, double scale, double shape) + public static double Sample(System.Random rnd, double scale, double shape) { if (Control.CheckDistributionParameters && !IsValidParameterSet(scale, shape)) { @@ -338,7 +335,7 @@ namespace MathNet.Numerics.Distributions /// The scale parameter. /// The shape parameter. /// a sequence of samples from the distribution. - public static IEnumerable Samples(Random rnd, double scale, double shape) + public static IEnumerable Samples(System.Random rnd, double scale, double shape) { if (Control.CheckDistributionParameters && !IsValidParameterSet(scale, shape)) { diff --git a/src/Numerics/Distributions/Discrete/Poisson.cs b/src/Numerics/Distributions/Poisson.cs similarity index 91% rename from src/Numerics/Distributions/Discrete/Poisson.cs rename to src/Numerics/Distributions/Poisson.cs index 34f2f5c8..6237fcbf 100644 --- a/src/Numerics/Distributions/Discrete/Poisson.cs +++ b/src/Numerics/Distributions/Poisson.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-2013 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 @@ -24,14 +28,14 @@ // OTHER DEALINGS IN THE SOFTWARE. // +using System; +using System.Collections.Generic; +using MathNet.Numerics.Properties; + namespace MathNet.Numerics.Distributions { - using System; - using System.Collections.Generic; - using Properties; - /// - /// Pseudo-random generation of poisson distributed deviates. + /// Discrete Univariate Poisson distribution. /// /// /// Distribution is described at Wikipedia - Poisson distribution. @@ -48,7 +52,7 @@ namespace MathNet.Numerics.Distributions /// /// The distribution's random number generator. /// - Random _random; + System.Random _random; /// /// Gets or sets the Poisson distribution parameter λ. @@ -66,7 +70,7 @@ namespace MathNet.Numerics.Distributions /// If is equal or less then 0.0. public Poisson(double lambda) { - _random = new Random(); + _random = new System.Random(); SetParameters(lambda); } @@ -76,9 +80,9 @@ namespace MathNet.Numerics.Distributions /// 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) + public Poisson(double lambda, System.Random randomSource) { - _random = randomSource ?? new Random(); + _random = randomSource ?? new System.Random(); SetParameters(lambda); } @@ -118,12 +122,10 @@ namespace MathNet.Numerics.Distributions return "Poisson(λ = " + _lambda + ")"; } - #region IDistribution Members - /// /// Gets or sets the random number generator which is used to draw random samples. /// - public Random RandomSource + public System.Random RandomSource { get { return _random; } set @@ -194,20 +196,6 @@ namespace MathNet.Numerics.Distributions get { return int.MaxValue; } } - /// - /// Computes the cumulative distribution function of the Poisson distribution. - /// - /// The location at which to compute the cumulative density. - /// the cumulative density at . - public double CumulativeDistribution(double x) - { - return 1.0 - SpecialFunctions.GammaLowerRegularized(x + 1, _lambda); - } - - #endregion - - #region IDiscreteDistribution Members - /// /// Gets the mode of the distribution. /// @@ -226,7 +214,7 @@ namespace MathNet.Numerics.Distributions } /// - /// Computes values of the probability mass function. + /// Computes the probability mass (PMF), i.e. P(X = x). /// /// The location in the domain where we want to evaluate the probability mass function. /// the probability mass at location . @@ -236,7 +224,7 @@ namespace MathNet.Numerics.Distributions } /// - /// Computes values of the log probability mass function. + /// Computes the log probability mass (lnPMF), i.e. ln(P(X = x)). /// /// The location in the domain where we want to evaluate the log probability mass function. /// the log probability mass at location . @@ -245,7 +233,15 @@ namespace MathNet.Numerics.Distributions return -_lambda + (k*Math.Log(_lambda)) - SpecialFunctions.FactorialLn(k); } - #endregion + /// + /// Computes the cumulative distribution (CDF) of the distribution, i.e. P(X <= x). + /// + /// The location at which to compute the cumulative distribution function. + /// the cumulative distribution at location . + public double CumulativeDistribution(double x) + { + return 1.0 - SpecialFunctions.GammaLowerRegularized(x + 1, _lambda); + } /// /// Generates one sample from the Poisson distribution. @@ -253,7 +249,7 @@ namespace MathNet.Numerics.Distributions /// The random source to use. /// The Poisson distribution parameter λ. /// A random sample from the Poisson distribution. - internal static int SampleUnchecked(Random rnd, double lambda) + internal static int SampleUnchecked(System.Random rnd, double lambda) { return (lambda < 30.0) ? DoSampleShort(rnd, lambda) : DoSampleLarge(rnd, lambda); } @@ -264,7 +260,7 @@ namespace MathNet.Numerics.Distributions /// The random source to use. /// The Poisson distribution parameter λ. /// A random sample from the Poisson distribution. - static int DoSampleShort(Random rnd, double lambda) + static int DoSampleShort(System.Random rnd, double lambda) { var limit = Math.Exp(-lambda); var count = 0; @@ -285,7 +281,7 @@ namespace MathNet.Numerics.Distributions /// "Rejection method PA" from "The Computer Generation of Poisson Random Variables" by A. C. Atkinson, /// Journal of the Royal Statistical Society Series C (Applied Statistics) Vol. 28, No. 1. (1979) /// The article is on pages 29-35. The algorithm given here is on page 32. - static int DoSampleLarge(Random rnd, double lambda) + static int DoSampleLarge(System.Random rnd, double lambda) { var c = 0.767 - (3.36/lambda); var beta = Math.PI/Math.Sqrt(3.0*lambda); @@ -341,7 +337,7 @@ namespace MathNet.Numerics.Distributions /// The random number generator to use. /// The Poisson distribution parameter λ. /// A sample from the Poisson distribution. - public static int Sample(Random rnd, double lambda) + public static int Sample(System.Random rnd, double lambda) { if (Control.CheckDistributionParameters && !IsValidParameterSet(lambda)) { @@ -357,7 +353,7 @@ namespace MathNet.Numerics.Distributions /// The random number generator to use. /// The Poisson distribution parameter λ. /// a sequence of samples from the distribution. - public static IEnumerable Samples(Random rnd, double lambda) + public static IEnumerable Samples(System.Random rnd, double lambda) { if (Control.CheckDistributionParameters && !IsValidParameterSet(lambda)) { diff --git a/src/Numerics/Distributions/Continuous/Rayleigh.cs b/src/Numerics/Distributions/Rayleigh.cs similarity index 90% rename from src/Numerics/Distributions/Continuous/Rayleigh.cs rename to src/Numerics/Distributions/Rayleigh.cs index 85bc03db..01243d02 100644 --- a/src/Numerics/Distributions/Continuous/Rayleigh.cs +++ b/src/Numerics/Distributions/Rayleigh.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-2013 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 @@ -24,13 +28,14 @@ // OTHER DEALINGS IN THE SOFTWARE. // +using System; +using System.Collections.Generic; +using MathNet.Numerics.Properties; + namespace MathNet.Numerics.Distributions { - using System; - using System.Collections.Generic; - using Properties; - /// + /// Continuous Univariate Rayleigh distribution. /// The Rayleigh distribution (pronounced /ˈreɪli/) is a continuous probability distribution. As an /// example of how it arises, the wind speed will have a Rayleigh distribution if the components of /// the two-dimensional wind velocity vector are uncorrelated and normally distributed with equal variance. @@ -52,7 +57,7 @@ namespace MathNet.Numerics.Distributions /// /// The distribution's random number generator. /// - Random _random; + System.Random _random; /// /// Initializes a new instance of the class. @@ -61,7 +66,7 @@ namespace MathNet.Numerics.Distributions /// If is negative. public Rayleigh(double scale) { - _random = new Random(); + _random = new System.Random(); SetParameters(scale); } @@ -71,9 +76,9 @@ namespace MathNet.Numerics.Distributions /// 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) + public Rayleigh(double scale, System.Random randomSource) { - _random = randomSource ?? new Random(); + _random = randomSource ?? new System.Random(); SetParameters(scale); } @@ -120,12 +125,10 @@ namespace MathNet.Numerics.Distributions return "Rayleigh(Scale = " + _scale + ")"; } - #region IDistribution Members - /// /// Gets or sets the random number generator which is used to draw random samples. /// - public Random RandomSource + public System.Random RandomSource { get { return _random; } set @@ -179,20 +182,6 @@ namespace MathNet.Numerics.Distributions get { return (2.0*Math.Sqrt(Constants.Pi)*(Constants.Pi - 3.0))/Math.Pow(4.0 - Constants.Pi, 1.5); } } - /// - /// Computes the cumulative distribution function of the distribution. - /// - /// The location at which to compute the cumulative density. - /// the cumulative density at . - public double CumulativeDistribution(double x) - { - return 1.0 - Math.Exp(-x*x/(2.0*_scale*_scale)); - } - - #endregion - - #region IContinuousDistribution Members - /// /// Gets the mode of the distribution. /// @@ -226,7 +215,7 @@ namespace MathNet.Numerics.Distributions } /// - /// Computes the density of the distribution. + /// Computes the density of the distribution (PDF), i.e. dP(X <= x)/dx. /// /// The location at which to compute the density. /// the density at . @@ -236,7 +225,7 @@ namespace MathNet.Numerics.Distributions } /// - /// Computes the log density of the distribution. + /// Computes the log density of the distribution (lnPDF), i.e. ln(dP(X <= x)/dx). /// /// The location at which to compute the log density. /// the log density at . @@ -245,7 +234,15 @@ namespace MathNet.Numerics.Distributions return Math.Log(x/(_scale*_scale)) - (x*x/(2.0*_scale*_scale)); } - #endregion + /// + /// Computes the cumulative distribution (CDF) of the distribution, i.e. P(X <= x). + /// + /// The location at which to compute the cumulative distribution function. + /// the cumulative distribution at location . + public double CumulativeDistribution(double x) + { + return 1.0 - Math.Exp(-x*x/(2.0*_scale*_scale)); + } /// /// Generates a sample from the Rayleigh distribution without doing parameter checking. @@ -253,7 +250,7 @@ namespace MathNet.Numerics.Distributions /// The random number generator to use. /// The scale parameter. /// a random number from the Rayleigh distribution. - internal static double SampleUnchecked(Random rnd, double scale) + internal static double SampleUnchecked(System.Random rnd, double scale) { return scale*Math.Sqrt(-2.0*Math.Log(rnd.NextDouble())); } @@ -285,7 +282,7 @@ namespace MathNet.Numerics.Distributions /// The random number generator to use. /// The scale parameter. /// a sample from the distribution. - public static double Sample(Random rnd, double scale) + public static double Sample(System.Random rnd, double scale) { if (Control.CheckDistributionParameters && !IsValidParameterSet(scale)) { @@ -301,7 +298,7 @@ namespace MathNet.Numerics.Distributions /// The random number generator to use. /// The scale parameter. /// a sequence of samples from the distribution. - public static IEnumerable Samples(Random rnd, double scale) + public static IEnumerable Samples(System.Random rnd, double scale) { if (Control.CheckDistributionParameters && !IsValidParameterSet(scale)) { diff --git a/src/Numerics/Distributions/Continuous/Stable.cs b/src/Numerics/Distributions/Stable.cs similarity index 94% rename from src/Numerics/Distributions/Continuous/Stable.cs rename to src/Numerics/Distributions/Stable.cs index 18cdf781..1e7f651a 100644 --- a/src/Numerics/Distributions/Continuous/Stable.cs +++ b/src/Numerics/Distributions/Stable.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-2013 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 @@ -24,13 +28,14 @@ // OTHER DEALINGS IN THE SOFTWARE. // +using System; +using System.Collections.Generic; +using MathNet.Numerics.Properties; + namespace MathNet.Numerics.Distributions { - using System; - using System.Collections.Generic; - using Properties; - /// + /// Continuous Univariate Stable distribution. /// A random variable is said to be stable (or to have a stable distribution) if it has /// the property that a linear combination of two independent copies of the variable has /// the same distribution, up to location and scale parameters. @@ -67,7 +72,7 @@ namespace MathNet.Numerics.Distributions /// /// The distribution's random number generator. /// - Random _random; + System.Random _random; /// /// Initializes a new instance of the class. @@ -78,7 +83,7 @@ namespace MathNet.Numerics.Distributions /// The location parameter of the distribution. public Stable(double alpha, double beta, double scale, double location) { - _random = new Random(); + _random = new System.Random(); SetParameters(alpha, beta, scale, location); } @@ -90,9 +95,9 @@ namespace MathNet.Numerics.Distributions /// 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) + public Stable(double alpha, double beta, double scale, double location, System.Random randomSource) { - _random = randomSource ?? new Random(); + _random = randomSource ?? new System.Random(); SetParameters(alpha, beta, scale, location); } @@ -174,12 +179,10 @@ namespace MathNet.Numerics.Distributions return "Stable(" + "Stability = " + _alpha + ", Skewness = " + _beta + ", Scale = " + _scale + ", Location = " + _location + ")"; } - #region IDistribution Members - /// /// Gets or sets the random number generator which is used to draw random samples. /// - public Random RandomSource + public System.Random RandomSource { get { return _random; } set @@ -267,51 +270,6 @@ namespace MathNet.Numerics.Distributions } } - /// - /// Computes the cumulative distribution function of the distribution. - /// - /// The location at which to compute the cumulative density. - /// the cumulative density at . - /// Throws a not supported exception if Alpha != 2, (Alpha != 1 and Beta !=0), or (Alpha != 0.5 and Beta != 1) - public double CumulativeDistribution(double x) - { - if (_alpha == 2) - { - return (new Normal(_location, StdDev)).CumulativeDistribution(x); - } - - if (_alpha == 1 && _beta == 0) - { - return (new Cauchy(_location, _scale)).CumulativeDistribution(x); - } - - if (_alpha == 0.5 && _beta == 1) - { - return LevyCumulativeDistribution(_scale, _location, x); - } - - throw new NotSupportedException(); - } - - /// - /// Computes the cumulative distribution function of the Levy distribution. - /// - /// The scale parameter. - /// The location parameter. - /// The location at which to compute the cumulative density. - /// - /// the cumulative density at . - /// - static double LevyCumulativeDistribution(double scale, double location, double x) - { - // The parameters scale and location must be correct - return SpecialFunctions.Erfc(Math.Sqrt(scale/(2*(x - location)))); - } - - #endregion - - #region IContinuousDistribution Members - /// /// Gets the mode of the distribution. /// @@ -371,7 +329,7 @@ namespace MathNet.Numerics.Distributions } /// - /// Computes the density of the distribution. + /// Computes the density of the distribution (PDF), i.e. dP(X <= x)/dx. /// /// The location at which to compute the density. /// the density at . @@ -414,7 +372,7 @@ namespace MathNet.Numerics.Distributions } /// - /// Computes the log density of the distribution. + /// Computes the log density of the distribution (lnPDF), i.e. ln(dP(X <= x)/dx). /// /// The location at which to compute the log density. /// the log density at . @@ -423,7 +381,44 @@ namespace MathNet.Numerics.Distributions return Math.Log(Density(x)); } - #endregion + /// + /// Computes the cumulative distribution (CDF) of the distribution, i.e. P(X <= x). + /// + /// The location at which to compute the cumulative distribution function. + /// the cumulative distribution at location . + /// Throws a not supported exception if Alpha != 2, (Alpha != 1 and Beta !=0), or (Alpha != 0.5 and Beta != 1) + public double CumulativeDistribution(double x) + { + if (_alpha == 2) + { + return (new Normal(_location, StdDev)).CumulativeDistribution(x); + } + + if (_alpha == 1 && _beta == 0) + { + return (new Cauchy(_location, _scale)).CumulativeDistribution(x); + } + + if (_alpha == 0.5 && _beta == 1) + { + return LevyCumulativeDistribution(_scale, _location, x); + } + + throw new NotSupportedException(); + } + + /// + /// Computes the cumulative distribution function of the Levy distribution. + /// + /// The scale parameter. + /// The location parameter. + /// The location at which to compute the cumulative density. + /// the cumulative density at . + static double LevyCumulativeDistribution(double scale, double location, double x) + { + // The parameters scale and location must be correct + return SpecialFunctions.Erfc(Math.Sqrt(scale/(2*(x - location)))); + } /// /// Samples the distribution. @@ -434,7 +429,7 @@ namespace MathNet.Numerics.Distributions /// The scale parameter of the distribution. /// The location parameter of the distribution. /// a random number from the distribution. - internal static double SampleUnchecked(Random rnd, double alpha, double beta, double scale, double location) + internal static double SampleUnchecked(System.Random rnd, double alpha, double beta, double scale, double location) { var randTheta = ContinuousUniform.Sample(rnd, -Constants.PiOver2, Constants.PiOver2); var randW = Exponential.Sample(rnd, 1.0); @@ -492,7 +487,7 @@ namespace MathNet.Numerics.Distributions /// The scale parameter of the distribution. /// The location parameter of the distribution. /// a sample from the distribution. - public static double Sample(Random rnd, double alpha, double beta, double scale, double location) + public static double Sample(System.Random rnd, double alpha, double beta, double scale, double location) { if (Control.CheckDistributionParameters && !IsValidParameterSet(alpha, beta, scale, location)) { @@ -511,7 +506,7 @@ namespace MathNet.Numerics.Distributions /// The scale parameter of the distribution. /// The location parameter of the distribution. /// a sequence of samples from the distribution. - public static IEnumerable Samples(Random rnd, double alpha, double beta, double scale, double location) + public static IEnumerable Samples(System.Random rnd, double alpha, double beta, double scale, double location) { if (Control.CheckDistributionParameters && !IsValidParameterSet(location, scale, scale, location)) { @@ -524,4 +519,4 @@ namespace MathNet.Numerics.Distributions } } } -} \ No newline at end of file +} diff --git a/src/Numerics/Distributions/Continuous/StudentT.cs b/src/Numerics/Distributions/StudentT.cs similarity index 91% rename from src/Numerics/Distributions/Continuous/StudentT.cs rename to src/Numerics/Distributions/StudentT.cs index 0ca0ae24..f5955a44 100644 --- a/src/Numerics/Distributions/Continuous/StudentT.cs +++ b/src/Numerics/Distributions/StudentT.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-2013 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 @@ -24,13 +28,14 @@ // OTHER DEALINGS IN THE SOFTWARE. // +using System; +using System.Collections.Generic; +using MathNet.Numerics.Properties; + namespace MathNet.Numerics.Distributions { - using System; - using System.Collections.Generic; - using Properties; - /// + /// Continuous Univariate Student's T-distribution. /// Implements the univariate Student t-distribution. For details about this /// distribution, see /// @@ -70,7 +75,7 @@ namespace MathNet.Numerics.Distributions /// /// The distribution's random number generator. /// - Random _random; + System.Random _random; /// /// Initializes a new instance of the StudentT class. This is a Student t-distribution with location 0.0 @@ -92,7 +97,7 @@ namespace MathNet.Numerics.Distributions /// The degrees of freedom for the Student t-distribution. public StudentT(double location, double scale, double dof) { - _random = new Random(); + _random = new System.Random(); SetParameters(location, scale, dof); } @@ -105,9 +110,9 @@ namespace MathNet.Numerics.Distributions /// 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) + public StudentT(double location, double scale, double dof, System.Random randomSource) { - _random = randomSource ?? new Random(); + _random = randomSource ?? new System.Random(); SetParameters(location, scale, dof); } @@ -178,12 +183,10 @@ namespace MathNet.Numerics.Distributions set { SetParameters(_location, _scale, value); } } - #region IDistribution implementation - /// /// Gets or sets the random number generator which is used to draw random samples. /// - public Random RandomSource + public System.Random RandomSource { get { return _random; } set @@ -279,10 +282,6 @@ namespace MathNet.Numerics.Distributions } } - #endregion - - #region IContinuousDistribution implementation - /// /// Gets the mode of the Student t-distribution. /// @@ -316,7 +315,7 @@ namespace MathNet.Numerics.Distributions } /// - /// Computes the density of the Student t-distribution. + /// Computes the density of the distribution (PDF), i.e. dP(X <= x)/dx. /// /// The location at which to compute the density. /// the density at . @@ -330,13 +329,13 @@ namespace MathNet.Numerics.Distributions var d = (x - _location)/_scale; return Math.Exp(SpecialFunctions.GammaLn((_dof + 1.0)/2.0) - SpecialFunctions.GammaLn(_dof/2.0)) - *Math.Pow(1.0 + (d*d/_dof), -0.5*(_dof + 1.0)) - /Math.Sqrt(_dof*Math.PI) - /_scale; + *Math.Pow(1.0 + (d*d/_dof), -0.5*(_dof + 1.0)) + /Math.Sqrt(_dof*Math.PI) + /_scale; } /// - /// Computes the log density of the Student t-distribution. + /// Computes the log density of the distribution (lnPDF), i.e. ln(dP(X <= x)/dx). /// /// The location at which to compute the log density. /// the log density at . @@ -350,16 +349,16 @@ namespace MathNet.Numerics.Distributions var d = (x - _location)/_scale; return SpecialFunctions.GammaLn((_dof + 1.0)/2.0) - - (0.5*((_dof + 1.0)*Math.Log(1.0 + (d*d/_dof)))) - - SpecialFunctions.GammaLn(_dof/2.0) - - (0.5*Math.Log(_dof*Math.PI)) - Math.Log(_scale); + - (0.5*((_dof + 1.0)*Math.Log(1.0 + (d*d/_dof)))) + - SpecialFunctions.GammaLn(_dof/2.0) + - (0.5*Math.Log(_dof*Math.PI)) - Math.Log(_scale); } /// - /// Computes the cumulative distribution function of the Student t-distribution. + /// Computes the cumulative distribution (CDF) of the distribution, i.e. P(X <= x). /// - /// The location at which to compute the cumulative density. - /// the cumulative density at . + /// The location at which to compute the cumulative distribution function. + /// the cumulative distribution at location . public double CumulativeDistribution(double x) { // TODO JVG we can probably do a better job for Cauchy special case @@ -374,8 +373,6 @@ namespace MathNet.Numerics.Distributions return x <= _location ? ib : 1.0 - ib; } - #endregion - /// /// Samples student-t distributed random variables. /// @@ -386,7 +383,7 @@ namespace MathNet.Numerics.Distributions /// The scale of the Student t-distribution. /// The degrees of freedom for the standard student-t distribution. /// a random number from the standard student-t distribution. - internal static double SampleUnchecked(Random rnd, double location, double scale, double dof) + internal static double SampleUnchecked(System.Random rnd, double location, double scale, double dof) { var n = Normal.SampleUncheckedBoxMuller(rnd).Item1; var g = Gamma.SampleUnchecked(rnd, 0.5*dof, 0.5); @@ -422,7 +419,7 @@ namespace MathNet.Numerics.Distributions /// The scale of the Student t-distribution. /// The degrees of freedom for the Student t-distribution. /// a sample from the distribution. - public static double Sample(Random rng, double location, double scale, double dof) + public static double Sample(System.Random rng, double location, double scale, double dof) { if (Control.CheckDistributionParameters && !IsValidParameterSet(location, scale, dof)) { @@ -440,7 +437,7 @@ namespace MathNet.Numerics.Distributions /// The scale of the Student t-distribution. /// The degrees of freedom for the Student t-distribution. /// a sequence of samples from the distribution. - public static IEnumerable Samples(Random rng, double location, double scale, double dof) + public static IEnumerable Samples(System.Random rng, double location, double scale, double dof) { if (Control.CheckDistributionParameters && !IsValidParameterSet(location, scale, dof)) { diff --git a/src/Numerics/Distributions/Continuous/Weibull.cs b/src/Numerics/Distributions/Weibull.cs similarity index 92% rename from src/Numerics/Distributions/Continuous/Weibull.cs rename to src/Numerics/Distributions/Weibull.cs index f5fbbe20..085f5db3 100644 --- a/src/Numerics/Distributions/Continuous/Weibull.cs +++ b/src/Numerics/Distributions/Weibull.cs @@ -28,14 +28,15 @@ // OTHER DEALINGS IN THE SOFTWARE. // +using System; +using System.Collections.Generic; +using MathNet.Numerics.Properties; + namespace MathNet.Numerics.Distributions { - using System; - using System.Collections.Generic; - using Properties; - /// - /// Implements the Weibull distribution. For details about this distribution, see + /// Continuous Univariate Weibull distribution. + /// For details about this distribution, see /// Wikipedia - Weibull distribution. /// /// @@ -69,7 +70,7 @@ namespace MathNet.Numerics.Distributions /// /// The distribution's random number generator. /// - Random _random; + System.Random _random; /// /// Initializes a new instance of the Weibull class. @@ -78,7 +79,7 @@ namespace MathNet.Numerics.Distributions /// The inverse scale of the Weibull distribution. public Weibull(double shape, double scale) { - _random = new Random(); + _random = new System.Random(); SetParameters(shape, scale); } @@ -88,9 +89,9 @@ namespace MathNet.Numerics.Distributions /// 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) + public Weibull(double shape, double scale, System.Random randomSource) { - _random = randomSource ?? new Random(); + _random = randomSource ?? new System.Random(); SetParameters(shape, scale); } @@ -150,12 +151,10 @@ namespace MathNet.Numerics.Distributions set { SetParameters(_shape, value); } } - #region IDistribution implementation - /// /// Gets or sets the random number generator which is used to draw random samples. /// - public Random RandomSource + public System.Random RandomSource { get { return _random; } set @@ -216,10 +215,6 @@ namespace MathNet.Numerics.Distributions } } - #endregion - - #region IContinuousDistribution implementation - /// /// Gets the mode of the Weibull distribution. /// @@ -261,7 +256,7 @@ namespace MathNet.Numerics.Distributions } /// - /// Computes the density of the Weibull distribution. + /// Computes the density of the distribution (PDF), i.e. dP(X <= x)/dx. /// /// The location at which to compute the density. /// the density at . @@ -281,7 +276,7 @@ namespace MathNet.Numerics.Distributions } /// - /// Computes the log density of the Weibull distribution. + /// Computes the log density of the distribution (lnPDF), i.e. ln(dP(X <= x)/dx). /// /// The location at which to compute the log density. /// the log density at . @@ -301,10 +296,10 @@ namespace MathNet.Numerics.Distributions } /// - /// Computes the cumulative distribution function of the Weibull distribution. + /// Computes the cumulative distribution (CDF) of the distribution, i.e. P(X <= x). /// - /// The location at which to compute the cumulative density. - /// the cumulative density at . + /// The location at which to compute the cumulative distribution function. + /// the cumulative distribution at location . public double CumulativeDistribution(double x) { if (x < 0.0) @@ -315,8 +310,6 @@ namespace MathNet.Numerics.Distributions return -SpecialFunctions.ExponentialMinusOne(-Math.Pow(x, _shape)*_scalePowShapeInv); } - #endregion - /// /// Generates one sample from the Weibull distribution. This method doesn't perform /// any parameter checks. @@ -325,7 +318,7 @@ namespace MathNet.Numerics.Distributions /// The shape of the Weibull distribution. /// The scale of the Weibull distribution. /// A sample from a Weibull distributed random variable. - internal static double SampleUnchecked(Random rnd, double shape, double scale) + internal static double SampleUnchecked(System.Random rnd, double shape, double scale) { var x = rnd.NextDouble(); return scale*Math.Pow(-Math.Log(x), 1.0/shape); @@ -359,7 +352,7 @@ namespace MathNet.Numerics.Distributions /// The shape of the Weibull distribution from which to generate samples. /// The scale of the Weibull distribution from which to generate samples. /// a sample from the distribution. - public static double Sample(Random rng, double shape, double scale) + public static double Sample(System.Random rng, double shape, double scale) { if (Control.CheckDistributionParameters && !IsValidParameterSet(shape, scale)) { @@ -376,7 +369,7 @@ namespace MathNet.Numerics.Distributions /// The shape of the Weibull distribution from which to generate samples. /// The scale of the Weibull distribution from which to generate samples. /// a sequence of samples from the distribution. - public static IEnumerable Samples(Random rng, double shape, double scale) + public static IEnumerable Samples(System.Random rng, double shape, double scale) { if (Control.CheckDistributionParameters && !IsValidParameterSet(shape, scale)) { diff --git a/src/Numerics/Distributions/Multivariate/Wishart.cs b/src/Numerics/Distributions/Wishart.cs similarity index 93% rename from src/Numerics/Distributions/Multivariate/Wishart.cs rename to src/Numerics/Distributions/Wishart.cs index bb114514..6b3ed40f 100644 --- a/src/Numerics/Distributions/Multivariate/Wishart.cs +++ b/src/Numerics/Distributions/Wishart.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-2013 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 @@ -24,6 +28,7 @@ // OTHER DEALINGS IN THE SOFTWARE. // +using System; using MathNet.Numerics.LinearAlgebra; using MathNet.Numerics.LinearAlgebra.Double; using MathNet.Numerics.LinearAlgebra.Factorization; @@ -31,10 +36,8 @@ using MathNet.Numerics.Properties; namespace MathNet.Numerics.Distributions { - using System; - /// - /// This class implements functionality for the Wishart distribution. This distribution is + /// Multivariate Wishart distribution. This distribution is /// parameterized by the degrees of freedom nu and the scale matrix S. The Wishart distribution /// is the conjugate prior for the precision (inverse covariance) matrix of the multivariate /// normal distribution. @@ -65,7 +68,7 @@ namespace MathNet.Numerics.Distributions /// /// The distribution's random number generator. /// - Random _random; + System.Random _random; /// /// Initializes a new instance of the class. @@ -74,7 +77,7 @@ namespace MathNet.Numerics.Distributions /// The scale matrix for the Wishart distribution. public Wishart(double nu, Matrix s) { - _random = new Random(); + _random = new System.Random(); SetParameters(nu, s); } @@ -84,9 +87,9 @@ namespace MathNet.Numerics.Distributions /// 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) + public Wishart(double nu, Matrix s, System.Random randomSource) { - _random = randomSource ?? new Random(); + _random = randomSource ?? new System.Random(); SetParameters(nu, s); } @@ -167,7 +170,7 @@ namespace MathNet.Numerics.Distributions /// /// Gets or sets the random number generator which is used to draw random samples. /// - public Random RandomSource + public System.Random RandomSource { get { return _random; } set @@ -246,10 +249,10 @@ namespace MathNet.Numerics.Distributions } return Math.Pow(dX, (_nu - p - 1.0)/2.0) - *Math.Exp(-0.5*siX.Trace()) - /Math.Pow(2.0, _nu*p/2.0) - /Math.Pow(_chol.Determinant, _nu/2.0) - /gp; + *Math.Exp(-0.5*siX.Trace()) + /Math.Pow(2.0, _nu*p/2.0) + /Math.Pow(_chol.Determinant, _nu/2.0) + /gp; } /// @@ -274,7 +277,7 @@ namespace MathNet.Numerics.Distributions /// The degrees of freedom. /// The scale matrix. /// a sequence of samples from the distribution. - public static Matrix Sample(Random rnd, double nu, Matrix s) + public static Matrix Sample(System.Random rnd, double nu, Matrix s) { if (Control.CheckDistributionParameters && !IsValidParameterSet(nu, s)) { @@ -292,7 +295,7 @@ namespace MathNet.Numerics.Distributions /// The S parameter to use. /// The cholesky decomposition to use. /// a random number from the distribution. - static Matrix DoSample(Random rnd, double nu, Matrix s, Cholesky chol) + static Matrix DoSample(System.Random rnd, double nu, Matrix s, Cholesky chol) { var count = s.RowCount; diff --git a/src/Numerics/Distributions/Discrete/Zipf.cs b/src/Numerics/Distributions/Zipf.cs similarity index 90% rename from src/Numerics/Distributions/Discrete/Zipf.cs rename to src/Numerics/Distributions/Zipf.cs index 7d859342..41c85a79 100644 --- a/src/Numerics/Distributions/Discrete/Zipf.cs +++ b/src/Numerics/Distributions/Zipf.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-2013 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 @@ -24,13 +28,14 @@ // OTHER DEALINGS IN THE SOFTWARE. // +using System; +using System.Collections.Generic; +using MathNet.Numerics.Properties; + namespace MathNet.Numerics.Distributions { - using System; - using System.Collections.Generic; - using Properties; - /// + /// Discrete Univariate Zipf distribution. /// Zipf's law, an empirical law formulated using mathematical statistics, refers to the fact /// that many types of data studied in the physical and social sciences can be approximated with /// a Zipfian distribution, one of a family of related discrete power law probability distributions. @@ -57,7 +62,7 @@ namespace MathNet.Numerics.Distributions /// /// The distribution's random number generator. /// - Random _random; + System.Random _random; /// /// Initializes a new instance of the class. @@ -66,7 +71,7 @@ namespace MathNet.Numerics.Distributions /// The n parameter of the distribution. public Zipf(double s, int n) { - _random = new Random(); + _random = new System.Random(); SetParameters(s, n); } @@ -76,9 +81,9 @@ namespace MathNet.Numerics.Distributions /// 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) + public Zipf(double s, int n, System.Random randomSource) { - _random = randomSource ?? new Random(); + _random = randomSource ?? new System.Random(); SetParameters(s, n); } @@ -136,12 +141,10 @@ namespace MathNet.Numerics.Distributions return "Zipf(S = " + _s + ", N = " + _n + ")"; } - #region IDistribution Members - /// /// Gets or sets the random number generator which is used to draw random samples. /// - public Random RandomSource + public System.Random RandomSource { get { return _random; } set @@ -222,25 +225,6 @@ namespace MathNet.Numerics.Distributions } } - /// - /// Computes the cumulative distribution function of the distribution. - /// - /// The integer location at which to compute the cumulative density. - /// the cumulative density at . - public double CumulativeDistribution(double x) - { - if (x <= 1) - { - return 0.0; - } - - return SpecialFunctions.GeneralHarmonic((int) x, _s)/SpecialFunctions.GeneralHarmonic(_n, _s); - } - - #endregion - - #region IDiscreteDistribution Members - /// /// Gets the mode of the distribution. /// @@ -274,30 +258,39 @@ namespace MathNet.Numerics.Distributions } /// - /// Computes values of the probability mass function. + /// Computes the probability mass (PMF), i.e. P(X = x). /// /// The location in the domain where we want to evaluate the probability mass function. - /// - /// the probability mass at location . - /// + /// the probability mass at location . public double Probability(int k) { return (1.0/Math.Pow(k, _s))/SpecialFunctions.GeneralHarmonic(_n, _s); } /// - /// Computes values of the log probability mass function. + /// Computes the log probability mass (lnPMF), i.e. ln(P(X = x)). /// /// The location in the domain where we want to evaluate the log probability mass function. - /// - /// the log probability mass at location . - /// + /// the log probability mass at location . public double ProbabilityLn(int k) { return Math.Log(Probability(k)); } - #endregion + /// + /// Computes the cumulative distribution (CDF) of the distribution, i.e. P(X <= x). + /// + /// The location at which to compute the cumulative distribution function. + /// the cumulative distribution at location . + public double CumulativeDistribution(double x) + { + if (x <= 1) + { + return 0.0; + } + + return SpecialFunctions.GeneralHarmonic((int) x, _s)/SpecialFunctions.GeneralHarmonic(_n, _s); + } /// /// Generates a sample from the Zipf distribution without doing parameter checking. @@ -306,7 +299,7 @@ namespace MathNet.Numerics.Distributions /// The s parameter of the distribution. /// The n parameter of the distribution. /// a random number from the Zipf distribution. - internal static int SampleUnchecked(Random rnd, double s, int n) + internal static int SampleUnchecked(System.Random rnd, double s, int n) { var r = 0.0; while (r == 0.0) @@ -356,7 +349,7 @@ namespace MathNet.Numerics.Distributions /// The random number generator to use. /// The s parameter of the distribution. /// The n parameter of the distribution. - public static int Sample(Random rnd, double s, int n) + public static int Sample(System.Random rnd, double s, int n) { if (Control.CheckDistributionParameters && !IsValidParameterSet(s, n)) { @@ -372,7 +365,7 @@ namespace MathNet.Numerics.Distributions /// The random number generator to use. /// The s parameter of the distribution. /// The n parameter of the distribution. - public static IEnumerable Samples(Random rnd, double s, int n) + public static IEnumerable Samples(System.Random rnd, double s, int n) { if (Control.CheckDistributionParameters && !IsValidParameterSet(s, n)) { diff --git a/src/Numerics/LinearAlgebra/Complex/Solvers/Iterative/MlkBiCgStab.cs b/src/Numerics/LinearAlgebra/Complex/Solvers/Iterative/MlkBiCgStab.cs index 8bf1155d..ff4b04d0 100644 --- a/src/Numerics/LinearAlgebra/Complex/Solvers/Iterative/MlkBiCgStab.cs +++ b/src/Numerics/LinearAlgebra/Complex/Solvers/Iterative/MlkBiCgStab.cs @@ -28,14 +28,14 @@ // OTHER DEALINGS IN THE SOFTWARE. // -using MathNet.Numerics.Distributions; -using MathNet.Numerics.LinearAlgebra.Complex.Solvers.Preconditioners; -using MathNet.Numerics.LinearAlgebra.Solvers.Status; -using MathNet.Numerics.Properties; using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; +using MathNet.Numerics.Distributions; +using MathNet.Numerics.LinearAlgebra.Complex.Solvers.Preconditioners; +using MathNet.Numerics.LinearAlgebra.Solvers.Status; +using MathNet.Numerics.Properties; namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative { diff --git a/src/Numerics/LinearAlgebra/Complex32/Solvers/Iterative/MlkBiCgStab.cs b/src/Numerics/LinearAlgebra/Complex32/Solvers/Iterative/MlkBiCgStab.cs index 70a40c88..ef3cceb7 100644 --- a/src/Numerics/LinearAlgebra/Complex32/Solvers/Iterative/MlkBiCgStab.cs +++ b/src/Numerics/LinearAlgebra/Complex32/Solvers/Iterative/MlkBiCgStab.cs @@ -28,14 +28,14 @@ // OTHER DEALINGS IN THE SOFTWARE. // -using MathNet.Numerics.Distributions; -using MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Preconditioners; -using MathNet.Numerics.LinearAlgebra.Solvers.Status; -using MathNet.Numerics.Properties; using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; +using MathNet.Numerics.Distributions; +using MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Preconditioners; +using MathNet.Numerics.LinearAlgebra.Solvers.Status; +using MathNet.Numerics.Properties; namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative { diff --git a/src/Numerics/LinearAlgebra/Double/Solvers/Iterative/MlkBiCgStab.cs b/src/Numerics/LinearAlgebra/Double/Solvers/Iterative/MlkBiCgStab.cs index 9b3b3871..d01ddac1 100644 --- a/src/Numerics/LinearAlgebra/Double/Solvers/Iterative/MlkBiCgStab.cs +++ b/src/Numerics/LinearAlgebra/Double/Solvers/Iterative/MlkBiCgStab.cs @@ -28,14 +28,14 @@ // OTHER DEALINGS IN THE SOFTWARE. // -using MathNet.Numerics.Distributions; -using MathNet.Numerics.LinearAlgebra.Double.Solvers.Preconditioners; -using MathNet.Numerics.LinearAlgebra.Solvers.Status; -using MathNet.Numerics.Properties; using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; +using MathNet.Numerics.Distributions; +using MathNet.Numerics.LinearAlgebra.Double.Solvers.Preconditioners; +using MathNet.Numerics.LinearAlgebra.Solvers.Status; +using MathNet.Numerics.Properties; namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative { diff --git a/src/Numerics/LinearAlgebra/Single/Solvers/Iterative/MlkBiCgStab.cs b/src/Numerics/LinearAlgebra/Single/Solvers/Iterative/MlkBiCgStab.cs index e72bf8b0..867a35d3 100644 --- a/src/Numerics/LinearAlgebra/Single/Solvers/Iterative/MlkBiCgStab.cs +++ b/src/Numerics/LinearAlgebra/Single/Solvers/Iterative/MlkBiCgStab.cs @@ -28,13 +28,13 @@ // OTHER DEALINGS IN THE SOFTWARE. // +using System; +using System.Collections.Generic; +using System.Diagnostics; using MathNet.Numerics.Distributions; using MathNet.Numerics.LinearAlgebra.Single.Solvers.Preconditioners; using MathNet.Numerics.LinearAlgebra.Solvers.Status; using MathNet.Numerics.Properties; -using System; -using System.Collections.Generic; -using System.Diagnostics; namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative { diff --git a/src/Numerics/Numerics.csproj b/src/Numerics/Numerics.csproj index ac85c9b4..079bad4c 100644 --- a/src/Numerics/Numerics.csproj +++ b/src/Numerics/Numerics.csproj @@ -86,6 +86,40 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -140,26 +174,6 @@ - - - - - - - - - - - - - - - - - - - - @@ -378,21 +392,9 @@ - - - - - - - - - - - - @@ -475,10 +477,6 @@ Designer - - - - diff --git a/src/Numerics/Statistics/MCMC/HybridMC.cs b/src/Numerics/Statistics/MCMC/HybridMC.cs index c32d86cb..865a39e4 100644 --- a/src/Numerics/Statistics/MCMC/HybridMC.cs +++ b/src/Numerics/Statistics/MCMC/HybridMC.cs @@ -28,11 +28,13 @@ // OTHER DEALINGS IN THE SOFTWARE. // +using System; +using System.Linq; +using MathNet.Numerics.Distributions; + namespace MathNet.Numerics.Statistics.Mcmc { - using System; - using System.Linq; - using Distributions; + using Random = System.Random; /// /// A hybrid Monte Carlo sampler for multivariate distributions. diff --git a/src/Numerics/Statistics/MCMC/UnivariateHybridMC.cs b/src/Numerics/Statistics/MCMC/UnivariateHybridMC.cs index 5db6bcad..7cd8542d 100644 --- a/src/Numerics/Statistics/MCMC/UnivariateHybridMC.cs +++ b/src/Numerics/Statistics/MCMC/UnivariateHybridMC.cs @@ -28,10 +28,12 @@ // OTHER DEALINGS IN THE SOFTWARE. // +using System; +using MathNet.Numerics.Distributions; + namespace MathNet.Numerics.Statistics.Mcmc { - using System; - using Distributions; + using Random = System.Random; /// /// A hybrid Monte Carlo sampler for univariate distributions. diff --git a/src/UnitTests/DistributionTests/CommonDistributionTests.cs b/src/UnitTests/DistributionTests/CommonDistributionTests.cs index 01b2ba96..e921b6d2 100644 --- a/src/UnitTests/DistributionTests/CommonDistributionTests.cs +++ b/src/UnitTests/DistributionTests/CommonDistributionTests.cs @@ -24,15 +24,17 @@ // OTHER DEALINGS IN THE SOFTWARE. // +using System; +using System.Collections.Generic; +using System.Linq; +using MathNet.Numerics.Distributions; +using MathNet.Numerics.Random; +using MathNet.Numerics.Statistics; +using NUnit.Framework; + namespace MathNet.Numerics.UnitTests.DistributionTests { - using System; - using System.Collections.Generic; - using System.Linq; - using Distributions; - using Numerics.Random; - using NUnit.Framework; - using Statistics; + using Random = System.Random; /// /// This class will perform various tests on discrete and continuous univariate distributions. The multivariate distributions diff --git a/src/UnitTests/DistributionTests/Continuous/BetaTests.cs b/src/UnitTests/DistributionTests/Continuous/BetaTests.cs index 65fec5d4..ff5971e6 100644 --- a/src/UnitTests/DistributionTests/Continuous/BetaTests.cs +++ b/src/UnitTests/DistributionTests/Continuous/BetaTests.cs @@ -24,12 +24,14 @@ // OTHER DEALINGS IN THE SOFTWARE. // +using System; +using System.Linq; +using MathNet.Numerics.Distributions; +using NUnit.Framework; + namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous { - using System; - using System.Linq; - using Distributions; - using NUnit.Framework; + using Random = System.Random; /// /// Beta distribution tests. diff --git a/src/UnitTests/DistributionTests/Continuous/CauchyTests.cs b/src/UnitTests/DistributionTests/Continuous/CauchyTests.cs index 95e4c5de..90331e19 100644 --- a/src/UnitTests/DistributionTests/Continuous/CauchyTests.cs +++ b/src/UnitTests/DistributionTests/Continuous/CauchyTests.cs @@ -24,13 +24,13 @@ // OTHER DEALINGS IN THE SOFTWARE. // +using System; +using System.Linq; +using MathNet.Numerics.Distributions; +using NUnit.Framework; + namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous { - using System; - using System.Linq; - using Distributions; - using NUnit.Framework; - /// /// Cauchy distribution tests. /// diff --git a/src/UnitTests/DistributionTests/Continuous/ChiSquareTests.cs b/src/UnitTests/DistributionTests/Continuous/ChiSquareTests.cs index b8430b83..08635927 100644 --- a/src/UnitTests/DistributionTests/Continuous/ChiSquareTests.cs +++ b/src/UnitTests/DistributionTests/Continuous/ChiSquareTests.cs @@ -24,12 +24,14 @@ // OTHER DEALINGS IN THE SOFTWARE. // +using System; +using System.Linq; +using MathNet.Numerics.Distributions; +using NUnit.Framework; + namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous { - using System; - using System.Linq; - using Distributions; - using NUnit.Framework; + using Random = System.Random; /// /// Chi square distribution test diff --git a/src/UnitTests/DistributionTests/Continuous/ChiTests.cs b/src/UnitTests/DistributionTests/Continuous/ChiTests.cs index 44f51771..72773980 100644 --- a/src/UnitTests/DistributionTests/Continuous/ChiTests.cs +++ b/src/UnitTests/DistributionTests/Continuous/ChiTests.cs @@ -24,13 +24,13 @@ // OTHER DEALINGS IN THE SOFTWARE. // +using System; +using System.Linq; +using MathNet.Numerics.Distributions; +using NUnit.Framework; + namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous { - using System; - using System.Linq; - using Distributions; - using NUnit.Framework; - /// /// Chi distribution test /// diff --git a/src/UnitTests/DistributionTests/Continuous/ContinuousUniformTests.cs b/src/UnitTests/DistributionTests/Continuous/ContinuousUniformTests.cs index 18e1fdb1..51f72bff 100644 --- a/src/UnitTests/DistributionTests/Continuous/ContinuousUniformTests.cs +++ b/src/UnitTests/DistributionTests/Continuous/ContinuousUniformTests.cs @@ -24,12 +24,14 @@ // OTHER DEALINGS IN THE SOFTWARE. // +using System; +using System.Linq; +using MathNet.Numerics.Distributions; +using NUnit.Framework; + namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous { - using System; - using System.Linq; - using Distributions; - using NUnit.Framework; + using Random = System.Random; /// /// Continuous uniform tests. diff --git a/src/UnitTests/DistributionTests/Continuous/ErlangTests.cs b/src/UnitTests/DistributionTests/Continuous/ErlangTests.cs index c6ed9ddb..2ce6978b 100644 --- a/src/UnitTests/DistributionTests/Continuous/ErlangTests.cs +++ b/src/UnitTests/DistributionTests/Continuous/ErlangTests.cs @@ -24,13 +24,13 @@ // OTHER DEALINGS IN THE SOFTWARE. // +using System; +using System.Linq; +using MathNet.Numerics.Distributions; +using NUnit.Framework; + namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous { - using System; - using System.Linq; - using Distributions; - using NUnit.Framework; - /// /// Erlang distribution tests. /// diff --git a/src/UnitTests/DistributionTests/Continuous/ExponentialTests.cs b/src/UnitTests/DistributionTests/Continuous/ExponentialTests.cs index 4e1c5add..2659468e 100644 --- a/src/UnitTests/DistributionTests/Continuous/ExponentialTests.cs +++ b/src/UnitTests/DistributionTests/Continuous/ExponentialTests.cs @@ -24,13 +24,13 @@ // OTHER DEALINGS IN THE SOFTWARE. // +using System; +using System.Linq; +using MathNet.Numerics.Distributions; +using NUnit.Framework; + namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous { - using System; - using System.Linq; - using Distributions; - using NUnit.Framework; - /// /// Exponential distribution tests. /// diff --git a/src/UnitTests/DistributionTests/Continuous/FisherSnedecorTests.cs b/src/UnitTests/DistributionTests/Continuous/FisherSnedecorTests.cs index 916f3902..2646fbfc 100644 --- a/src/UnitTests/DistributionTests/Continuous/FisherSnedecorTests.cs +++ b/src/UnitTests/DistributionTests/Continuous/FisherSnedecorTests.cs @@ -24,13 +24,13 @@ // OTHER DEALINGS IN THE SOFTWARE. // +using System; +using System.Linq; +using MathNet.Numerics.Distributions; +using NUnit.Framework; + namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous { - using System; - using System.Linq; - using Distributions; - using NUnit.Framework; - /// /// Fisher-Snedecor distribution tests. /// diff --git a/src/UnitTests/DistributionTests/Continuous/GammaTests.cs b/src/UnitTests/DistributionTests/Continuous/GammaTests.cs index abf5269d..85df4664 100644 --- a/src/UnitTests/DistributionTests/Continuous/GammaTests.cs +++ b/src/UnitTests/DistributionTests/Continuous/GammaTests.cs @@ -24,12 +24,14 @@ // OTHER DEALINGS IN THE SOFTWARE. // +using System; +using System.Linq; +using MathNet.Numerics.Distributions; +using NUnit.Framework; + namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous { - using System; - using System.Linq; - using Distributions; - using NUnit.Framework; + using Random = System.Random; /// /// Gamma distribution tests. diff --git a/src/UnitTests/DistributionTests/Continuous/InverseGammaTests.cs b/src/UnitTests/DistributionTests/Continuous/InverseGammaTests.cs index a8744cf5..91921ebc 100644 --- a/src/UnitTests/DistributionTests/Continuous/InverseGammaTests.cs +++ b/src/UnitTests/DistributionTests/Continuous/InverseGammaTests.cs @@ -24,13 +24,13 @@ // OTHER DEALINGS IN THE SOFTWARE. // +using System; +using System.Linq; +using MathNet.Numerics.Distributions; +using NUnit.Framework; + namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous { - using System; - using System.Linq; - using Distributions; - using NUnit.Framework; - /// /// Inverse gamma distribution tests. /// diff --git a/src/UnitTests/DistributionTests/Continuous/LaplaceTests.cs b/src/UnitTests/DistributionTests/Continuous/LaplaceTests.cs index 415b522e..aaba5930 100644 --- a/src/UnitTests/DistributionTests/Continuous/LaplaceTests.cs +++ b/src/UnitTests/DistributionTests/Continuous/LaplaceTests.cs @@ -24,13 +24,13 @@ // OTHER DEALINGS IN THE SOFTWARE. // +using System; +using System.Linq; +using MathNet.Numerics.Distributions; +using NUnit.Framework; + namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous { - using System; - using System.Linq; - using Distributions; - using NUnit.Framework; - /// /// Laplace distribution tests. /// diff --git a/src/UnitTests/DistributionTests/Continuous/LogNormalTests.cs b/src/UnitTests/DistributionTests/Continuous/LogNormalTests.cs index 6a0d12c6..3edec8f8 100644 --- a/src/UnitTests/DistributionTests/Continuous/LogNormalTests.cs +++ b/src/UnitTests/DistributionTests/Continuous/LogNormalTests.cs @@ -24,12 +24,14 @@ // OTHER DEALINGS IN THE SOFTWARE. // +using System; +using System.Linq; +using MathNet.Numerics.Distributions; +using NUnit.Framework; + namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous { - using System; - using System.Linq; - using Distributions; - using NUnit.Framework; + using Random = System.Random; /// /// LogNormal distribution tests. diff --git a/src/UnitTests/DistributionTests/Continuous/NormalTests.cs b/src/UnitTests/DistributionTests/Continuous/NormalTests.cs index d1bfa5c9..fc16a6cd 100644 --- a/src/UnitTests/DistributionTests/Continuous/NormalTests.cs +++ b/src/UnitTests/DistributionTests/Continuous/NormalTests.cs @@ -24,12 +24,14 @@ // OTHER DEALINGS IN THE SOFTWARE. // +using System; +using System.Linq; +using MathNet.Numerics.Distributions; +using NUnit.Framework; + namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous { - using System; - using System.Linq; - using Distributions; - using NUnit.Framework; + using Random = System.Random; /// /// Normal distribution tests. diff --git a/src/UnitTests/DistributionTests/Continuous/ParetoTests.cs b/src/UnitTests/DistributionTests/Continuous/ParetoTests.cs index 3ded5929..7cb1bfc4 100644 --- a/src/UnitTests/DistributionTests/Continuous/ParetoTests.cs +++ b/src/UnitTests/DistributionTests/Continuous/ParetoTests.cs @@ -24,13 +24,13 @@ // OTHER DEALINGS IN THE SOFTWARE. // +using System; +using System.Linq; +using MathNet.Numerics.Distributions; +using NUnit.Framework; + namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous { - using System; - using System.Linq; - using Distributions; - using NUnit.Framework; - /// /// Pareto distribution tests. /// diff --git a/src/UnitTests/DistributionTests/Continuous/RayleighTests.cs b/src/UnitTests/DistributionTests/Continuous/RayleighTests.cs index 92ec996f..4f212d14 100644 --- a/src/UnitTests/DistributionTests/Continuous/RayleighTests.cs +++ b/src/UnitTests/DistributionTests/Continuous/RayleighTests.cs @@ -24,13 +24,13 @@ // OTHER DEALINGS IN THE SOFTWARE. // +using System; +using System.Linq; +using MathNet.Numerics.Distributions; +using NUnit.Framework; + namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous { - using System; - using System.Linq; - using Distributions; - using NUnit.Framework; - /// /// Rayleigh distribution tests. /// diff --git a/src/UnitTests/DistributionTests/Continuous/StableTests.cs b/src/UnitTests/DistributionTests/Continuous/StableTests.cs index 07651bed..bf9a0a8c 100644 --- a/src/UnitTests/DistributionTests/Continuous/StableTests.cs +++ b/src/UnitTests/DistributionTests/Continuous/StableTests.cs @@ -24,13 +24,13 @@ // OTHER DEALINGS IN THE SOFTWARE. // +using System; +using System.Linq; +using MathNet.Numerics.Distributions; +using NUnit.Framework; + namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous { - using System; - using System.Linq; - using Distributions; - using NUnit.Framework; - /// /// Stable distribution tests. /// diff --git a/src/UnitTests/DistributionTests/Continuous/StudentTTests.cs b/src/UnitTests/DistributionTests/Continuous/StudentTTests.cs index 03c97796..8448ef2f 100644 --- a/src/UnitTests/DistributionTests/Continuous/StudentTTests.cs +++ b/src/UnitTests/DistributionTests/Continuous/StudentTTests.cs @@ -24,12 +24,14 @@ // OTHER DEALINGS IN THE SOFTWARE. // +using System; +using System.Linq; +using MathNet.Numerics.Distributions; +using NUnit.Framework; + namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous { - using System; - using System.Linq; - using Distributions; - using NUnit.Framework; + using Random = System.Random; /// /// StudentT distribution tests. diff --git a/src/UnitTests/DistributionTests/Continuous/WeibullTests.cs b/src/UnitTests/DistributionTests/Continuous/WeibullTests.cs index 01963185..852e0066 100644 --- a/src/UnitTests/DistributionTests/Continuous/WeibullTests.cs +++ b/src/UnitTests/DistributionTests/Continuous/WeibullTests.cs @@ -24,12 +24,14 @@ // OTHER DEALINGS IN THE SOFTWARE. // +using System; +using System.Linq; +using MathNet.Numerics.Distributions; +using NUnit.Framework; + namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous { - using System; - using System.Linq; - using Distributions; - using NUnit.Framework; + using Random = System.Random; /// /// Weibull distribution tests. diff --git a/src/UnitTests/DistributionTests/Multivariate/DirichletTests.cs b/src/UnitTests/DistributionTests/Multivariate/DirichletTests.cs index 98fae20f..009360bc 100644 --- a/src/UnitTests/DistributionTests/Multivariate/DirichletTests.cs +++ b/src/UnitTests/DistributionTests/Multivariate/DirichletTests.cs @@ -24,12 +24,14 @@ // OTHER DEALINGS IN THE SOFTWARE. // +using System; +using System.Linq; +using MathNet.Numerics.Distributions; +using NUnit.Framework; + namespace MathNet.Numerics.UnitTests.DistributionTests.Multivariate { - using System; - using System.Linq; - using Distributions; - using NUnit.Framework; + using Random = System.Random; /// /// Dirichlet distribution tests diff --git a/src/UnitTests/IntegralTransformsTests/FourierTest.cs b/src/UnitTests/IntegralTransformsTests/FourierTest.cs index 102f210d..cf325024 100644 --- a/src/UnitTests/IntegralTransformsTests/FourierTest.cs +++ b/src/UnitTests/IntegralTransformsTests/FourierTest.cs @@ -24,15 +24,17 @@ // OTHER DEALINGS IN THE SOFTWARE. // +using System; +using System.Numerics; +using MathNet.Numerics.Distributions; +using MathNet.Numerics.IntegralTransforms; +using MathNet.Numerics.IntegralTransforms.Algorithms; +using MathNet.Numerics.Signals; +using NUnit.Framework; + namespace MathNet.Numerics.UnitTests.IntegralTransformsTests { - using System; - using System.Numerics; - using Distributions; - using IntegralTransforms; - using IntegralTransforms.Algorithms; - using NUnit.Framework; - using Signals; + using Random = System.Random; /// /// Fourier test. diff --git a/src/UnitTests/IntegralTransformsTests/HartleyTest.cs b/src/UnitTests/IntegralTransformsTests/HartleyTest.cs index be0ec043..06451e29 100644 --- a/src/UnitTests/IntegralTransformsTests/HartleyTest.cs +++ b/src/UnitTests/IntegralTransformsTests/HartleyTest.cs @@ -24,15 +24,17 @@ // OTHER DEALINGS IN THE SOFTWARE. // +using System; +using System.Numerics; +using MathNet.Numerics.Distributions; +using MathNet.Numerics.IntegralTransforms; +using MathNet.Numerics.IntegralTransforms.Algorithms; +using MathNet.Numerics.Signals; +using NUnit.Framework; + namespace MathNet.Numerics.UnitTests.IntegralTransformsTests { - using System; - using System.Numerics; - using Distributions; - using IntegralTransforms; - using IntegralTransforms.Algorithms; - using NUnit.Framework; - using Signals; + using Random = System.Random; /// /// Hartley tests. diff --git a/src/UnitTests/IntegralTransformsTests/InverseTransformTest.cs b/src/UnitTests/IntegralTransformsTests/InverseTransformTest.cs index ca0fb6f8..e766d385 100644 --- a/src/UnitTests/IntegralTransformsTests/InverseTransformTest.cs +++ b/src/UnitTests/IntegralTransformsTests/InverseTransformTest.cs @@ -24,15 +24,17 @@ // OTHER DEALINGS IN THE SOFTWARE. // +using System; +using System.Numerics; +using MathNet.Numerics.Distributions; +using MathNet.Numerics.IntegralTransforms; +using MathNet.Numerics.IntegralTransforms.Algorithms; +using MathNet.Numerics.Signals; +using NUnit.Framework; + namespace MathNet.Numerics.UnitTests.IntegralTransformsTests { - using System; - using System.Numerics; - using Distributions; - using IntegralTransforms; - using IntegralTransforms.Algorithms; - using NUnit.Framework; - using Signals; + using Random = System.Random; /// /// Inverse Transform test. diff --git a/src/UnitTests/IntegralTransformsTests/MatchingNaiveTransformTest.cs b/src/UnitTests/IntegralTransformsTests/MatchingNaiveTransformTest.cs index f4a8af5d..9ba7996b 100644 --- a/src/UnitTests/IntegralTransformsTests/MatchingNaiveTransformTest.cs +++ b/src/UnitTests/IntegralTransformsTests/MatchingNaiveTransformTest.cs @@ -24,15 +24,17 @@ // OTHER DEALINGS IN THE SOFTWARE. // +using System; +using System.Numerics; +using MathNet.Numerics.Distributions; +using MathNet.Numerics.IntegralTransforms; +using MathNet.Numerics.IntegralTransforms.Algorithms; +using MathNet.Numerics.Signals; +using NUnit.Framework; + namespace MathNet.Numerics.UnitTests.IntegralTransformsTests { - using System; - using System.Numerics; - using Distributions; - using IntegralTransforms; - using IntegralTransforms.Algorithms; - using NUnit.Framework; - using Signals; + using Random = System.Random; /// /// Matching Naive transform tests. diff --git a/src/UnitTests/IntegralTransformsTests/ParsevalTheoremTest.cs b/src/UnitTests/IntegralTransformsTests/ParsevalTheoremTest.cs index 2447aa58..821cb8e4 100644 --- a/src/UnitTests/IntegralTransformsTests/ParsevalTheoremTest.cs +++ b/src/UnitTests/IntegralTransformsTests/ParsevalTheoremTest.cs @@ -24,17 +24,18 @@ // OTHER DEALINGS IN THE SOFTWARE. // +using System.Linq; +using System.Numerics; +using MathNet.Numerics.Distributions; +using MathNet.Numerics.IntegralTransforms; +using MathNet.Numerics.IntegralTransforms.Algorithms; +using MathNet.Numerics.Signals; +using MathNet.Numerics.Statistics; +using NUnit.Framework; + namespace MathNet.Numerics.UnitTests.IntegralTransformsTests { - using System; - using System.Linq; - using System.Numerics; - using Distributions; - using IntegralTransforms; - using IntegralTransforms.Algorithms; - using NUnit.Framework; - using Signals; - using Statistics; + using Random = System.Random; /// /// Parseval theorem verification tests. diff --git a/src/UnitTests/InterpolationTests/LinearInterpolationCase.cs b/src/UnitTests/InterpolationTests/LinearInterpolationCase.cs index a3d19295..c6301b10 100644 --- a/src/UnitTests/InterpolationTests/LinearInterpolationCase.cs +++ b/src/UnitTests/InterpolationTests/LinearInterpolationCase.cs @@ -28,11 +28,11 @@ // OTHER DEALINGS IN THE SOFTWARE. // +using MathNet.Numerics.Distributions; +using MathNet.Numerics.Random; + namespace MathNet.Numerics.UnitTests.InterpolationTests { - using Distributions; - using Numerics.Random; - /// /// LinearInterpolation test case. /// diff --git a/src/UnitTests/LinearAlgebraProviderTests/Complex/LinearAlgebraProviderTests.cs b/src/UnitTests/LinearAlgebraProviderTests/Complex/LinearAlgebraProviderTests.cs index faff6d2e..1aa911c3 100644 --- a/src/UnitTests/LinearAlgebraProviderTests/Complex/LinearAlgebraProviderTests.cs +++ b/src/UnitTests/LinearAlgebraProviderTests/Complex/LinearAlgebraProviderTests.cs @@ -28,14 +28,14 @@ // OTHER DEALINGS IN THE SOFTWARE. // +using System; +using System.Collections.Generic; using MathNet.Numerics.Distributions; using MathNet.Numerics.LinearAlgebra; using MathNet.Numerics.LinearAlgebra.Complex; using MathNet.Numerics.LinearAlgebra.Factorization; using MathNet.Numerics.Providers.LinearAlgebra; using NUnit.Framework; -using System; -using System.Collections.Generic; namespace MathNet.Numerics.UnitTests.LinearAlgebraProviderTests.Complex { diff --git a/src/UnitTests/LinearAlgebraProviderTests/Complex32/LinearAlgebraProviderTests.cs b/src/UnitTests/LinearAlgebraProviderTests/Complex32/LinearAlgebraProviderTests.cs index 3408bc95..91ea6a57 100644 --- a/src/UnitTests/LinearAlgebraProviderTests/Complex32/LinearAlgebraProviderTests.cs +++ b/src/UnitTests/LinearAlgebraProviderTests/Complex32/LinearAlgebraProviderTests.cs @@ -28,14 +28,14 @@ // OTHER DEALINGS IN THE SOFTWARE. // +using System; +using System.Collections.Generic; using MathNet.Numerics.Distributions; using MathNet.Numerics.LinearAlgebra; using MathNet.Numerics.LinearAlgebra.Complex32; using MathNet.Numerics.LinearAlgebra.Factorization; using MathNet.Numerics.Providers.LinearAlgebra; using NUnit.Framework; -using System; -using System.Collections.Generic; namespace MathNet.Numerics.UnitTests.LinearAlgebraProviderTests.Complex32 { diff --git a/src/UnitTests/LinearAlgebraProviderTests/Double/LinearAlgebraProviderTests.cs b/src/UnitTests/LinearAlgebraProviderTests/Double/LinearAlgebraProviderTests.cs index e5075cda..3128006b 100644 --- a/src/UnitTests/LinearAlgebraProviderTests/Double/LinearAlgebraProviderTests.cs +++ b/src/UnitTests/LinearAlgebraProviderTests/Double/LinearAlgebraProviderTests.cs @@ -28,14 +28,14 @@ // OTHER DEALINGS IN THE SOFTWARE. // +using System; +using System.Collections.Generic; using MathNet.Numerics.Distributions; using MathNet.Numerics.LinearAlgebra; using MathNet.Numerics.LinearAlgebra.Double; using MathNet.Numerics.LinearAlgebra.Factorization; using MathNet.Numerics.Providers.LinearAlgebra; using NUnit.Framework; -using System; -using System.Collections.Generic; namespace MathNet.Numerics.UnitTests.LinearAlgebraProviderTests.Double { diff --git a/src/UnitTests/LinearAlgebraProviderTests/Single/LinearAlgebraProviderTests.cs b/src/UnitTests/LinearAlgebraProviderTests/Single/LinearAlgebraProviderTests.cs index 1b38404e..ce4e2369 100644 --- a/src/UnitTests/LinearAlgebraProviderTests/Single/LinearAlgebraProviderTests.cs +++ b/src/UnitTests/LinearAlgebraProviderTests/Single/LinearAlgebraProviderTests.cs @@ -28,14 +28,14 @@ // OTHER DEALINGS IN THE SOFTWARE. // +using System; +using System.Collections.Generic; using MathNet.Numerics.Distributions; using MathNet.Numerics.LinearAlgebra; using MathNet.Numerics.LinearAlgebra.Factorization; using MathNet.Numerics.LinearAlgebra.Single; using MathNet.Numerics.Providers.LinearAlgebra; using NUnit.Framework; -using System; -using System.Collections.Generic; namespace MathNet.Numerics.UnitTests.LinearAlgebraProviderTests.Single { diff --git a/src/UnitTests/LinearAlgebraTests/Complex/MatrixLoader.cs b/src/UnitTests/LinearAlgebraTests/Complex/MatrixLoader.cs index 49771454..df319b06 100644 --- a/src/UnitTests/LinearAlgebraTests/Complex/MatrixLoader.cs +++ b/src/UnitTests/LinearAlgebraTests/Complex/MatrixLoader.cs @@ -28,12 +28,12 @@ // OTHER DEALINGS IN THE SOFTWARE. // +using System.Collections.Generic; using MathNet.Numerics.Distributions; using MathNet.Numerics.LinearAlgebra; using MathNet.Numerics.LinearAlgebra.Complex; using MathNet.Numerics.Random; using NUnit.Framework; -using System.Collections.Generic; namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex { diff --git a/src/UnitTests/LinearAlgebraTests/Complex/MatrixStructureTheory.cs b/src/UnitTests/LinearAlgebraTests/Complex/MatrixStructureTheory.cs index 819e5112..7768eca4 100644 --- a/src/UnitTests/LinearAlgebraTests/Complex/MatrixStructureTheory.cs +++ b/src/UnitTests/LinearAlgebraTests/Complex/MatrixStructureTheory.cs @@ -28,12 +28,12 @@ // OTHER DEALINGS IN THE SOFTWARE. // +using System.Linq; using MathNet.Numerics.Distributions; using MathNet.Numerics.LinearAlgebra; using MathNet.Numerics.LinearAlgebra.Complex; using MathNet.Numerics.Random; using NUnit.Framework; -using System.Linq; namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex { diff --git a/src/UnitTests/LinearAlgebraTests/Complex/MatrixTests.Arithmetic.cs b/src/UnitTests/LinearAlgebraTests/Complex/MatrixTests.Arithmetic.cs index be9012c1..59868bea 100644 --- a/src/UnitTests/LinearAlgebraTests/Complex/MatrixTests.Arithmetic.cs +++ b/src/UnitTests/LinearAlgebraTests/Complex/MatrixTests.Arithmetic.cs @@ -24,11 +24,11 @@ // OTHER DEALINGS IN THE SOFTWARE. // +using System; using MathNet.Numerics.Distributions; using MathNet.Numerics.LinearAlgebra; using MathNet.Numerics.LinearAlgebra.Complex; using NUnit.Framework; -using System; namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex { diff --git a/src/UnitTests/LinearAlgebraTests/Complex/VectorTests.cs b/src/UnitTests/LinearAlgebraTests/Complex/VectorTests.cs index f62df2ea..ecad7d94 100644 --- a/src/UnitTests/LinearAlgebraTests/Complex/VectorTests.cs +++ b/src/UnitTests/LinearAlgebraTests/Complex/VectorTests.cs @@ -28,14 +28,14 @@ // OTHER DEALINGS IN THE SOFTWARE. // -using MathNet.Numerics.Distributions; -using MathNet.Numerics.LinearAlgebra; -using MathNet.Numerics.LinearAlgebra.Complex; -using NUnit.Framework; using System; using System.Collections; using System.Collections.Generic; using System.Linq; +using MathNet.Numerics.Distributions; +using MathNet.Numerics.LinearAlgebra; +using MathNet.Numerics.LinearAlgebra.Complex; +using NUnit.Framework; namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex { diff --git a/src/UnitTests/LinearAlgebraTests/Complex32/MatrixLoader.cs b/src/UnitTests/LinearAlgebraTests/Complex32/MatrixLoader.cs index 254aee61..075f617f 100644 --- a/src/UnitTests/LinearAlgebraTests/Complex32/MatrixLoader.cs +++ b/src/UnitTests/LinearAlgebraTests/Complex32/MatrixLoader.cs @@ -28,12 +28,12 @@ // OTHER DEALINGS IN THE SOFTWARE. // +using System.Collections.Generic; using MathNet.Numerics.Distributions; using MathNet.Numerics.LinearAlgebra; using MathNet.Numerics.LinearAlgebra.Complex32; using MathNet.Numerics.Random; using NUnit.Framework; -using System.Collections.Generic; namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32 { diff --git a/src/UnitTests/LinearAlgebraTests/Complex32/MatrixStructureTheory.cs b/src/UnitTests/LinearAlgebraTests/Complex32/MatrixStructureTheory.cs index 28fa7e72..1a2eb3bb 100644 --- a/src/UnitTests/LinearAlgebraTests/Complex32/MatrixStructureTheory.cs +++ b/src/UnitTests/LinearAlgebraTests/Complex32/MatrixStructureTheory.cs @@ -28,12 +28,12 @@ // OTHER DEALINGS IN THE SOFTWARE. // +using System.Linq; using MathNet.Numerics.Distributions; using MathNet.Numerics.LinearAlgebra; using MathNet.Numerics.LinearAlgebra.Complex32; using MathNet.Numerics.Random; using NUnit.Framework; -using System.Linq; namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32 { diff --git a/src/UnitTests/LinearAlgebraTests/Complex32/MatrixTests.Arithmetic.cs b/src/UnitTests/LinearAlgebraTests/Complex32/MatrixTests.Arithmetic.cs index fdef2f4f..23e03903 100644 --- a/src/UnitTests/LinearAlgebraTests/Complex32/MatrixTests.Arithmetic.cs +++ b/src/UnitTests/LinearAlgebraTests/Complex32/MatrixTests.Arithmetic.cs @@ -24,11 +24,11 @@ // OTHER DEALINGS IN THE SOFTWARE. // +using System; using MathNet.Numerics.Distributions; using MathNet.Numerics.LinearAlgebra; using MathNet.Numerics.LinearAlgebra.Complex32; using NUnit.Framework; -using System; namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32 { diff --git a/src/UnitTests/LinearAlgebraTests/Complex32/VectorTests.cs b/src/UnitTests/LinearAlgebraTests/Complex32/VectorTests.cs index 8d5e55f8..b04ee180 100644 --- a/src/UnitTests/LinearAlgebraTests/Complex32/VectorTests.cs +++ b/src/UnitTests/LinearAlgebraTests/Complex32/VectorTests.cs @@ -28,14 +28,14 @@ // OTHER DEALINGS IN THE SOFTWARE. // -using MathNet.Numerics.Distributions; -using MathNet.Numerics.LinearAlgebra; -using MathNet.Numerics.LinearAlgebra.Complex32; -using NUnit.Framework; using System; using System.Collections; using System.Collections.Generic; using System.Linq; +using MathNet.Numerics.Distributions; +using MathNet.Numerics.LinearAlgebra; +using MathNet.Numerics.LinearAlgebra.Complex32; +using NUnit.Framework; namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32 { diff --git a/src/UnitTests/LinearAlgebraTests/Double/MatrixLoader.cs b/src/UnitTests/LinearAlgebraTests/Double/MatrixLoader.cs index f4a5f052..955d2af6 100644 --- a/src/UnitTests/LinearAlgebraTests/Double/MatrixLoader.cs +++ b/src/UnitTests/LinearAlgebraTests/Double/MatrixLoader.cs @@ -28,12 +28,12 @@ // OTHER DEALINGS IN THE SOFTWARE. // +using System.Collections.Generic; using MathNet.Numerics.Distributions; using MathNet.Numerics.LinearAlgebra; using MathNet.Numerics.LinearAlgebra.Double; using MathNet.Numerics.Random; using NUnit.Framework; -using System.Collections.Generic; namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double { diff --git a/src/UnitTests/LinearAlgebraTests/Double/MatrixStructureTheory.cs b/src/UnitTests/LinearAlgebraTests/Double/MatrixStructureTheory.cs index 67d6cb14..043ef7cc 100644 --- a/src/UnitTests/LinearAlgebraTests/Double/MatrixStructureTheory.cs +++ b/src/UnitTests/LinearAlgebraTests/Double/MatrixStructureTheory.cs @@ -28,12 +28,12 @@ // OTHER DEALINGS IN THE SOFTWARE. // +using System.Linq; using MathNet.Numerics.Distributions; using MathNet.Numerics.LinearAlgebra; using MathNet.Numerics.LinearAlgebra.Double; using MathNet.Numerics.Random; using NUnit.Framework; -using System.Linq; namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double { diff --git a/src/UnitTests/LinearAlgebraTests/Double/MatrixTests.Arithmetic.cs b/src/UnitTests/LinearAlgebraTests/Double/MatrixTests.Arithmetic.cs index 274baa43..0ecda380 100644 --- a/src/UnitTests/LinearAlgebraTests/Double/MatrixTests.Arithmetic.cs +++ b/src/UnitTests/LinearAlgebraTests/Double/MatrixTests.Arithmetic.cs @@ -24,11 +24,11 @@ // OTHER DEALINGS IN THE SOFTWARE. // +using System; using MathNet.Numerics.Distributions; using MathNet.Numerics.LinearAlgebra; using MathNet.Numerics.LinearAlgebra.Double; using NUnit.Framework; -using System; namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double { diff --git a/src/UnitTests/LinearAlgebraTests/Double/VectorTests.cs b/src/UnitTests/LinearAlgebraTests/Double/VectorTests.cs index 27fa7c9a..ce671dd7 100644 --- a/src/UnitTests/LinearAlgebraTests/Double/VectorTests.cs +++ b/src/UnitTests/LinearAlgebraTests/Double/VectorTests.cs @@ -28,13 +28,13 @@ // OTHER DEALINGS IN THE SOFTWARE. // +using System; +using System.Collections; +using System.Collections.Generic; using MathNet.Numerics.Distributions; using MathNet.Numerics.LinearAlgebra; using MathNet.Numerics.LinearAlgebra.Double; using NUnit.Framework; -using System; -using System.Collections; -using System.Collections.Generic; namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double { diff --git a/src/UnitTests/LinearAlgebraTests/Single/MatrixLoader.cs b/src/UnitTests/LinearAlgebraTests/Single/MatrixLoader.cs index 064d8290..35f7e820 100644 --- a/src/UnitTests/LinearAlgebraTests/Single/MatrixLoader.cs +++ b/src/UnitTests/LinearAlgebraTests/Single/MatrixLoader.cs @@ -28,12 +28,12 @@ // OTHER DEALINGS IN THE SOFTWARE. // +using System.Collections.Generic; using MathNet.Numerics.Distributions; using MathNet.Numerics.LinearAlgebra; using MathNet.Numerics.LinearAlgebra.Single; using MathNet.Numerics.Random; using NUnit.Framework; -using System.Collections.Generic; namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single { diff --git a/src/UnitTests/LinearAlgebraTests/Single/MatrixStructureTheory.cs b/src/UnitTests/LinearAlgebraTests/Single/MatrixStructureTheory.cs index 3ca2e0b1..6275ead2 100644 --- a/src/UnitTests/LinearAlgebraTests/Single/MatrixStructureTheory.cs +++ b/src/UnitTests/LinearAlgebraTests/Single/MatrixStructureTheory.cs @@ -28,12 +28,12 @@ // OTHER DEALINGS IN THE SOFTWARE. // +using System.Linq; using MathNet.Numerics.Distributions; using MathNet.Numerics.LinearAlgebra; using MathNet.Numerics.LinearAlgebra.Single; using MathNet.Numerics.Random; using NUnit.Framework; -using System.Linq; namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single { diff --git a/src/UnitTests/LinearAlgebraTests/Single/MatrixTests.Arithmetic.cs b/src/UnitTests/LinearAlgebraTests/Single/MatrixTests.Arithmetic.cs index 845512c9..7358a313 100644 --- a/src/UnitTests/LinearAlgebraTests/Single/MatrixTests.Arithmetic.cs +++ b/src/UnitTests/LinearAlgebraTests/Single/MatrixTests.Arithmetic.cs @@ -24,14 +24,14 @@ // OTHER DEALINGS IN THE SOFTWARE. // +using System; +using MathNet.Numerics.Distributions; +using MathNet.Numerics.LinearAlgebra; +using MathNet.Numerics.LinearAlgebra.Single; +using NUnit.Framework; + namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single { - using Distributions; - using LinearAlgebra; - using LinearAlgebra.Single; - using NUnit.Framework; - using System; - /// /// Abstract class with the common set of matrix tests /// diff --git a/src/UnitTests/LinearAlgebraTests/Single/VectorTests.cs b/src/UnitTests/LinearAlgebraTests/Single/VectorTests.cs index fa1e76d5..ab175db0 100644 --- a/src/UnitTests/LinearAlgebraTests/Single/VectorTests.cs +++ b/src/UnitTests/LinearAlgebraTests/Single/VectorTests.cs @@ -28,13 +28,13 @@ // OTHER DEALINGS IN THE SOFTWARE. // +using System; +using System.Collections; +using System.Collections.Generic; using MathNet.Numerics.Distributions; using MathNet.Numerics.LinearAlgebra; using MathNet.Numerics.LinearAlgebra.Single; using NUnit.Framework; -using System; -using System.Collections; -using System.Collections.Generic; namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single { diff --git a/src/UnitTests/StatisticsTests/MCMCTests/HybridMCTest.cs b/src/UnitTests/StatisticsTests/MCMCTests/HybridMCTest.cs index 5b7c24c1..dd55ebe3 100644 --- a/src/UnitTests/StatisticsTests/MCMCTests/HybridMCTest.cs +++ b/src/UnitTests/StatisticsTests/MCMCTests/HybridMCTest.cs @@ -29,10 +29,11 @@ // using System; -using NUnit.Framework; +using MathNet.Numerics.Distributions; using MathNet.Numerics.Statistics; using MathNet.Numerics.Statistics.Mcmc; using MathNet.Numerics.Statistics.Mcmc.Diagnostics; +using NUnit.Framework; namespace MathNet.Numerics.UnitTests.StatisticsTests.McmcTests { @@ -42,7 +43,7 @@ namespace MathNet.Numerics.UnitTests.StatisticsTests.McmcTests [TestFixture] public class HybridMCTest { - private readonly Distributions.Normal _normal = new Distributions.Normal(0, 1); + private readonly Normal _normal = new Normal(0, 1); /// /// Testing the constructor to make sure that RandomSource is diff --git a/src/UnitTests/StatisticsTests/MCMCTests/MCMCDiagnosticsTest.cs b/src/UnitTests/StatisticsTests/MCMCTests/MCMCDiagnosticsTest.cs index 3e2df90f..99075ee3 100644 --- a/src/UnitTests/StatisticsTests/MCMCTests/MCMCDiagnosticsTest.cs +++ b/src/UnitTests/StatisticsTests/MCMCTests/MCMCDiagnosticsTest.cs @@ -29,10 +29,10 @@ // using System; -using NUnit.Framework; -using MathNet.Numerics.Statistics; using MathNet.Numerics.Distributions; +using MathNet.Numerics.Statistics; using MathNet.Numerics.Statistics.Mcmc.Diagnostics; +using NUnit.Framework; namespace MathNet.Numerics.UnitTests.StatisticsTests.McmcTests { diff --git a/src/UnitTests/StatisticsTests/MCMCTests/MetropolisHastingsSamplerTests.cs b/src/UnitTests/StatisticsTests/MCMCTests/MetropolisHastingsSamplerTests.cs index d4b10e47..089fdd36 100644 --- a/src/UnitTests/StatisticsTests/MCMCTests/MetropolisHastingsSamplerTests.cs +++ b/src/UnitTests/StatisticsTests/MCMCTests/MetropolisHastingsSamplerTests.cs @@ -28,13 +28,15 @@ // OTHER DEALINGS IN THE SOFTWARE. // +using System; +using MathNet.Numerics.Distributions; +using MathNet.Numerics.Random; +using MathNet.Numerics.Statistics.Mcmc; +using NUnit.Framework; + namespace MathNet.Numerics.UnitTests.StatisticsTests.McmcTests { - using System; - using Distributions; - using Numerics.Random; - using NUnit.Framework; - using Statistics.Mcmc; + using Random = System.Random; /// /// Metropolis hastings sampler tests. @@ -57,7 +59,7 @@ namespace MathNet.Numerics.UnitTests.StatisticsTests.McmcTests }; Assert.IsNotNull(ms.RandomSource); - ms.RandomSource = new Random(); + ms.RandomSource = new System.Random(); Assert.IsNotNull(ms.RandomSource); } diff --git a/src/UnitTests/StatisticsTests/MCMCTests/MetropolisSamplerTests.cs b/src/UnitTests/StatisticsTests/MCMCTests/MetropolisSamplerTests.cs index 85b88f20..e7112393 100644 --- a/src/UnitTests/StatisticsTests/MCMCTests/MetropolisSamplerTests.cs +++ b/src/UnitTests/StatisticsTests/MCMCTests/MetropolisSamplerTests.cs @@ -28,13 +28,15 @@ // OTHER DEALINGS IN THE SOFTWARE. // +using System; +using MathNet.Numerics.Distributions; +using MathNet.Numerics.Random; +using MathNet.Numerics.Statistics.Mcmc; +using NUnit.Framework; + namespace MathNet.Numerics.UnitTests.StatisticsTests.McmcTests { - using System; - using Distributions; - using Numerics.Random; - using NUnit.Framework; - using Statistics.Mcmc; + using Random = System.Random; /// /// Metropolis sampler tests. diff --git a/src/UnitTests/StatisticsTests/MCMCTests/RejectionSamplerTests.cs b/src/UnitTests/StatisticsTests/MCMCTests/RejectionSamplerTests.cs index 199ea215..ae11a3e7 100644 --- a/src/UnitTests/StatisticsTests/MCMCTests/RejectionSamplerTests.cs +++ b/src/UnitTests/StatisticsTests/MCMCTests/RejectionSamplerTests.cs @@ -28,14 +28,14 @@ // OTHER DEALINGS IN THE SOFTWARE. // +using System; +using MathNet.Numerics.Distributions; +using MathNet.Numerics.Random; +using MathNet.Numerics.Statistics.Mcmc; +using NUnit.Framework; + namespace MathNet.Numerics.UnitTests.StatisticsTests.McmcTests { - using System; - using Distributions; - using Numerics.Random; - using NUnit.Framework; - using Statistics.Mcmc; - /// /// Rejection sampler tests. /// diff --git a/src/UnitTests/StatisticsTests/MCMCTests/UnivariateHybridMCTest.cs b/src/UnitTests/StatisticsTests/MCMCTests/UnivariateHybridMCTest.cs index 0388753f..27238180 100644 --- a/src/UnitTests/StatisticsTests/MCMCTests/UnivariateHybridMCTest.cs +++ b/src/UnitTests/StatisticsTests/MCMCTests/UnivariateHybridMCTest.cs @@ -30,14 +30,13 @@ using System; using MathNet.Numerics.Distributions; -using NUnit.Framework; +using MathNet.Numerics.Statistics; using MathNet.Numerics.Statistics.Mcmc; using MathNet.Numerics.Statistics.Mcmc.Diagnostics; -using MathNet.Numerics.Statistics; +using NUnit.Framework; namespace MathNet.Numerics.UnitTests.StatisticsTests.McmcTests { - /// /// Test for the UnivariateHybridMC. /// diff --git a/src/UnitTests/StatisticsTests/StatisticsTests.cs b/src/UnitTests/StatisticsTests/StatisticsTests.cs index b249970d..5132dbdc 100644 --- a/src/UnitTests/StatisticsTests/StatisticsTests.cs +++ b/src/UnitTests/StatisticsTests/StatisticsTests.cs @@ -28,15 +28,16 @@ // OTHER DEALINGS IN THE SOFTWARE. // +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using MathNet.Numerics.Distributions; using MathNet.Numerics.Random; +using NUnit.Framework; namespace MathNet.Numerics.UnitTests.StatisticsTests { - using System; - using System.Collections.Generic; - using System.IO; - using System.Linq; - using NUnit.Framework; using Statistics; /// @@ -565,7 +566,7 @@ namespace MathNet.Numerics.UnitTests.StatisticsTests public void StabilityMeanVariance() { // Test around 10^9, potential stability issues - var gaussian = new Distributions.Normal(1e+9, 2, new MersenneTwister(100)); + var gaussian = new 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);