diff --git a/src/Examples/ContinuousDistributions/ContinuousUniformDistribution.cs b/src/Examples/ContinuousDistributions/ContinuousUniformDistribution.cs index bfb2d11e..cdd71e7c 100644 --- a/src/Examples/ContinuousDistributions/ContinuousUniformDistribution.cs +++ b/src/Examples/ContinuousDistributions/ContinuousUniformDistribution.cs @@ -65,7 +65,7 @@ namespace Examples.ContinuousDistributionsExamples { // 1. Initialize the new instance of the ContinuousUniform distribution class with default parameters. var continuousUniform = new ContinuousUniform(); - Console.WriteLine(@"1. Initialize the new instance of the ContinuousUniform distribution class with parameters Lower = {0}, Upper = {1}", continuousUniform.Lower, continuousUniform.Upper); + Console.WriteLine(@"1. Initialize the new instance of the ContinuousUniform distribution class with parameters Lower = {0}, Upper = {1}", continuousUniform.LowerBound, continuousUniform.UpperBound); Console.WriteLine(); // 2. Distributuion properties: @@ -131,8 +131,8 @@ namespace Examples.ContinuousDistributionsExamples // 5. Generate 100000 samples of the ContinuousUniform(2, 10) distribution and display histogram Console.WriteLine(@"5. Generate 100000 samples of the ContinuousUniform(2, 10) distribution and display histogram"); - continuousUniform.Upper = 10; - continuousUniform.Lower = 2; + continuousUniform.UpperBound = 10; + continuousUniform.LowerBound = 2; for (var i = 0; i < data.Length; i++) { data[i] = continuousUniform.Sample(); diff --git a/src/Examples/ContinuousDistributions/ExponentialDistribution.cs b/src/Examples/ContinuousDistributions/ExponentialDistribution.cs index 5e3b83c3..e8522103 100644 --- a/src/Examples/ContinuousDistributions/ExponentialDistribution.cs +++ b/src/Examples/ContinuousDistributions/ExponentialDistribution.cs @@ -65,7 +65,7 @@ namespace Examples.ContinuousDistributionsExamples { // 1. Initialize the new instance of the Exponential distribution class with parameter Lambda = 1. var exponential = new Exponential(1); - Console.WriteLine(@"1. Initialize the new instance of the Exponential distribution class with parameter Lambda = {0}", exponential.Lambda); + Console.WriteLine(@"1. Initialize the new instance of the Exponential distribution class with parameter Lambda = {0}", exponential.Rate); Console.WriteLine(); // 2. Distributuion properties: @@ -131,7 +131,7 @@ namespace Examples.ContinuousDistributionsExamples // 5. Generate 100000 samples of the Exponential(9) distribution and display histogram Console.WriteLine(@"5. Generate 100000 samples of the Exponential(9) distribution and display histogram"); - exponential.Lambda = 9; + exponential.Rate = 9; for (var i = 0; i < data.Length; i++) { data[i] = exponential.Sample(); @@ -142,7 +142,7 @@ namespace Examples.ContinuousDistributionsExamples // 6. Generate 100000 samples of the Exponential(0.01) distribution and display histogram Console.WriteLine(@"6. Generate 100000 samples of the Exponential(0.01) distribution and display histogram"); - exponential.Lambda = 0.01; + exponential.Rate = 0.01; for (var i = 0; i < data.Length; i++) { data[i] = exponential.Sample(); diff --git a/src/Numerics/Distributions/Bernoulli.cs b/src/Numerics/Distributions/Bernoulli.cs index 95ad2137..77a8a4ce 100644 --- a/src/Numerics/Distributions/Bernoulli.cs +++ b/src/Numerics/Distributions/Bernoulli.cs @@ -109,21 +109,21 @@ namespace MathNet.Numerics.Distributions } /// - /// Gets or sets the random number generator which is used to draw random samples. + /// Gets or sets the probability of generating a one. /// - public System.Random RandomSource + public double P { - get { return _random; } - set { _random = value ?? new System.Random(); } + get { return _p; } + set { SetParameters(value); } } /// - /// Gets or sets the probability of generating a one. + /// Gets or sets the random number generator which is used to draw random samples. /// - public double P + public System.Random RandomSource { - get { return _p; } - set { SetParameters(value); } + get { return _random; } + set { _random = value ?? new System.Random(); } } /// diff --git a/src/Numerics/Distributions/Beta.cs b/src/Numerics/Distributions/Beta.cs index d4bba871..0945af2f 100644 --- a/src/Numerics/Distributions/Beta.cs +++ b/src/Numerics/Distributions/Beta.cs @@ -1,4 +1,4 @@ -// +// // Math.NET Numerics, part of the Math.NET Project // http://numerics.mathdotnet.com // http://github.com/mathnet/mathnet-numerics @@ -61,8 +61,8 @@ namespace MathNet.Numerics.Distributions /// /// Initializes a new instance of the Beta class. /// - /// The a shape parameter of the Beta distribution. - /// The b shape parameter of the Beta distribution. + /// The α shape parameter of the Beta distribution. + /// The β shape parameter of the Beta distribution. /// If any of the Beta parameters are negative. public Beta(double a, double b) { @@ -73,8 +73,8 @@ namespace MathNet.Numerics.Distributions /// /// Initializes a new instance of the Beta class. /// - /// The a shape parameter of the Beta distribution. - /// The b shape parameter of the Beta distribution. + /// The α shape parameter of the Beta distribution. + /// The β 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, System.Random randomSource) @@ -89,14 +89,14 @@ namespace MathNet.Numerics.Distributions /// A string representation of the Beta distribution. public override string ToString() { - return "Beta(A = " + _shapeA + ", B = " + _shapeB + ")"; + return "Beta(α = " + _shapeA + ", β = " + _shapeB + ")"; } /// /// Checks whether the parameters of the distribution are valid. /// - /// The a shape parameter of the Beta distribution. - /// The b shape parameter of the Beta distribution. + /// The α shape parameter of the Beta distribution. + /// The β shape parameter of the Beta distribution. /// true when the parameters are valid, false otherwise. static bool IsValidParameterSet(double a, double b) { @@ -106,8 +106,8 @@ namespace MathNet.Numerics.Distributions /// /// Sets the parameters of the distribution after checking their validity. /// - /// The a shape parameter of the Beta distribution. - /// The b shape parameter of the Beta distribution. + /// The α shape parameter of the Beta distribution. + /// The β shape parameter of the Beta distribution. /// When the parameters don't pass the function. void SetParameters(double a, double b) { @@ -121,16 +121,7 @@ namespace MathNet.Numerics.Distributions } /// - /// Gets or sets the random number generator which is used to draw random samples. - /// - public System.Random RandomSource - { - get { return _random; } - set { _random = value ?? new System.Random(); } - } - - /// - /// Gets or sets the A shape parameter of the Beta distribution. + /// Gets or sets the α shape parameter of the Beta distribution. /// public double A { @@ -139,7 +130,7 @@ namespace MathNet.Numerics.Distributions } /// - /// Gets or sets the B shape parameter of the Beta distribution. + /// Gets or sets the β shape parameter of the Beta distribution. /// public double B { @@ -147,6 +138,15 @@ namespace MathNet.Numerics.Distributions set { SetParameters(_shapeA, value); } } + /// + /// Gets or sets the random number generator which is used to draw random samples. + /// + public System.Random RandomSource + { + get { return _random; } + set { _random = value ?? new System.Random(); } + } + /// /// Gets the mean of the Beta distribution. /// @@ -524,8 +524,8 @@ namespace MathNet.Numerics.Distributions /// Samples Beta distributed random variables by sampling two Gamma variables and normalizing. /// /// The random number generator to use. - /// The A shape parameter. - /// The B shape parameter. + /// The α shape parameter of the Beta distribution. + /// The β shape parameter of the Beta distribution. /// a random number from the Beta distribution. internal static double SampleUnchecked(System.Random rnd, double a, double b) { @@ -559,8 +559,8 @@ namespace MathNet.Numerics.Distributions /// Generates a sample from the distribution. /// /// The random number generator to use. - /// The a shape parameter of the Beta distribution. - /// The b shape parameter of the Beta distribution. + /// The α shape parameter of the Beta distribution. + /// The β shape parameter of the Beta distribution. /// a sample from the distribution. public static double Sample(System.Random rnd, double a, double b) { @@ -576,8 +576,8 @@ namespace MathNet.Numerics.Distributions /// Generates a sequence of samples from the distribution. /// /// The random number generator to use. - /// The a shape parameter of the Beta distribution. - /// The b shape parameter of the Beta distribution. + /// The α shape parameter of the Beta distribution. + /// The β shape parameter of the Beta distribution. /// a sequence of samples from the distribution. public static IEnumerable Samples(System.Random rnd, double a, double b) { diff --git a/src/Numerics/Distributions/Binomial.cs b/src/Numerics/Distributions/Binomial.cs index 8721d9f3..9eec7bef 100644 --- a/src/Numerics/Distributions/Binomial.cs +++ b/src/Numerics/Distributions/Binomial.cs @@ -49,20 +49,13 @@ namespace MathNet.Numerics.Distributions { System.Random _random; - /// - /// Success probability in each trial. - /// double _p; - - /// - /// The number of trials. - /// int _trials; /// /// Initializes a new instance of the Binomial class. /// - /// The success probability of a trial. + /// The success probability in each trial. /// The number of trials. /// If is not in the interval [0.0,1.0]. /// If is negative. @@ -75,7 +68,7 @@ namespace MathNet.Numerics.Distributions /// /// Initializes a new instance of the Binomial class. /// - /// The success probability of a trial. + /// The success probability in each trial. /// The number of trials. /// The random number generator which is used to draw random samples. /// If is not in the interval [0.0,1.0]. @@ -125,16 +118,7 @@ namespace MathNet.Numerics.Distributions } /// - /// Gets or sets the random number generator which is used to draw random samples. - /// - public System.Random RandomSource - { - get { return _random; } - set { _random = value ?? new System.Random(); } - } - - /// - /// Gets or sets the success probability. + /// Gets or sets the success probability in each trial. /// public double P { @@ -151,6 +135,15 @@ namespace MathNet.Numerics.Distributions set { SetParameters(_p, value); } } + /// + /// Gets or sets the random number generator which is used to draw random samples. + /// + public System.Random RandomSource + { + get { return _random; } + set { _random = value ?? new System.Random(); } + } + /// /// Gets the mean of the distribution. /// diff --git a/src/Numerics/Distributions/Categorical.cs b/src/Numerics/Distributions/Categorical.cs index 5b9617dc..e5da163b 100644 --- a/src/Numerics/Distributions/Categorical.cs +++ b/src/Numerics/Distributions/Categorical.cs @@ -192,23 +192,22 @@ namespace MathNet.Numerics.Distributions } /// - /// Gets or sets the random number generator which is used to draw random samples. + /// Gets or sets the probability mass vector (non-negative ratios) of the multinomial. /// - public System.Random RandomSource + /// Sometimes the normalized probability vector cannot be represented exactly in a floating point representation. + public double[] P { - get { return _random; } - set { _random = value ?? new System.Random(); } + get { return (double[])_pmfNormalized.Clone(); } + set { SetParameters(value); } } /// - /// Gets or sets the normalized probability vector of the multinomial. + /// Gets or sets the random number generator which is used to draw random samples. /// - /// Sometimes the normalized probability vector cannot be represented - /// exactly in a floating point representation. - public double[] P + public System.Random RandomSource { - get { return (double[]) _pmfNormalized.Clone(); } - set { SetParameters(value); } + get { return _random; } + set { _random = value ?? new System.Random(); } } /// diff --git a/src/Numerics/Distributions/Cauchy.cs b/src/Numerics/Distributions/Cauchy.cs index 28689843..512a852c 100644 --- a/src/Numerics/Distributions/Cauchy.cs +++ b/src/Numerics/Distributions/Cauchy.cs @@ -33,7 +33,7 @@ namespace MathNet.Numerics.Distributions /// /// Continuous Univariate Cauchy distribution. /// The Cauchy distribution is a symmetric continuous probability distribution. For details about this distribution, see - /// Wikipedia - Cauchy distribution. + /// Wikipedia - Cauchy distribution. /// /// The distribution will use the by default. /// Users can get/set the random number generator by using the property. @@ -44,6 +44,7 @@ namespace MathNet.Numerics.Distributions { System.Random _random; + double _location; double _scale; /// @@ -56,8 +57,8 @@ namespace MathNet.Numerics.Distributions /// /// Initializes a new instance of the class. /// - /// The location parameter for the distribution. - /// The scale parameter for the distribution. + /// The location (x0) of the distribution. + /// The scale (γ) of the distribution. /// If is negative. public Cauchy(double location, double scale) { @@ -68,8 +69,8 @@ namespace MathNet.Numerics.Distributions /// /// Initializes a new instance of the class. /// - /// The location parameter for the distribution. - /// The scale parameter for the distribution. + /// The location (x0) of the distribution. + /// The scale (γ) of the distribution. /// The random number generator which is used to draw random samples. /// If is negative. public Cauchy(double location, double scale, System.Random randomSource) @@ -84,14 +85,14 @@ namespace MathNet.Numerics.Distributions /// a string representation of the distribution. public override string ToString() { - return "Cauchy(Location = " + Median + ", Scale = " + _scale + ")"; + return "Cauchy(x0 = " + _location + ", γ = " + _scale + ")"; } /// /// Checks whether the parameters of the distribution are valid. /// - /// Location parameter. - /// Scale parameter. Must be greater than 0. + /// The location (x0) of the distribution. + /// The scale (γ) of the distribution. Must be greater than 0. /// True when the parameters are valid, false otherwise. static bool IsValidParameterSet(double location, double scale) { @@ -101,8 +102,8 @@ namespace MathNet.Numerics.Distributions /// /// Sets the parameters of the distribution after checking their validity. /// - /// Location parameter. - /// Scale parameter. Must be greater than 0. + /// The location (x0) of the distribution. + /// The scale (γ) of the distribution. Must be greater than 0. /// When the parameters don't pass the function. void SetParameters(double location, double scale) { @@ -111,37 +112,36 @@ namespace MathNet.Numerics.Distributions throw new ArgumentOutOfRangeException(Resources.InvalidDistributionParameters); } - Median = location; + _location = location; _scale = scale; } /// - /// Gets or sets the random number generator which is used to draw random samples. - /// - public System.Random RandomSource - { - get { return _random; } - set { _random = value ?? new System.Random(); } - } - - /// - /// Gets or sets the location parameter of the distribution. + /// Gets or sets the location (x0) of the distribution. /// public double Location { - get { return Median; } + get { return _location; } set { SetParameters(value, _scale); } } /// - /// Gets or sets the scale parameter of the distribution. + /// Gets or sets the scale (γ) of the distribution. /// public double Scale { get { return _scale; } - set { SetParameters(Median, value); } + set { SetParameters(_location, value); } } + /// + /// Gets or sets the random number generator which is used to draw random samples. + /// + public System.Random RandomSource + { + get { return _random; } + set { _random = value ?? new System.Random(); } + } /// /// Gets the mean of the distribution. @@ -188,13 +188,16 @@ namespace MathNet.Numerics.Distributions /// public double Mode { - get { return Median; } + get { return _location; } } /// /// Gets the median of the distribution. /// - public double Median { get; private set; } + public double Median + { + get { return _location; } + } /// /// Gets the minimum of the distribution. @@ -219,7 +222,7 @@ namespace MathNet.Numerics.Distributions /// the density at . public double Density(double x) { - return 1.0/(Constants.Pi*_scale*(1.0 + (((x - Median)/_scale)*((x - Median)/_scale)))); + return 1.0/(Constants.Pi*_scale*(1.0 + (((x - _location)/_scale)*((x - _location)/_scale)))); } /// @@ -229,7 +232,7 @@ namespace MathNet.Numerics.Distributions /// the log density at . public double DensityLn(double x) { - return -Math.Log(Constants.Pi*_scale*(1.0 + (((x - Median)/_scale)*((x - Median)/_scale)))); + return -Math.Log(Constants.Pi*_scale*(1.0 + (((x - _location)/_scale)*((x - _location)/_scale)))); } /// @@ -239,15 +242,15 @@ namespace MathNet.Numerics.Distributions /// the cumulative distribution at location . public double CumulativeDistribution(double x) { - return ((1.0/Constants.Pi)*Math.Atan((x - Median)/_scale)) + 0.5; + return ((1.0/Constants.Pi)*Math.Atan((x - _location)/_scale)) + 0.5; } /// /// Samples the distribution. /// /// The random number generator to use. - /// The location shape parameter. - /// The scale parameter. + /// The location (x0) of the distribution. + /// The scale (γ) of the distribution. /// a random number from the distribution. internal static double SampleUnchecked(System.Random rnd, double location, double scale) { @@ -261,7 +264,7 @@ namespace MathNet.Numerics.Distributions /// A random number from this distribution. public double Sample() { - return SampleUnchecked(RandomSource, Median, _scale); + return SampleUnchecked(RandomSource, _location, _scale); } /// @@ -272,7 +275,7 @@ namespace MathNet.Numerics.Distributions { while (true) { - yield return SampleUnchecked(RandomSource, Median, _scale); + yield return SampleUnchecked(RandomSource, _location, _scale); } } @@ -280,8 +283,8 @@ namespace MathNet.Numerics.Distributions /// Generates a sample from the distribution. /// /// The random number generator to use. - /// The location shape parameter. - /// The scale parameter. + /// The location (x0) of the distribution. + /// The scale (γ) of the distribution. /// a sample from the distribution. public static double Sample(System.Random rnd, double location, double scale) { @@ -297,8 +300,8 @@ namespace MathNet.Numerics.Distributions /// Generates a sequence of samples from the distribution. /// /// The random number generator to use. - /// The location shape parameter. - /// The scale parameter. + /// The location (x0) of the distribution. + /// The scale (γ) of the distribution. /// a sequence of samples from the distribution. public static IEnumerable Samples(System.Random rnd, double location, double scale) { diff --git a/src/Numerics/Distributions/Chi.cs b/src/Numerics/Distributions/Chi.cs index 98123961..0dee8af3 100644 --- a/src/Numerics/Distributions/Chi.cs +++ b/src/Numerics/Distributions/Chi.cs @@ -50,10 +50,7 @@ namespace MathNet.Numerics.Distributions { System.Random _random; - /// - /// Keeps track of the degrees of freedom for the Chi distribution. - /// - double _dof; + double _freedom; /// /// Initializes a new instance of the class. @@ -82,7 +79,7 @@ namespace MathNet.Numerics.Distributions /// a string representation of the distribution. public override string ToString() { - return "Chi(DoF = " + _dof + ")"; + return "Chi(DoF = " + _freedom + ")"; } /// @@ -107,25 +104,25 @@ namespace MathNet.Numerics.Distributions throw new ArgumentOutOfRangeException(Resources.InvalidDistributionParameters); } - _dof = dof; + _freedom = dof; } /// - /// Gets or sets the random number generator which is used to draw random samples. + /// Gets or sets the degrees of freedom of the Chi distribution. /// - public System.Random RandomSource + public double DegreesOfFreedom { - get { return _random; } - set { _random = value ?? new System.Random(); } + get { return _freedom; } + set { SetParameters(value); } } /// - /// Gets or sets the degrees of freedom of the Chi distribution. + /// Gets or sets the random number generator which is used to draw random samples. /// - public double DegreesOfFreedom + public System.Random RandomSource { - get { return _dof; } - set { SetParameters(value); } + get { return _random; } + set { _random = value ?? new System.Random(); } } /// @@ -133,7 +130,7 @@ namespace MathNet.Numerics.Distributions /// public double Mean { - get { return Constants.Sqrt2*(SpecialFunctions.Gamma((_dof + 1.0)/2.0)/SpecialFunctions.Gamma(_dof/2.0)); } + get { return Constants.Sqrt2*(SpecialFunctions.Gamma((_freedom + 1.0)/2.0)/SpecialFunctions.Gamma(_freedom/2.0)); } } /// @@ -141,7 +138,7 @@ namespace MathNet.Numerics.Distributions /// public double Variance { - get { return _dof - (Mean*Mean); } + get { return _freedom - (Mean*Mean); } } /// @@ -157,7 +154,7 @@ namespace MathNet.Numerics.Distributions /// public double Entropy { - get { return SpecialFunctions.GammaLn(_dof/2.0) + ((_dof - Math.Log(2) - ((_dof - 1.0)*SpecialFunctions.DiGamma(_dof/2.0)))/2.0); } + get { return SpecialFunctions.GammaLn(_freedom/2.0) + ((_freedom - Math.Log(2) - ((_freedom - 1.0)*SpecialFunctions.DiGamma(_freedom/2.0)))/2.0); } } /// @@ -179,12 +176,12 @@ namespace MathNet.Numerics.Distributions { get { - if (_dof < 1) + if (_freedom < 1) { throw new NotSupportedException(); } - return Math.Sqrt(_dof - 1.0); + return Math.Sqrt(_freedom - 1.0); } } @@ -219,7 +216,7 @@ namespace MathNet.Numerics.Distributions /// the density at . public double Density(double x) { - return (Math.Pow(2.0, 1.0 - (_dof/2.0))*Math.Pow(x, _dof - 1.0)*Math.Exp(-x*x/2.0))/SpecialFunctions.Gamma(_dof/2.0); + return (Math.Pow(2.0, 1.0 - (_freedom/2.0))*Math.Pow(x, _freedom - 1.0)*Math.Exp(-x*x/2.0))/SpecialFunctions.Gamma(_freedom/2.0); } /// @@ -229,7 +226,7 @@ namespace MathNet.Numerics.Distributions /// the log density at . public double DensityLn(double x) { - 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); + return ((1.0 - (_freedom/2.0))*Math.Log(2.0)) + ((_freedom - 1.0)*Math.Log(x)) - (x*x/2.0) - SpecialFunctions.GammaLn(_freedom/2.0); } /// @@ -239,7 +236,7 @@ namespace MathNet.Numerics.Distributions /// 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); + return SpecialFunctions.GammaLowerIncomplete(_freedom/2.0, x*x/2.0)/SpecialFunctions.Gamma(_freedom/2.0); } /// @@ -265,7 +262,7 @@ namespace MathNet.Numerics.Distributions /// a sample from the distribution. public double Sample() { - return SampleUnchecked(RandomSource, (int) _dof); + return SampleUnchecked(RandomSource, (int) _freedom); } /// @@ -274,7 +271,7 @@ namespace MathNet.Numerics.Distributions /// a sequence of samples from the distribution. public IEnumerable Samples() { - var dof = (int) _dof; + var dof = (int) _freedom; while (true) { yield return SampleUnchecked(RandomSource, dof); diff --git a/src/Numerics/Distributions/ChiSquare.cs b/src/Numerics/Distributions/ChiSquare.cs index a52670cf..9b15e809 100644 --- a/src/Numerics/Distributions/ChiSquare.cs +++ b/src/Numerics/Distributions/ChiSquare.cs @@ -48,6 +48,8 @@ namespace MathNet.Numerics.Distributions { System.Random _random; + double _freedom; + /// /// Initializes a new instance of the class. /// @@ -75,7 +77,7 @@ namespace MathNet.Numerics.Distributions /// a string representation of the distribution. public override string ToString() { - return "ChiSquare(DoF = " + Mean + ")"; + return "ChiSquare(DoF = " + _freedom + ")"; } /// @@ -100,38 +102,41 @@ namespace MathNet.Numerics.Distributions throw new ArgumentOutOfRangeException(Resources.InvalidDistributionParameters); } - Mean = dof; + _freedom = dof; } /// - /// Gets or sets the random number generator which is used to draw random samples. + /// Gets or sets the degrees of freedom of the ChiSquare distribution. /// - public System.Random RandomSource + public double DegreesOfFreedom { - get { return _random; } - set { _random = value ?? new System.Random(); } + get { return _freedom; } + set { SetParameters(value); } } /// - /// Gets or sets the degrees of freedom of the ChiSquare distribution. + /// Gets or sets the random number generator which is used to draw random samples. /// - public double DegreesOfFreedom + public System.Random RandomSource { - get { return Mean; } - set { SetParameters(value); } + get { return _random; } + set { _random = value ?? new System.Random(); } } /// /// Gets the mean of the distribution. /// - public double Mean { get; private set; } + public double Mean + { + get { return _freedom; } + } /// /// Gets the variance of the distribution. /// public double Variance { - get { return 2.0*Mean; } + get { return 2.0*_freedom; } } /// @@ -139,7 +144,7 @@ namespace MathNet.Numerics.Distributions /// public double StdDev { - get { return Math.Sqrt(2.0*Mean); } + get { return Math.Sqrt(2.0 * _freedom); } } /// @@ -147,7 +152,7 @@ namespace MathNet.Numerics.Distributions /// public double Entropy { - get { return (Mean/2.0) + Math.Log(2.0*SpecialFunctions.Gamma(Mean/2.0)) + ((1.0 - (Mean/2.0))*SpecialFunctions.DiGamma(Mean/2.0)); } + get { return (_freedom/2.0) + Math.Log(2.0*SpecialFunctions.Gamma(_freedom/2.0)) + ((1.0 - (_freedom/2.0))*SpecialFunctions.DiGamma(_freedom/2.0)); } } /// @@ -155,7 +160,7 @@ namespace MathNet.Numerics.Distributions /// public double Skewness { - get { return Math.Sqrt(8.0/Mean); } + get { return Math.Sqrt(8.0 / _freedom); } } /// @@ -163,7 +168,7 @@ namespace MathNet.Numerics.Distributions /// public double Mode { - get { return Mean - 2.0; } + get { return _freedom - 2.0; } } /// @@ -171,7 +176,7 @@ namespace MathNet.Numerics.Distributions /// public double Median { - get { return Mean - (2.0/3.0); } + get { return _freedom - (2.0 / 3.0); } } /// @@ -197,7 +202,7 @@ namespace MathNet.Numerics.Distributions /// the density at . public double Density(double x) { - return (Math.Pow(x, (Mean/2.0) - 1.0)*Math.Exp(-x/2.0))/(Math.Pow(2.0, Mean/2.0)*SpecialFunctions.Gamma(Mean/2.0)); + return (Math.Pow(x, (_freedom / 2.0) - 1.0) * Math.Exp(-x / 2.0)) / (Math.Pow(2.0, _freedom / 2.0) * SpecialFunctions.Gamma(_freedom / 2.0)); } /// @@ -207,7 +212,7 @@ namespace MathNet.Numerics.Distributions /// the log density at . public double DensityLn(double x) { - return (-x/2.0) + (((Mean/2.0) - 1.0)*Math.Log(x)) - ((Mean/2.0)*Math.Log(2)) - SpecialFunctions.GammaLn(Mean/2.0); + return (-x / 2.0) + (((_freedom / 2.0) - 1.0) * Math.Log(x)) - ((_freedom / 2.0) * Math.Log(2)) - SpecialFunctions.GammaLn(_freedom / 2.0); } /// @@ -217,7 +222,7 @@ namespace MathNet.Numerics.Distributions /// the cumulative distribution at location . public double CumulativeDistribution(double x) { - return SpecialFunctions.GammaLowerIncomplete(Mean/2.0, x/2.0)/SpecialFunctions.Gamma(Mean/2.0); + return SpecialFunctions.GammaLowerIncomplete(_freedom / 2.0, x / 2.0) / SpecialFunctions.Gamma(_freedom / 2.0); } /// @@ -250,7 +255,7 @@ namespace MathNet.Numerics.Distributions /// a sample from the distribution. public double Sample() { - return SampleUnchecked(RandomSource, Mean); + return SampleUnchecked(RandomSource, _freedom); } /// @@ -261,7 +266,7 @@ namespace MathNet.Numerics.Distributions { while (true) { - yield return SampleUnchecked(RandomSource, Mean); + yield return SampleUnchecked(RandomSource, _freedom); } } diff --git a/src/Numerics/Distributions/ContinuousUniform.cs b/src/Numerics/Distributions/ContinuousUniform.cs index bc587a89..ef0bf0d2 100644 --- a/src/Numerics/Distributions/ContinuousUniform.cs +++ b/src/Numerics/Distributions/ContinuousUniform.cs @@ -48,14 +48,7 @@ namespace MathNet.Numerics.Distributions { System.Random _random; - /// - /// The distribution's lower bound. - /// double _lower; - - /// - /// The distribution's upper bound. - /// double _upper; /// @@ -127,19 +120,10 @@ namespace MathNet.Numerics.Distributions _upper = upper; } - /// - /// Gets or sets the random number generator which is used to draw random samples. - /// - public System.Random RandomSource - { - get { return _random; } - set { _random = value ?? new System.Random(); } - } - /// /// Gets or sets the lower bound of the distribution. /// - public double Lower + public double LowerBound { get { return _lower; } set { SetParameters(value, _upper); } @@ -148,12 +132,21 @@ namespace MathNet.Numerics.Distributions /// /// Gets or sets the upper bound of the distribution. /// - public double Upper + public double UpperBound { get { return _upper; } set { SetParameters(_lower, value); } } + /// + /// Gets or sets the random number generator which is used to draw random samples. + /// + public System.Random RandomSource + { + get { return _random; } + set { _random = value ?? new System.Random(); } + } + /// /// Gets the mean of the distribution. /// diff --git a/src/Numerics/Distributions/ConwayMaxwellPoisson.cs b/src/Numerics/Distributions/ConwayMaxwellPoisson.cs index 237b85fb..20958af2 100644 --- a/src/Numerics/Distributions/ConwayMaxwellPoisson.cs +++ b/src/Numerics/Distributions/ConwayMaxwellPoisson.cs @@ -55,11 +55,8 @@ namespace MathNet.Numerics.Distributions { System.Random _random; - /// - /// Since many properties of the distribution can only be computed approximately, the tolerance - /// level specifies how much error we accept. - /// - const double Tolerance = 1e-12; + double _lambda; + double _nu; /// /// The mean of the distribution. @@ -77,20 +74,16 @@ namespace MathNet.Numerics.Distributions double _z = double.MinValue; /// - /// The lambda parameter. - /// - double _lambda; - - /// - /// The nu parameter. + /// Since many properties of the distribution can only be computed approximately, the tolerance + /// level specifies how much error we accept. /// - double _nu; + const double Tolerance = 1e-12; /// /// Initializes a new instance of the class. /// - /// The lambda parameter. - /// The nu parameter. + /// The lambda (λ) parameter. + /// The nu (ν) parameter. public ConwayMaxwellPoisson(double lambda, double nu) { _random = new System.Random(); @@ -100,8 +93,8 @@ namespace MathNet.Numerics.Distributions /// /// Initializes a new instance of the class. /// - /// The lambda parameter. - /// The nu parameter. + /// The lambda (λ) parameter. + /// The nu (ν) parameter. /// The random number generator which is used to draw random samples. public ConwayMaxwellPoisson(double lambda, double nu, System.Random randomSource) { @@ -112,19 +105,17 @@ namespace MathNet.Numerics.Distributions /// /// Returns a that represents this instance. /// - /// - /// A that represents this instance. - /// + /// A that represents this instance. public override string ToString() { - return "ConwayMaxwellPoisson(Lambda = " + _lambda + ", Nu = " + _nu + ")"; + return "ConwayMaxwellPoisson(λ = " + _lambda + ", ν = " + _nu + ")"; } /// /// Checks whether the parameters of the distribution are valid. /// - /// The lambda parameter. - /// The nu parameter. + /// The lambda (λ) parameter. + /// The nu (ν) parameter. /// true when the parameters are valid, false otherwise. static bool IsValidParameterSet(double lambda, double nu) { @@ -134,8 +125,8 @@ namespace MathNet.Numerics.Distributions /// /// Sets the parameters of the distribution after checking their validity. /// - /// The lambda parameter. - /// The nu parameter. + /// The lambda (λ) parameter. + /// The nu (ν) parameter. /// When the parameters don't pass the function. void SetParameters(double lambda, double nu) { @@ -149,16 +140,7 @@ namespace MathNet.Numerics.Distributions } /// - /// Gets or sets the random number generator which is used to draw random samples. - /// - public System.Random RandomSource - { - get { return _random; } - set { _random = value ?? new System.Random(); } - } - - /// - /// Gets or sets the lambda parameter. + /// Gets or sets the lambda (λ) parameter. /// /// The value of the lambda parameter. public double Lambda @@ -168,15 +150,24 @@ namespace MathNet.Numerics.Distributions } /// - /// Gets or sets the Nu parameter. + /// Gets or sets the DegreeOfFreedom (ν) parameter. /// - /// The value of the Nu parameter. + /// The value of the DegreeOfFreedom parameter. public double Nu { get { return _nu; } set { SetParameters(_lambda, value); } } + /// + /// Gets or sets the random number generator which is used to draw random samples. + /// + public System.Random RandomSource + { + get { return _random; } + set { _random = value ?? new System.Random(); } + } + /// /// Gets the mean of the distribution. /// @@ -454,8 +445,8 @@ namespace MathNet.Numerics.Distributions /// Returns one trials from the distribution. /// /// The random number generator to use. - /// The lambda parameter - /// The nu parameter. + /// The lambda (λ) parameter. + /// The nu (ν) parameter. /// The z parameter. /// /// One sample from the distribution implied by , , and . @@ -504,8 +495,8 @@ namespace MathNet.Numerics.Distributions /// Samples a random variable. /// /// The random number generator to use. - /// The lambda parameter - /// The nu parameter. + /// The lambda (λ) parameter. + /// The nu (ν) parameter. public static int Sample(System.Random rnd, double lambda, double nu) { if (Control.CheckDistributionParameters && !IsValidParameterSet(lambda, nu)) @@ -521,8 +512,8 @@ namespace MathNet.Numerics.Distributions /// Samples a sequence of this random variable. /// /// The random number generator to use. - /// The lambda parameter - /// The nu parameter. + /// The lambda (λ) parameter. + /// The nu (ν) parameter. public static IEnumerable Samples(System.Random rnd, double lambda, double nu) { if (Control.CheckDistributionParameters && !IsValidParameterSet(lambda, nu)) diff --git a/src/Numerics/Distributions/Dirichlet.cs b/src/Numerics/Distributions/Dirichlet.cs index bd178dd7..200b5ba3 100644 --- a/src/Numerics/Distributions/Dirichlet.cs +++ b/src/Numerics/Distributions/Dirichlet.cs @@ -47,9 +47,6 @@ namespace MathNet.Numerics.Distributions { System.Random _random; - /// - /// The Dirichlet distribution parameters. - /// double[] _alpha; /// @@ -167,6 +164,15 @@ namespace MathNet.Numerics.Distributions _alpha = (double[]) alpha.Clone(); } + /// + /// Gets or sets the parameters of the Dirichlet distribution. + /// + public double[] Alpha + { + get { return _alpha; } + set { SetParameters(value); } + } + /// /// Gets or sets the random number generator which is used to draw random samples. /// @@ -184,15 +190,6 @@ namespace MathNet.Numerics.Distributions get { return _alpha.Length; } } - /// - /// Gets or sets the parameters of the Dirichlet distribution. - /// - public double[] Alpha - { - get { return _alpha; } - set { SetParameters(value); } - } - /// /// Gets the sum of the Dirichlet parameters. /// diff --git a/src/Numerics/Distributions/DiscreteUniform.cs b/src/Numerics/Distributions/DiscreteUniform.cs index dbe5ad44..6a34eba9 100644 --- a/src/Numerics/Distributions/DiscreteUniform.cs +++ b/src/Numerics/Distributions/DiscreteUniform.cs @@ -49,14 +49,7 @@ namespace MathNet.Numerics.Distributions { System.Random _random; - /// - /// The distribution's lower bound. - /// int _lower; - - /// - /// The distribution's upper bound. - /// int _upper; /// @@ -121,15 +114,6 @@ namespace MathNet.Numerics.Distributions _upper = upper; } - /// - /// Gets or sets the random number generator which is used to draw random samples. - /// - public System.Random RandomSource - { - get { return _random; } - set { _random = value ?? new System.Random(); } - } - /// /// Gets or sets the lower bound of the probability distribution. /// @@ -148,6 +132,15 @@ namespace MathNet.Numerics.Distributions set { SetParameters(_lower, value); } } + /// + /// Gets or sets the random number generator which is used to draw random samples. + /// + public System.Random RandomSource + { + get { return _random; } + set { _random = value ?? new System.Random(); } + } + /// /// Gets the mean of the distribution. /// diff --git a/src/Numerics/Distributions/Erlang.cs b/src/Numerics/Distributions/Erlang.cs index a59f8a8c..8d4ace24 100644 --- a/src/Numerics/Distributions/Erlang.cs +++ b/src/Numerics/Distributions/Erlang.cs @@ -50,37 +50,37 @@ namespace MathNet.Numerics.Distributions System.Random _random; double _shape; - double _invScale; + double _rate; /// /// Initializes a new instance of the class. /// - /// The shape of the Erlang distribution. - /// The inverse scale of the Erlang distribution. - public Erlang(int shape, double invScale) + /// The shape (k) of the Erlang distribution. + /// The rate or inverse scale (λ) of the Erlang distribution. + public Erlang(int shape, double rate) { _random = new System.Random(); - SetParameters(shape, invScale); + SetParameters(shape, rate); } /// /// Initializes a new instance of the class. /// - /// The shape of the Erlang distribution. - /// The inverse scale of the Erlang distribution. + /// The shape (k) of the Erlang distribution. + /// The rate or inverse scale (λ) of the Erlang distribution. /// The random number generator which is used to draw random samples. - public Erlang(int shape, double invScale, System.Random randomSource) + public Erlang(int shape, double rate, System.Random randomSource) { _random = randomSource ?? new System.Random(); - SetParameters(shape, invScale); + SetParameters(shape, rate); } /// /// Constructs a Erlang distribution from a shape and scale parameter. The distribution will /// be initialized with the default random number generator. /// - /// The shape of the Erlang distribution. - /// The scale of the Erlang distribution. + /// The shape (k) of the Erlang distribution. + /// The scale (mu) of the Erlang distribution. /// a normal distribution. public static Erlang WithShapeScale(int shape, double scale) { @@ -91,12 +91,12 @@ namespace MathNet.Numerics.Distributions /// Constructs a Erlang distribution from a shape and inverse scale parameter. The distribution will /// be initialized with the default random number generator. /// - /// The shape of the Erlang distribution. - /// The inverse scale of the Erlang distribution. + /// The shape (k) of the Erlang distribution. + /// The rate or inverse scale (λ) of the Erlang distribution. /// a normal distribution. - public static Erlang WithShapeInvScale(int shape, double invScale) + public static Erlang WithShapeRate(int shape, double rate) { - return new Erlang(shape, invScale); + return new Erlang(shape, rate); } /// @@ -105,52 +105,52 @@ namespace MathNet.Numerics.Distributions /// a string representation of the distribution. public override string ToString() { - return "Erlang(Shape = " + _shape + ", Inverse Scale = " + _invScale + ")"; + return "Erlang(Shape = " + _shape + ", λ = " + _rate + ")"; } /// /// Checks whether the parameters of the distribution are valid. /// - /// The shape of the Erlang distribution. - /// The inverse scale of the Erlang distribution. + /// The shape (k) of the Erlang distribution. + /// The rate or inverse scale (λ) of the Erlang distribution. /// true when the parameters are valid, false otherwise. - static bool IsValidParameterSet(double shape, double invScale) + static bool IsValidParameterSet(double shape, double rate) { - return shape >= 0.0 && invScale >= 0.0; + return shape >= 0.0 && rate >= 0.0; } /// /// Sets the parameters of the distribution after checking their validity. /// - /// The shape of the Erlang distribution. - /// The inverse scale of the Erlang distribution. - void SetParameters(double shape, double invScale) + /// The shape (k) of the Erlang distribution. + /// The rate or inverse scale (λ) of the Erlang distribution. + void SetParameters(double shape, double rate) { - if (Control.CheckDistributionParameters && !IsValidParameterSet(shape, invScale)) + if (Control.CheckDistributionParameters && !IsValidParameterSet(shape, rate)) { throw new ArgumentOutOfRangeException(Resources.InvalidDistributionParameters); } _shape = shape; - _invScale = invScale; + _rate = rate; } /// - /// Gets or sets the random number generator which is used to draw random samples. + /// Gets or sets the shape (k) of the Erlang distribution. /// - public System.Random RandomSource + public int Shape { - get { return _random; } - set { _random = value ?? new System.Random(); } + get { return (int)_shape; } + set { SetParameters(value, _rate); } } /// - /// Gets or sets the shape of the Erlang distribution. + /// Gets or sets the rate or inverse scale (λ) of the Erlang distribution. /// - public int Shape + public double Rate { - get { return (int) _shape; } - set { SetParameters(value, _invScale); } + get { return _rate; } + set { SetParameters(_shape, value); } } /// @@ -158,27 +158,25 @@ namespace MathNet.Numerics.Distributions /// public double Scale { - get { return 1.0/_invScale; } + get { return 1.0 / _rate; } set { - var invScale = 1.0/value; - + var invScale = 1.0 / value; if (Double.IsNegativeInfinity(invScale)) { invScale = -invScale; } - SetParameters(_shape, invScale); } } /// - /// Gets or sets the inverse scale of the Erlang distribution. + /// Gets or sets the random number generator which is used to draw random samples. /// - public double InvScale + public System.Random RandomSource { - get { return _invScale; } - set { SetParameters(_shape, value); } + get { return _random; } + set { _random = value ?? new System.Random(); } } /// @@ -188,17 +186,17 @@ namespace MathNet.Numerics.Distributions { get { - if (Double.IsPositiveInfinity(_invScale)) + if (Double.IsPositiveInfinity(_rate)) { return _shape; } - if (_invScale == 0.0 && _shape == 0.0) + if (_rate == 0.0 && _shape == 0.0) { return Double.NaN; } - return _shape/_invScale; + return _shape/_rate; } } @@ -209,17 +207,17 @@ namespace MathNet.Numerics.Distributions { get { - if (Double.IsPositiveInfinity(_invScale)) + if (Double.IsPositiveInfinity(_rate)) { return 0.0; } - if (_invScale == 0.0 && _shape == 0.0) + if (_rate == 0.0 && _shape == 0.0) { return Double.NaN; } - return _shape/(_invScale*_invScale); + return _shape/(_rate*_rate); } } @@ -230,17 +228,17 @@ namespace MathNet.Numerics.Distributions { get { - if (Double.IsPositiveInfinity(_invScale)) + if (Double.IsPositiveInfinity(_rate)) { return 0.0; } - if (_invScale == 0.0 && _shape == 0.0) + if (_rate == 0.0 && _shape == 0.0) { return Double.NaN; } - return Math.Sqrt(_shape)/_invScale; + return Math.Sqrt(_shape)/_rate; } } @@ -251,17 +249,17 @@ namespace MathNet.Numerics.Distributions { get { - if (Double.IsPositiveInfinity(_invScale)) + if (Double.IsPositiveInfinity(_rate)) { return 0.0; } - if (_invScale == 0.0 && _shape == 0.0) + if (_rate == 0.0 && _shape == 0.0) { return Double.NaN; } - return _shape - Math.Log(_invScale) + SpecialFunctions.GammaLn(_shape) + ((1.0 - _shape)*SpecialFunctions.DiGamma(_shape)); + return _shape - Math.Log(_rate) + SpecialFunctions.GammaLn(_shape) + ((1.0 - _shape)*SpecialFunctions.DiGamma(_shape)); } } @@ -272,12 +270,12 @@ namespace MathNet.Numerics.Distributions { get { - if (Double.IsPositiveInfinity(_invScale)) + if (Double.IsPositiveInfinity(_rate)) { return 0.0; } - if (_invScale == 0.0 && _shape == 0.0) + if (_rate == 0.0 && _shape == 0.0) { return Double.NaN; } @@ -298,17 +296,17 @@ namespace MathNet.Numerics.Distributions throw new NotSupportedException(); } - if (Double.IsPositiveInfinity(_invScale)) + if (Double.IsPositiveInfinity(_rate)) { return _shape; } - if (_invScale == 0.0 && _shape == 0.0) + if (_rate == 0.0 && _shape == 0.0) { return Double.NaN; } - return (_shape - 1.0)/_invScale; + return (_shape - 1.0)/_rate; } } @@ -343,22 +341,22 @@ namespace MathNet.Numerics.Distributions /// the density at . public double Density(double x) { - if (Double.IsPositiveInfinity(_invScale)) + if (Double.IsPositiveInfinity(_rate)) { return x == _shape ? Double.PositiveInfinity : 0.0; } - if (_shape == 0.0 && _invScale == 0.0) + if (_shape == 0.0 && _rate == 0.0) { return 0.0; } if (_shape == 1.0) { - return _invScale*Math.Exp(-_invScale*x); + return _rate*Math.Exp(-_rate*x); } - return Math.Pow(_invScale, _shape)*Math.Pow(x, _shape - 1.0)*Math.Exp(-_invScale*x)/SpecialFunctions.Gamma(_shape); + return Math.Pow(_rate, _shape)*Math.Pow(x, _shape - 1.0)*Math.Exp(-_rate*x)/SpecialFunctions.Gamma(_shape); } /// @@ -368,22 +366,22 @@ namespace MathNet.Numerics.Distributions /// the log density at . public double DensityLn(double x) { - if (Double.IsPositiveInfinity(_invScale)) + if (Double.IsPositiveInfinity(_rate)) { return x == _shape ? Double.PositiveInfinity : Double.NegativeInfinity; } - if (_shape == 0.0 && _invScale == 0.0) + if (_shape == 0.0 && _rate == 0.0) { return Double.NegativeInfinity; } if (_shape == 1.0) { - return Math.Log(_invScale) - (_invScale*x); + return Math.Log(_rate) - (_rate*x); } - return (_shape*Math.Log(_invScale)) + ((_shape - 1.0)*Math.Log(x)) - (_invScale*x) - SpecialFunctions.GammaLn(_shape); + return (_shape*Math.Log(_rate)) + ((_shape - 1.0)*Math.Log(x)) - (_rate*x) - SpecialFunctions.GammaLn(_shape); } /// @@ -393,17 +391,17 @@ namespace MathNet.Numerics.Distributions /// the cumulative distribution at location . public double CumulativeDistribution(double x) { - if (Double.IsPositiveInfinity(_invScale)) + if (Double.IsPositiveInfinity(_rate)) { return x >= _shape ? 1.0 : 0.0; } - if (_shape == 0.0 && _invScale == 0.0) + if (_shape == 0.0 && _rate == 0.0) { return 0.0; } - return SpecialFunctions.GammaLowerRegularized(_shape, x*_invScale); + return SpecialFunctions.GammaLowerRegularized(_shape, x*_rate); } /// @@ -466,7 +464,7 @@ namespace MathNet.Numerics.Distributions /// a sample from the distribution. public double Sample() { - return SampleUnchecked(RandomSource, _shape, _invScale); + return SampleUnchecked(RandomSource, _shape, _rate); } /// @@ -477,7 +475,7 @@ namespace MathNet.Numerics.Distributions { while (true) { - yield return SampleUnchecked(RandomSource, _shape, _invScale); + yield return SampleUnchecked(RandomSource, _shape, _rate); } } diff --git a/src/Numerics/Distributions/Exponential.cs b/src/Numerics/Distributions/Exponential.cs index df1ea23c..257de61c 100644 --- a/src/Numerics/Distributions/Exponential.cs +++ b/src/Numerics/Distributions/Exponential.cs @@ -37,7 +37,7 @@ namespace MathNet.Numerics.Distributions /// /// Continuous Univariate Exponential distribution. /// The exponential distribution is a distribution over the real numbers parameterized by one non-negative parameter. - /// Wikipedia - exponential distribution. + /// Wikipedia - exponential distribution. /// /// The distribution will use the by default. /// Users can set the random number generator by using the property. @@ -48,27 +48,27 @@ namespace MathNet.Numerics.Distributions { System.Random _random; - double _lambda; + double _rate; /// /// Initializes a new instance of the class. /// - /// The lambda parameter of the Exponential distribution. - public Exponential(double lambda) + /// The rate (λ) parameter of the Exponential distribution. + public Exponential(double rate) { _random = new System.Random(); - SetParameters(lambda); + SetParameters(rate); } /// /// Initializes a new instance of the class. /// - /// The lambda parameter of the Exponential distribution. + /// The rate (λ) parameter of the Exponential distribution. /// The random number generator which is used to draw random samples. - public Exponential(double lambda, System.Random randomSource) + public Exponential(double rate, System.Random randomSource) { _random = randomSource ?? new System.Random(); - SetParameters(lambda); + SetParameters(rate); } /// @@ -77,50 +77,50 @@ namespace MathNet.Numerics.Distributions /// a string representation of the distribution. public override string ToString() { - return "Exponential(Lambda = " + _lambda + ")"; + return "Exponential(λ = " + _rate + ")"; } /// /// Checks whether the parameters of the distribution are valid. /// - /// Lambda parameter. + /// The rate (λ) parameter of the Exponential distribution. /// true when the parameters are valid, false otherwise. - static bool IsValidParameterSet(double lambda) + static bool IsValidParameterSet(double rate) { - return lambda >= 0.0; + return rate >= 0.0; } /// /// Sets the parameters of the distribution after checking their validity. /// - /// Lambda parameter. + /// The rate (λ) parameter of the Exponential distribution. /// When the parameters don't pass the function. - void SetParameters(double lambda) + void SetParameters(double rate) { - if (Control.CheckDistributionParameters && !IsValidParameterSet(lambda)) + if (Control.CheckDistributionParameters && !IsValidParameterSet(rate)) { throw new ArgumentOutOfRangeException(Resources.InvalidDistributionParameters); } - _lambda = lambda; + _rate = rate; } /// - /// Gets or sets the random number generator which is used to draw random samples. + /// Gets or sets the rate (λ) parameter of the distribution. /// - public System.Random RandomSource + public double Rate { - get { return _random; } - set { _random = value ?? new System.Random(); } + get { return _rate; } + set { SetParameters(value); } } /// - /// Gets or sets the lambda parameter of the distribution. + /// Gets or sets the random number generator which is used to draw random samples. /// - public double Lambda + public System.Random RandomSource { - get { return _lambda; } - set { SetParameters(value); } + get { return _random; } + set { _random = value ?? new System.Random(); } } /// @@ -128,7 +128,7 @@ namespace MathNet.Numerics.Distributions /// public double Mean { - get { return 1.0/_lambda; } + get { return 1.0/_rate; } } /// @@ -136,7 +136,7 @@ namespace MathNet.Numerics.Distributions /// public double Variance { - get { return 1.0/(_lambda*_lambda); } + get { return 1.0/(_rate*_rate); } } /// @@ -144,7 +144,7 @@ namespace MathNet.Numerics.Distributions /// public double StdDev { - get { return 1.0/_lambda; } + get { return 1.0/_rate; } } /// @@ -152,7 +152,7 @@ namespace MathNet.Numerics.Distributions /// public double Entropy { - get { return 1.0 - Math.Log(_lambda); } + get { return 1.0 - Math.Log(_rate); } } /// @@ -176,7 +176,7 @@ namespace MathNet.Numerics.Distributions /// public double Median { - get { return Math.Log(2.0)/_lambda; } + get { return Math.Log(2.0)/_rate; } } /// @@ -204,7 +204,7 @@ namespace MathNet.Numerics.Distributions { if (x >= 0.0) { - return _lambda*Math.Exp(-_lambda*x); + return _rate*Math.Exp(-_rate*x); } return 0.0; @@ -217,7 +217,7 @@ namespace MathNet.Numerics.Distributions /// the log density at . public double DensityLn(double x) { - return Math.Log(_lambda) - (_lambda*x); + return Math.Log(_rate) - (_rate*x); } /// @@ -229,7 +229,7 @@ namespace MathNet.Numerics.Distributions { if (x >= 0.0) { - return 1.0 - Math.Exp(-_lambda*x); + return 1.0 - Math.Exp(-_rate*x); } return 0.0; @@ -239,9 +239,9 @@ namespace MathNet.Numerics.Distributions /// Samples the distribution. /// /// The random number generator to use. - /// The lambda parameter of the Exponential distribution. + /// The rate (λ) parameter of the Exponential distribution. /// a random number from the distribution. - internal static double SampleUnchecked(System.Random rnd, double lambda) + internal static double SampleUnchecked(System.Random rnd, double rate) { var r = rnd.NextDouble(); while (r == 0.0) @@ -249,7 +249,7 @@ namespace MathNet.Numerics.Distributions r = rnd.NextDouble(); } - return -Math.Log(r)/lambda; + return -Math.Log(r)/rate; } /// @@ -258,7 +258,7 @@ namespace MathNet.Numerics.Distributions /// A random number from this distribution. public double Sample() { - return SampleUnchecked(RandomSource, _lambda); + return SampleUnchecked(RandomSource, _rate); } /// @@ -269,7 +269,7 @@ namespace MathNet.Numerics.Distributions { while (true) { - yield return SampleUnchecked(RandomSource, _lambda); + yield return SampleUnchecked(RandomSource, _rate); } } @@ -277,34 +277,34 @@ namespace MathNet.Numerics.Distributions /// Draws a random sample from the distribution. /// /// The random number generator to use. - /// The lambda parameter of the Exponential distribution. + /// The rate (λ) parameter of the Exponential distribution. /// A random number from this distribution. - public static double Sample(System.Random rnd, double lambda) + public static double Sample(System.Random rnd, double rate) { - if (Control.CheckDistributionParameters && !IsValidParameterSet(lambda)) + if (Control.CheckDistributionParameters && !IsValidParameterSet(rate)) { throw new ArgumentOutOfRangeException(Resources.InvalidDistributionParameters); } - return SampleUnchecked(rnd, lambda); + return SampleUnchecked(rnd, rate); } /// /// Generates a sequence of samples from the Exponential distribution. /// /// The random number generator to use. - /// The lambda parameter of the Exponential distribution. + /// The rate (λ) parameter of the Exponential distribution. /// a sequence of samples from the distribution. - public static IEnumerable Samples(System.Random rnd, double lambda) + public static IEnumerable Samples(System.Random rnd, double rate) { - if (Control.CheckDistributionParameters && !IsValidParameterSet(lambda)) + if (Control.CheckDistributionParameters && !IsValidParameterSet(rate)) { throw new ArgumentOutOfRangeException(Resources.InvalidDistributionParameters); } while (true) { - yield return SampleUnchecked(rnd, lambda); + yield return SampleUnchecked(rnd, rate); } } } diff --git a/src/Numerics/Distributions/FisherSnedecor.cs b/src/Numerics/Distributions/FisherSnedecor.cs index 8b681afd..5a0b9e36 100644 --- a/src/Numerics/Distributions/FisherSnedecor.cs +++ b/src/Numerics/Distributions/FisherSnedecor.cs @@ -48,15 +48,8 @@ namespace MathNet.Numerics.Distributions { System.Random _random; - /// - /// The first parameter - degree of freedom. - /// - double _d1; - - /// - /// The second parameter - degree of freedom. - /// - double _d2; + double _freedom1; + double _freedom2; /// /// Initializes a new instance of the class. @@ -87,7 +80,7 @@ namespace MathNet.Numerics.Distributions /// a string representation of the distribution. public override string ToString() { - return "FisherSnedecor(DegreeOfFreedom1 = " + _d1 + ", DegreeOfFreedom2 = " + _d2 + ")"; + return "FisherSnedecor(DegreeOfFreedom1 = " + _freedom1 + ", DegreeOfFreedom2 = " + _freedom2 + ")"; } /// @@ -113,35 +106,35 @@ namespace MathNet.Numerics.Distributions throw new ArgumentOutOfRangeException(Resources.InvalidDistributionParameters); } - _d1 = d1; - _d2 = d2; + _freedom1 = d1; + _freedom2 = d2; } /// - /// Gets or sets the random number generator which is used to draw random samples. + /// Gets or sets the first parameter - degree of freedom. /// - public System.Random RandomSource + public double DegreeOfFreedom1 { - get { return _random; } - set { _random = value ?? new System.Random(); } + get { return _freedom1; } + set { SetParameters(value, _freedom2); } } /// - /// Gets or sets the first parameter - degree of freedom. + /// Gets or sets the second parameter - degree of freedom. /// - public double DegreeOfFreedom1 + public double DegreeOfFreedom2 { - get { return _d1; } - set { SetParameters(value, _d2); } + get { return _freedom2; } + set { SetParameters(_freedom1, value); } } /// - /// Gets or sets the second parameter - degree of freedom. + /// Gets or sets the random number generator which is used to draw random samples. /// - public double DegreeOfFreedom2 + public System.Random RandomSource { - get { return _d2; } - set { SetParameters(_d1, value); } + get { return _random; } + set { _random = value ?? new System.Random(); } } /// @@ -151,12 +144,12 @@ namespace MathNet.Numerics.Distributions { get { - if (_d2 <= 2) + if (_freedom2 <= 2) { throw new NotSupportedException(); } - return _d2/(_d2 - 2.0); + return _freedom2/(_freedom2 - 2.0); } } @@ -167,12 +160,12 @@ namespace MathNet.Numerics.Distributions { get { - if (_d2 <= 4) + if (_freedom2 <= 4) { throw new NotSupportedException(); } - return (2.0*_d2*_d2*(_d1 + _d2 - 2.0))/(_d1*(_d2 - 2.0)*(_d2 - 2.0)*(_d2 - 4.0)); + return (2.0*_freedom2*_freedom2*(_freedom1 + _freedom2 - 2.0))/(_freedom1*(_freedom2 - 2.0)*(_freedom2 - 2.0)*(_freedom2 - 4.0)); } } @@ -199,12 +192,12 @@ namespace MathNet.Numerics.Distributions { get { - if (_d2 <= 6) + if (_freedom2 <= 6) { throw new NotSupportedException(); } - return (((2.0*_d1) + _d2 - 2.0)*Math.Sqrt(8.0*(_d2 - 4.0)))/((_d2 - 6.0)*Math.Sqrt(_d1*(_d1 + _d2 - 2.0))); + return (((2.0*_freedom1) + _freedom2 - 2.0)*Math.Sqrt(8.0*(_freedom2 - 4.0)))/((_freedom2 - 6.0)*Math.Sqrt(_freedom1*(_freedom1 + _freedom2 - 2.0))); } } @@ -215,12 +208,12 @@ namespace MathNet.Numerics.Distributions { get { - if (_d1 <= 2) + if (_freedom1 <= 2) { throw new NotSupportedException(); } - return (_d2*(_d1 - 2.0))/(_d1*(_d2 + 2.0)); + return (_freedom2*(_freedom1 - 2.0))/(_freedom1*(_freedom2 + 2.0)); } } @@ -255,7 +248,7 @@ namespace MathNet.Numerics.Distributions /// the density at . public double Density(double x) { - return Math.Sqrt(Math.Pow(_d1*x, _d1)*Math.Pow(_d2, _d2)/Math.Pow((_d1*x) + _d2, _d1 + _d2))/(x*SpecialFunctions.Beta(_d1/2.0, _d2/2.0)); + return Math.Sqrt(Math.Pow(_freedom1*x, _freedom1)*Math.Pow(_freedom2, _freedom2)/Math.Pow((_freedom1*x) + _freedom2, _freedom1 + _freedom2))/(x*SpecialFunctions.Beta(_freedom1/2.0, _freedom2/2.0)); } /// @@ -275,7 +268,7 @@ namespace MathNet.Numerics.Distributions /// the cumulative distribution at location . public double CumulativeDistribution(double x) { - return SpecialFunctions.BetaRegularized(_d1/2.0, _d2/2.0, _d1*x/((_d1*x) + _d2)); + return SpecialFunctions.BetaRegularized(_freedom1/2.0, _freedom2/2.0, _freedom1*x/((_freedom1*x) + _freedom2)); } /// @@ -296,7 +289,7 @@ namespace MathNet.Numerics.Distributions /// a sample from the distribution. public double Sample() { - return SampleUnchecked(RandomSource, _d1, _d2); + return SampleUnchecked(RandomSource, _freedom1, _freedom2); } /// @@ -307,7 +300,7 @@ namespace MathNet.Numerics.Distributions { while (true) { - yield return SampleUnchecked(RandomSource, _d1, _d2); + yield return SampleUnchecked(RandomSource, _freedom1, _freedom2); } } diff --git a/src/Numerics/Distributions/Gamma.cs b/src/Numerics/Distributions/Gamma.cs index 72348ed0..85f1c8d2 100644 --- a/src/Numerics/Distributions/Gamma.cs +++ b/src/Numerics/Distributions/Gamma.cs @@ -1,4 +1,4 @@ -// +// // Math.NET Numerics, part of the Math.NET Project // http://numerics.mathdotnet.com // http://github.com/mathnet/mathnet-numerics @@ -46,7 +46,7 @@ namespace MathNet.Numerics.Distributions /// with shape and inverse scale both zero is undefined. /// Random number generation for the Gamma distribution is based on the algorithm in: /// "A Simple Method for Generating Gamma Variables" - Marsaglia & Tsang - /// ACM Transactions on Mathematical Software, Vol. 26, No. 3, September 2000, Pages 363–372. + /// ACM Transactions on Mathematical Software, Vol. 26, No. 3, September 2000, Pages 363–372. /// The distribution will use the by default. /// Users can get/set the random number generator by using the property. /// The statistics classes will check all the incoming parameters whether they are in the allowed @@ -57,38 +57,37 @@ namespace MathNet.Numerics.Distributions System.Random _random; double _shape; - double _invScale; + double _rate; /// /// Initializes a new instance of the Gamma class. /// - /// The shape of the Gamma distribution. - /// The inverse scale of the Gamma distribution. - public Gamma(double shape, double invScale) + /// The shape (k, α) of the Gamma distribution. + /// The rate or inverse scale (β) of the Gamma distribution. + public Gamma(double shape, double rate) { _random = new System.Random(); - SetParameters(shape, invScale); + SetParameters(shape, rate); } /// /// Initializes a new instance of the Gamma class. /// - /// The shape of the Gamma distribution. - /// The inverse scale of the Gamma distribution. + /// The shape (k, α) of the Gamma distribution. + /// The rate or inverse scale (β) of the Gamma distribution. /// The random number generator which is used to draw random samples. - public Gamma(double shape, double invScale, System.Random randomSource) + public Gamma(double shape, double rate, System.Random randomSource) { _random = randomSource ?? new System.Random(); - SetParameters(shape, invScale); + SetParameters(shape, rate); } /// /// Constructs a Gamma distribution from a shape and scale parameter. The distribution will /// be initialized with the default random number generator. /// - /// The shape of the Gamma distribution. - /// The scale of the Gamma distribution. - /// a normal distribution. + /// The shape (k) of the Gamma distribution. + /// The scale (θ) of the Gamma distribution. public static Gamma WithShapeScale(double shape, double scale) { return new Gamma(shape, 1.0/scale); @@ -98,12 +97,11 @@ namespace MathNet.Numerics.Distributions /// Constructs a Gamma distribution from a shape and inverse scale parameter. The distribution will /// be initialized with the default random number generator. /// - /// The shape of the Gamma distribution. - /// The inverse scale of the Gamma distribution. - /// a normal distribution. - public static Gamma WithShapeInvScale(double shape, double invScale) + /// The shape (α) of the Gamma distribution. + /// The rate or inverse scale (β) of the Gamma distribution. + public static Gamma WithShapeRate(double shape, double rate) { - return new Gamma(shape, invScale); + return new Gamma(shape, rate); } /// @@ -112,81 +110,79 @@ namespace MathNet.Numerics.Distributions /// a string representation of the distribution. public override string ToString() { - return "Gamma(Shape = " + _shape + ", Inverse Scale = " + _invScale + ")"; + return "Gamma(α = " + _shape + ", β = " + _rate + ")"; } /// /// Checks whether the parameters of the distribution are valid. /// - /// The shape of the Gamma distribution. - /// The inverse scale of the Gamma distribution. + /// The shape (k, α) of the Gamma distribution. + /// The rate or inverse scale (β) of the Gamma distribution. /// true when the parameters are valid, false otherwise. - static bool IsValidParameterSet(double shape, double invScale) + static bool IsValidParameterSet(double shape, double rate) { - return shape >= 0.0 && invScale >= 0.0; + return shape >= 0.0 && rate >= 0.0; } /// /// Sets the parameters of the distribution after checking their validity. /// - /// The shape of the Gamma distribution. - /// The inverse scale of the Gamma distribution. + /// The shape (k, α) of the Gamma distribution. + /// The rate or inverse scale (β) of the Gamma distribution. /// When the parameters don't pass the function. - void SetParameters(double shape, double invScale) + void SetParameters(double shape, double rate) { - if (Control.CheckDistributionParameters && !IsValidParameterSet(shape, invScale)) + if (Control.CheckDistributionParameters && !IsValidParameterSet(shape, rate)) { throw new ArgumentOutOfRangeException(Resources.InvalidDistributionParameters); } _shape = shape; - _invScale = invScale; + _rate = rate; } /// - /// Gets or sets the random number generator which is used to draw random samples. + /// Gets or sets the shape (k, α) of the Gamma distribution. /// - public System.Random RandomSource + public double Shape { - get { return _random; } - set { _random = value ?? new System.Random(); } + get { return _shape; } + set { SetParameters(value, _rate); } } /// - /// Gets or sets the shape of the Gamma distribution. + /// Gets or sets the rate or inverse scale (β) of the Gamma distribution. /// - public double Shape + public double Rate { - get { return _shape; } - set { SetParameters(value, _invScale); } + get { return _rate; } + set { SetParameters(_shape, value); } } /// - /// Gets or sets the scale of the Gamma distribution. + /// Gets or sets the scale (θ) of the Gamma distribution. /// public double Scale { - get { return 1.0/_invScale; } + get { return 1.0 / _rate; } set { - var invScale = 1.0/value; - - if (Double.IsNegativeInfinity(invScale)) + var rate = 1.0 / value; + if (Double.IsNegativeInfinity(rate)) { - invScale = -invScale; + rate = -rate; } - - SetParameters(_shape, invScale); + SetParameters(_shape, rate); } } /// - /// Gets or sets the inverse scale of the Gamma distribution. + /// Gets or sets the random number generator which is used to draw random samples. /// - public double InvScale + public System.Random RandomSource { - get { return _invScale; } - set { SetParameters(_shape, value); } + get { return _random; } + set { _random = value ?? new System.Random(); } } /// @@ -196,17 +192,17 @@ namespace MathNet.Numerics.Distributions { get { - if (Double.IsPositiveInfinity(_invScale)) + if (Double.IsPositiveInfinity(_rate)) { return _shape; } - if (_invScale == 0.0 && _shape == 0.0) + if (_rate == 0.0 && _shape == 0.0) { return Double.NaN; } - return _shape/_invScale; + return _shape/_rate; } } @@ -217,17 +213,17 @@ namespace MathNet.Numerics.Distributions { get { - if (Double.IsPositiveInfinity(_invScale)) + if (Double.IsPositiveInfinity(_rate)) { return 0.0; } - if (_invScale == 0.0 && _shape == 0.0) + if (_rate == 0.0 && _shape == 0.0) { return Double.NaN; } - return _shape/(_invScale*_invScale); + return _shape/(_rate*_rate); } } @@ -238,17 +234,17 @@ namespace MathNet.Numerics.Distributions { get { - if (Double.IsPositiveInfinity(_invScale)) + if (Double.IsPositiveInfinity(_rate)) { return 0.0; } - if (_invScale == 0.0 && _shape == 0.0) + if (_rate == 0.0 && _shape == 0.0) { return Double.NaN; } - return Math.Sqrt(_shape/(_invScale*_invScale)); + return Math.Sqrt(_shape/(_rate*_rate)); } } @@ -259,17 +255,17 @@ namespace MathNet.Numerics.Distributions { get { - if (Double.IsPositiveInfinity(_invScale)) + if (Double.IsPositiveInfinity(_rate)) { return 0.0; } - if (_invScale == 0.0 && _shape == 0.0) + if (_rate == 0.0 && _shape == 0.0) { return Double.NaN; } - return _shape - Math.Log(_invScale) + SpecialFunctions.GammaLn(_shape) + ((1.0 - _shape)*SpecialFunctions.DiGamma(_shape)); + return _shape - Math.Log(_rate) + SpecialFunctions.GammaLn(_shape) + ((1.0 - _shape)*SpecialFunctions.DiGamma(_shape)); } } @@ -280,12 +276,12 @@ namespace MathNet.Numerics.Distributions { get { - if (Double.IsPositiveInfinity(_invScale)) + if (Double.IsPositiveInfinity(_rate)) { return 0.0; } - if (_invScale == 0.0 && _shape == 0.0) + if (_rate == 0.0 && _shape == 0.0) { return Double.NaN; } @@ -301,17 +297,17 @@ namespace MathNet.Numerics.Distributions { get { - if (Double.IsPositiveInfinity(_invScale)) + if (Double.IsPositiveInfinity(_rate)) { return _shape; } - if (_invScale == 0.0 && _shape == 0.0) + if (_rate == 0.0 && _shape == 0.0) { return Double.NaN; } - return (_shape - 1.0)/_invScale; + return (_shape - 1.0)/_rate; } } @@ -346,22 +342,22 @@ namespace MathNet.Numerics.Distributions /// the density at . public double Density(double x) { - if (Double.IsPositiveInfinity(_invScale)) + if (Double.IsPositiveInfinity(_rate)) { return x == _shape ? Double.PositiveInfinity : 0.0; } - if (_shape == 0.0 && _invScale == 0.0) + if (_shape == 0.0 && _rate == 0.0) { return 0.0; } if (_shape == 1.0) { - return _invScale*Math.Exp(-_invScale*x); + return _rate*Math.Exp(-_rate*x); } - return Math.Pow(_invScale, _shape)*Math.Pow(x, _shape - 1.0)*Math.Exp(-_invScale*x)/SpecialFunctions.Gamma(_shape); + return Math.Pow(_rate, _shape)*Math.Pow(x, _shape - 1.0)*Math.Exp(-_rate*x)/SpecialFunctions.Gamma(_shape); } /// @@ -371,22 +367,22 @@ namespace MathNet.Numerics.Distributions /// the log density at . public double DensityLn(double x) { - if (Double.IsPositiveInfinity(_invScale)) + if (Double.IsPositiveInfinity(_rate)) { return x == _shape ? Double.PositiveInfinity : Double.NegativeInfinity; } - if (_shape == 0.0 && _invScale == 0.0) + if (_shape == 0.0 && _rate == 0.0) { return Double.NegativeInfinity; } if (_shape == 1.0) { - return Math.Log(_invScale) - (_invScale*x); + return Math.Log(_rate) - (_rate*x); } - return (_shape*Math.Log(_invScale)) + ((_shape - 1.0)*Math.Log(x)) - (_invScale*x) - SpecialFunctions.GammaLn(_shape); + return (_shape*Math.Log(_rate)) + ((_shape - 1.0)*Math.Log(x)) - (_rate*x) - SpecialFunctions.GammaLn(_shape); } /// @@ -396,32 +392,32 @@ namespace MathNet.Numerics.Distributions /// the cumulative distribution at location . public double CumulativeDistribution(double x) { - if (Double.IsPositiveInfinity(_invScale)) + if (Double.IsPositiveInfinity(_rate)) { return x >= _shape ? 1.0 : 0.0; } - if (_shape == 0.0 && _invScale == 0.0) + if (_shape == 0.0 && _rate == 0.0) { return 0.0; } - return SpecialFunctions.GammaLowerRegularized(_shape, x*_invScale); + return SpecialFunctions.GammaLowerRegularized(_shape, x*_rate); } /// /// Sampling implementation based on: /// "A Simple Method for Generating Gamma Variables" - Marsaglia & Tsang - /// ACM Transactions on Mathematical Software, Vol. 26, No. 3, September 2000, Pages 363–372. + /// ACM Transactions on Mathematical Software, Vol. 26, No. 3, September 2000, Pages 363–372. /// This method performs no parameter checks. /// /// The random number generator to use. - /// The shape of the Gamma distribution. - /// The inverse scale of the Gamma distribution. + /// The shape (k, α) of the Gamma distribution. + /// The rate or inverse scale (β) of the Gamma distribution. /// A sample from a Gamma distributed random variable. - internal static double SampleUnchecked(System.Random rnd, double shape, double invScale) + internal static double SampleUnchecked(System.Random rnd, double shape, double rate) { - if (Double.IsPositiveInfinity(invScale)) + if (Double.IsPositiveInfinity(rate)) { return shape; } @@ -453,12 +449,12 @@ namespace MathNet.Numerics.Distributions x = x*x; if (u < 1.0 - (0.0331*x*x)) { - return alphafix*d*v/invScale; + return alphafix*d*v/rate; } if (Math.Log(u) < (0.5*x) + (d*(1.0 - v + Math.Log(v)))) { - return alphafix*d*v/invScale; + return alphafix*d*v/rate; } } } @@ -469,7 +465,7 @@ namespace MathNet.Numerics.Distributions /// a sample from the distribution. public double Sample() { - return SampleUnchecked(RandomSource, _shape, _invScale); + return SampleUnchecked(RandomSource, _shape, _rate); } /// @@ -480,7 +476,7 @@ namespace MathNet.Numerics.Distributions { while (true) { - yield return SampleUnchecked(RandomSource, _shape, _invScale); + yield return SampleUnchecked(RandomSource, _shape, _rate); } } @@ -488,36 +484,36 @@ namespace MathNet.Numerics.Distributions /// Generates a sample from the Gamma distribution. /// /// The random number generator to use. - /// The shape of the Gamma distribution from which to generate samples. - /// The inverse scale of the Gamma distribution from which to generate samples. + /// The shape (k, α) of the Gamma distribution. + /// The rate or inverse scale (β) of the Gamma distribution. /// a sample from the distribution. - public static double Sample(System.Random rng, double shape, double invScale) + public static double Sample(System.Random rng, double shape, double rate) { - if (Control.CheckDistributionParameters && !IsValidParameterSet(shape, invScale)) + if (Control.CheckDistributionParameters && !IsValidParameterSet(shape, rate)) { throw new ArgumentOutOfRangeException(Resources.InvalidDistributionParameters); } - return SampleUnchecked(rng, shape, invScale); + return SampleUnchecked(rng, shape, rate); } /// /// Generates a sequence of samples from the Gamma distribution. /// /// The random number generator to use. - /// The shape of the Gamma distribution from which to generate samples. - /// The inverse scale of the Gamma distribution from which to generate samples. + /// The shape (k, α) of the Gamma distribution. + /// The rate or inverse scale (β) of the Gamma distribution. /// a sequence of samples from the distribution. - public static IEnumerable Samples(System.Random rng, double shape, double invScale) + public static IEnumerable Samples(System.Random rng, double shape, double rate) { - if (Control.CheckDistributionParameters && !IsValidParameterSet(shape, invScale)) + if (Control.CheckDistributionParameters && !IsValidParameterSet(shape, rate)) { throw new ArgumentOutOfRangeException(Resources.InvalidDistributionParameters); } while (true) { - yield return SampleUnchecked(rng, shape, invScale); + yield return SampleUnchecked(rng, shape, rate); } } } diff --git a/src/Numerics/Distributions/Geometric.cs b/src/Numerics/Distributions/Geometric.cs index bb21ef65..51914162 100644 --- a/src/Numerics/Distributions/Geometric.cs +++ b/src/Numerics/Distributions/Geometric.cs @@ -111,22 +111,21 @@ namespace MathNet.Numerics.Distributions } /// - /// Gets or sets the random number generator which is used to draw random samples. + /// Gets or sets the probability of generating a one. /// - public System.Random RandomSource + public double P { - get { return _random; } - set { _random = value ?? new System.Random(); } + get { return _p; } + set { SetParameters(value); } } /// - /// Gets or sets the probability of generating a one. + /// Gets or sets the random number generator which is used to draw random samples. /// - public double P + public System.Random RandomSource { - get { return _p; } - - set { SetParameters(value); } + get { return _random; } + set { _random = value ?? new System.Random(); } } /// diff --git a/src/Numerics/Distributions/Hypergeometric.cs b/src/Numerics/Distributions/Hypergeometric.cs index 45fd6c06..52faf2c9 100644 --- a/src/Numerics/Distributions/Hypergeometric.cs +++ b/src/Numerics/Distributions/Hypergeometric.cs @@ -51,19 +51,8 @@ namespace MathNet.Numerics.Distributions { System.Random _random; - /// - /// The size of the population (N). - /// int _population; - - /// - /// The number successes within the population (K, M). - /// int _success; - - /// - /// The number of draws without replacement (n). - /// int _draws; /// diff --git a/src/Numerics/Distributions/InverseGamma.cs b/src/Numerics/Distributions/InverseGamma.cs index eab245d9..e7c1a449 100644 --- a/src/Numerics/Distributions/InverseGamma.cs +++ b/src/Numerics/Distributions/InverseGamma.cs @@ -38,7 +38,7 @@ namespace MathNet.Numerics.Distributions /// 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. + /// Wikipedia - InverseGamma distribution. /// /// The distribution will use the by default. /// Users can set the random number generator by using the property. @@ -55,8 +55,8 @@ namespace MathNet.Numerics.Distributions /// /// Initializes a new instance of the class. /// - /// The shape (alpha) parameter of the inverse Gamma distribution. - /// The scale (beta) parameter of the inverse Gamma distribution. + /// The shape (α) of the inverse Gamma distribution. + /// The scale (β) of the inverse Gamma distribution. public InverseGamma(double shape, double scale) { _random = new System.Random(); @@ -66,8 +66,8 @@ namespace MathNet.Numerics.Distributions /// /// Initializes a new instance of the class. /// - /// The shape (alpha) parameter of the inverse Gamma distribution. - /// The scale (beta) parameter of the inverse Gamma distribution. + /// The shape (α) of the inverse Gamma distribution. + /// The scale (β) of the inverse Gamma distribution. /// The random number generator which is used to draw random samples. public InverseGamma(double shape, double scale, System.Random randomSource) { @@ -81,14 +81,14 @@ namespace MathNet.Numerics.Distributions /// a string representation of the distribution. public override string ToString() { - return "InverseGamma(Shape = " + _shape + ", Inverse Scale = " + _scale + ")"; + return "InverseGamma(α = " + _shape + ", β = " + _scale + ")"; } /// /// Checks whether the parameters of the distribution are valid. /// - /// The shape (alpha) parameter of the inverse Gamma distribution. - /// The scale (beta) parameter of the inverse Gamma distribution. + /// The shape (α) of the inverse Gamma distribution. + /// The scale (β) of the inverse Gamma distribution. /// true when the parameters are valid, false otherwise. static bool IsValidParameterSet(double shape, double scale) { @@ -98,8 +98,8 @@ namespace MathNet.Numerics.Distributions /// /// Sets the parameters of the distribution after checking their validity. /// - /// The shape (alpha) parameter of the inverse Gamma distribution. - /// The scale (beta) parameter of the inverse Gamma distribution. + /// The shape (α) of the inverse Gamma distribution. + /// The scale (β) of the inverse Gamma distribution. /// When the parameters don't pass the function. void SetParameters(double shape, double scale) { @@ -113,16 +113,7 @@ namespace MathNet.Numerics.Distributions } /// - /// Gets or sets the random number generator which is used to draw random samples. - /// - public System.Random RandomSource - { - get { return _random; } - set { _random = value ?? new System.Random(); } - } - - /// - /// Gets or sets the shape (alpha) parameter. + /// Gets or sets the shape (α) parameter. /// public double Shape { @@ -131,7 +122,7 @@ namespace MathNet.Numerics.Distributions } /// - /// Gets or sets The scale (beta) parameter. + /// Gets or sets The scale (β) parameter. /// public double Scale { @@ -139,6 +130,15 @@ namespace MathNet.Numerics.Distributions set { SetParameters(_shape, value); } } + /// + /// Gets or sets the random number generator which is used to draw random samples. + /// + public System.Random RandomSource + { + get { return _random; } + set { _random = value ?? new System.Random(); } + } + /// /// Gets the mean of the distribution. /// @@ -275,8 +275,8 @@ namespace MathNet.Numerics.Distributions /// Samples the distribution. /// /// The random number generator to use. - /// The shape (alpha) parameter of the inverse Gamma distribution. - /// The scale (beta) parameter of the inverse Gamma distribution. + /// The shape (α) of the inverse Gamma distribution. + /// The scale (β) of the inverse Gamma distribution. /// a random number from the distribution. internal static double SampleUnchecked(System.Random rnd, double shape, double scale) { @@ -308,8 +308,8 @@ namespace MathNet.Numerics.Distributions /// Generates a sample from the distribution. /// /// The random number generator to use. - /// The shape (alpha) parameter of the inverse Gamma distribution. - /// The scale (beta) parameter of the inverse Gamma distribution. + /// The shape (α) of the inverse Gamma distribution. + /// The scale (β) of the inverse Gamma distribution. /// a sample from the distribution. public static double Sample(System.Random rnd, double shape, double scale) { @@ -325,8 +325,8 @@ namespace MathNet.Numerics.Distributions /// Generates a sequence of samples from the distribution. /// /// The random number generator to use. - /// The shape (alpha) parameter of the inverse Gamma distribution. - /// The scale (beta) parameter of the inverse Gamma distribution. + /// The shape (α) of the inverse Gamma distribution. + /// The scale (β) of the inverse Gamma distribution. /// a sequence of samples from the distribution. public static IEnumerable Samples(System.Random rnd, double shape, double scale) { diff --git a/src/Numerics/Distributions/InverseWishart.cs b/src/Numerics/Distributions/InverseWishart.cs index 3e24fbb1..e767a1d2 100644 --- a/src/Numerics/Distributions/InverseWishart.cs +++ b/src/Numerics/Distributions/InverseWishart.cs @@ -50,15 +50,8 @@ namespace MathNet.Numerics.Distributions { System.Random _random; - /// - /// The degrees of freedom for the inverse Wishart distribution. - /// - double _nu; - - /// - /// The scale matrix for the inverse Wishart distribution. - /// - Matrix _s; + double _freedom; + Matrix _scale; /// /// Caches the Cholesky factorization of the scale matrix. @@ -68,24 +61,24 @@ namespace MathNet.Numerics.Distributions /// /// Initializes a new instance of the class. /// - /// The degrees of freedom for the inverse Wishart distribution. - /// The scale matrix for the inverse Wishart distribution. - public InverseWishart(double nu, Matrix s) + /// The degree of freedom (ν) for the inverse Wishart distribution. + /// The scale matrix (Ψ) for the inverse Wishart distribution. + public InverseWishart(double degreeOfFreedom, Matrix scale) { _random = new System.Random(); - SetParameters(nu, s); + SetParameters(degreeOfFreedom, scale); } /// /// Initializes a new instance of the class. /// - /// The degrees of freedom for the inverse Wishart distribution. - /// The scale matrix for the inverse Wishart distribution. + /// The degree 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, System.Random randomSource) + public InverseWishart(double degreeOfFreedom, Matrix scale, System.Random randomSource) { _random = randomSource ?? new System.Random(); - SetParameters(nu, s); + SetParameters(degreeOfFreedom, scale); } /// @@ -94,76 +87,76 @@ namespace MathNet.Numerics.Distributions /// a string representation of the distribution. public override string ToString() { - return "InverseWishart(Nu = " + _nu + ", Rows = " + _s.RowCount + ", Columns = " + _s.ColumnCount + ")"; + return "InverseWishart(ν = " + _freedom + ", Rows = " + _scale.RowCount + ", Columns = " + _scale.ColumnCount + ")"; } /// /// Checks whether the parameters of the distribution are valid. /// - /// The degrees of freedom for the Wishart distribution. - /// The scale matrix for the Wishart distribution. + /// The degree of freedom (ν) for the inverse Wishart distribution. + /// The scale matrix (Ψ) for the inverse Wishart distribution. /// true when the parameters are valid, false otherwise. - static bool IsValidParameterSet(double nu, Matrix s) + static bool IsValidParameterSet(double degreeOfFreedom, Matrix scale) { - if (s.RowCount != s.ColumnCount) + if (scale.RowCount != scale.ColumnCount) { return false; } - for (var i = 0; i < s.RowCount; i++) + for (var i = 0; i < scale.RowCount; i++) { - if (s.At(i, i) <= 0.0) + if (scale.At(i, i) <= 0.0) { return false; } } - return nu > 0.0; + return degreeOfFreedom > 0.0; } /// /// Sets the parameters of the distribution after checking their validity. /// - /// The degrees of freedom for the Wishart distribution. - /// The scale matrix for the Wishart distribution. + /// The degree of freedom (ν) for the inverse Wishart distribution. + /// The scale matrix (Ψ) for the inverse Wishart distribution. /// When the parameters don't pass the function. - void SetParameters(double nu, Matrix s) + void SetParameters(double degreeOfFreedom, Matrix scale) { - if (Control.CheckDistributionParameters && !IsValidParameterSet(nu, s)) + if (Control.CheckDistributionParameters && !IsValidParameterSet(degreeOfFreedom, scale)) { throw new ArgumentOutOfRangeException(Resources.InvalidDistributionParameters); } - _nu = nu; - _s = s; - _chol = Cholesky.Create(_s); + _freedom = degreeOfFreedom; + _scale = scale; + _chol = Cholesky.Create(_scale); } /// - /// Gets or sets the random number generator which is used to draw random samples. + /// Gets or sets the degree of freedom (ν) for the inverse Wishart distribution. /// - public System.Random RandomSource + public double DegreeOfFreedom { - get { return _random; } - set { _random = value ?? new System.Random(); } + get { return _freedom; } + set { SetParameters(value, _scale); } } /// - /// Gets or sets the degrees of freedom for the inverse Wishart distribution. + /// Gets or sets the scale matrix (Ψ) for the inverse Wishart distribution. /// - public double Nu + public Matrix Scale { - get { return _nu; } - set { SetParameters(value, _s); } + get { return _scale; } + set { SetParameters(_freedom, value); } } /// - /// Gets or sets the scale matrix for the inverse Wishart distribution. + /// Gets or sets the random number generator which is used to draw random samples. /// - public Matrix S + public System.Random RandomSource { - get { return _s; } - set { SetParameters(_nu, value); } + get { return _random; } + set { _random = value ?? new System.Random(); } } /// @@ -172,7 +165,7 @@ namespace MathNet.Numerics.Distributions /// The mean of the distribution. public Matrix Mean { - get { return _s*(1.0/(_nu - _s.RowCount - 1.0)); } + get { return _scale*(1.0/(_freedom - _scale.RowCount - 1.0)); } } /// @@ -182,7 +175,7 @@ namespace MathNet.Numerics.Distributions /// A. O'Hagan, and J. J. Forster (2004). Kendall's Advanced Theory of Statistics: Bayesian Inference. 2B (2 ed.). Arnold. ISBN 0-340-80752-0. public Matrix Mode { - get { return _s*(1.0/(_nu + _s.RowCount + 1.0)); } + get { return _scale*(1.0/(_freedom + _scale.RowCount + 1.0)); } } /// @@ -194,13 +187,13 @@ namespace MathNet.Numerics.Distributions { get { - var res = _s.CreateMatrix(_s.RowCount, _s.ColumnCount); + var res = _scale.CreateMatrix(_scale.RowCount, _scale.ColumnCount); for (var i = 0; i < res.RowCount; i++) { for (var j = 0; j < res.ColumnCount; j++) { - var num1 = ((_nu - _s.RowCount + 1)*_s.At(i, j)*_s.At(i, j)) + ((_nu - _s.RowCount - 1)*_s.At(i, i)*_s.At(j, j)); - var num2 = (_nu - _s.RowCount)*(_nu - _s.RowCount - 1)*(_nu - _s.RowCount - 1)*(_nu - _s.RowCount - 3); + var num1 = ((_freedom - _scale.RowCount + 1)*_scale.At(i, j)*_scale.At(i, j)) + ((_freedom - _scale.RowCount - 1)*_scale.At(i, i)*_scale.At(j, j)); + var num2 = (_freedom - _scale.RowCount)*(_freedom - _scale.RowCount - 1)*(_freedom - _scale.RowCount - 1)*(_freedom - _scale.RowCount - 3); res.At(i, j, num1/num2); } } @@ -217,7 +210,7 @@ namespace MathNet.Numerics.Distributions /// the density at . public double Density(Matrix x) { - var p = _s.RowCount; + var p = _scale.RowCount; if (x.RowCount != p || x.ColumnCount != p) { @@ -226,19 +219,19 @@ namespace MathNet.Numerics.Distributions var chol = Cholesky.Create(x); var dX = chol.Determinant; - var sXi = chol.Solve(S); + var sXi = chol.Solve(Scale); // Compute the multivariate Gamma function. var gp = Math.Pow(Constants.Pi, p*(p - 1.0)/4.0); for (var j = 1; j <= p; j++) { - gp *= SpecialFunctions.Gamma((_nu + 1.0 - j)/2.0); + gp *= SpecialFunctions.Gamma((_freedom + 1.0 - j)/2.0); } - return Math.Pow(dX, -(_nu + p + 1.0)/2.0) + return Math.Pow(dX, -(_freedom + 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) + *Math.Pow(_chol.Determinant, _freedom/2.0) + /Math.Pow(2.0, _freedom*p/2.0) /gp; } @@ -249,7 +242,7 @@ namespace MathNet.Numerics.Distributions /// a sample from the distribution. public Matrix Sample() { - return Sample(RandomSource, _nu, _s); + return Sample(RandomSource, _freedom, _scale); } /// @@ -257,17 +250,17 @@ namespace MathNet.Numerics.Distributions /// a Wishart random variable and inverting the matrix. /// /// The random number generator to use. - /// The degrees of freedom. - /// The scale matrix. + /// The degree of freedom (ν) for the inverse Wishart distribution. + /// The scale matrix (Ψ) for the inverse Wishart distribution. /// a sample from the distribution. - public static Matrix Sample(System.Random rnd, double nu, Matrix s) + public static Matrix Sample(System.Random rnd, double degreeOfFreedom, Matrix scale) { - if (Control.CheckDistributionParameters && !IsValidParameterSet(nu, s)) + if (Control.CheckDistributionParameters && !IsValidParameterSet(degreeOfFreedom, scale)) { throw new ArgumentOutOfRangeException(Resources.InvalidDistributionParameters); } - var r = Wishart.Sample(rnd, nu, s.Inverse()); + var r = Wishart.Sample(rnd, degreeOfFreedom, scale.Inverse()); return r.Inverse(); } } diff --git a/src/Numerics/Distributions/Laplace.cs b/src/Numerics/Distributions/Laplace.cs index 4c6b263b..795408ad 100644 --- a/src/Numerics/Distributions/Laplace.cs +++ b/src/Numerics/Distributions/Laplace.cs @@ -50,26 +50,9 @@ namespace MathNet.Numerics.Distributions { System.Random _random; + double _location; double _scale; - /// - /// Gets or sets the location of the Laplace distribution. - /// - public double Location - { - get { return Mean; } - set { SetParameters(value, _scale); } - } - - /// - /// Gets or sets the scale of the Laplace distribution. - /// - public double Scale - { - get { return _scale; } - set { SetParameters(Mean, value); } - } - /// /// Initializes a new instance of the class (location = 0, scale = 1). /// @@ -109,14 +92,14 @@ namespace MathNet.Numerics.Distributions /// a string representation of the distribution. public override string ToString() { - return "Laplace(Location = " + Mean + ", Scale = " + _scale + ")"; + return "Laplace(μ = " + _location + ", b = " + _scale + ")"; } /// /// Checks whether the parameters of the distribution are valid. /// - /// The location for the Laplace distribution. - /// The scale for the Laplace distribution. + /// The location (μ) of the Laplace distribution. + /// The scale (b) of the Laplace distribution. /// true when the parameters are valid, false otherwise. static bool IsValidParameterSet(double location, double scale) { @@ -126,8 +109,8 @@ namespace MathNet.Numerics.Distributions /// /// Sets the parameters of the distribution after checking their validity. /// - /// The location for the Laplace distribution. - /// The scale for the Laplace distribution. + /// The location (μ) of the Laplace distribution. + /// The scale (b) of the Laplace distribution. /// When the parameters don't pass the function. void SetParameters(double location, double scale) { @@ -136,10 +119,28 @@ namespace MathNet.Numerics.Distributions throw new ArgumentOutOfRangeException(Resources.InvalidDistributionParameters); } - Mean = location; + _location = location; _scale = scale; } + /// + /// Gets or sets the location (μ) of the Laplace distribution. + /// + public double Location + { + get { return _location; } + set { SetParameters(value, _scale); } + } + + /// + /// Gets or sets the scale (b) of the Laplace distribution. + /// + public double Scale + { + get { return _scale; } + set { SetParameters(_location, value); } + } + /// /// Gets or sets the random number generator which is used to draw random samples. /// @@ -152,7 +153,10 @@ namespace MathNet.Numerics.Distributions /// /// Gets the mean of the distribution. /// - public double Mean { get; private set; } + public double Mean + { + get { return _location; } + } /// /// Gets the variance of the distribution. @@ -191,7 +195,7 @@ namespace MathNet.Numerics.Distributions /// public double Mode { - get { return Mean; } + get { return _location; } } /// @@ -199,7 +203,7 @@ namespace MathNet.Numerics.Distributions /// public double Median { - get { return Mean; } + get { return _location; } } /// @@ -225,7 +229,7 @@ namespace MathNet.Numerics.Distributions /// the density at . public double Density(double x) { - return Math.Exp(-Math.Abs(x - Mean)/_scale)/(2.0*_scale); + return Math.Exp(-Math.Abs(x - _location)/_scale)/(2.0*_scale); } /// @@ -245,15 +249,15 @@ namespace MathNet.Numerics.Distributions /// 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)))); + return 0.5*(1.0 + (Math.Sign(x - _location)*(1.0 - Math.Exp(-Math.Abs(x - _location)/_scale)))); } /// /// Samples the distribution. /// /// The random number generator to use. - /// The location shape parameter. - /// The scale parameter. + /// The location (μ) of the Laplace distribution. + /// The scale (b) of the Laplace distribution. /// a random number from the distribution. internal static double SampleUnchecked(System.Random rnd, double location, double scale) { @@ -267,7 +271,7 @@ namespace MathNet.Numerics.Distributions /// a sample from the distribution. public double Sample() { - return SampleUnchecked(RandomSource, Mean, _scale); + return SampleUnchecked(RandomSource, _location, _scale); } /// @@ -278,7 +282,7 @@ namespace MathNet.Numerics.Distributions { while (true) { - yield return SampleUnchecked(RandomSource, Mean, _scale); + yield return SampleUnchecked(RandomSource, _location, _scale); } } @@ -286,8 +290,8 @@ namespace MathNet.Numerics.Distributions /// Generates a sample from the distribution. /// /// The random number generator to use. - /// The location shape parameter. - /// The scale parameter. + /// The location (μ) of the Laplace distribution. + /// The scale (b) of the Laplace distribution. /// a sample from the distribution. public static double Sample(System.Random rnd, double location, double scale) { @@ -303,8 +307,8 @@ namespace MathNet.Numerics.Distributions /// Generates a sequence of samples from the distribution. /// /// The random number generator to use. - /// The location shape parameter. - /// The scale parameter. + /// The location (μ) of the Laplace distribution. + /// The scale (b) of the Laplace distribution. /// a sequence of samples from the distribution. public static IEnumerable Samples(System.Random rnd, double location, double scale) { diff --git a/src/Numerics/Distributions/LogNormal.cs b/src/Numerics/Distributions/LogNormal.cs index 0a0eaf37..e92b4841 100644 --- a/src/Numerics/Distributions/LogNormal.cs +++ b/src/Numerics/Distributions/LogNormal.cs @@ -1,4 +1,4 @@ -// +// // Math.NET Numerics, part of the Math.NET Project // http://numerics.mathdotnet.com // http://github.com/mathnet/mathnet-numerics @@ -58,8 +58,8 @@ namespace MathNet.Numerics.Distributions /// The distribution will be initialized with the default /// random number generator. /// - /// The mu of the logarithm of the distribution. - /// The standard deviation of the logarithm of the distribution. + /// The log-scale (μ) of the logarithm of the distribution. + /// The shape (σ) of the logarithm of the distribution. public LogNormal(double mu, double sigma) { _random = new System.Random(); @@ -71,8 +71,8 @@ namespace MathNet.Numerics.Distributions /// The distribution will be initialized with the default /// random number generator. /// - /// The mu of the logarithm of the distribution. - /// The standard deviation of the logarithm of the distribution. + /// The log-scale (μ) of the distribution. + /// The shape (σ) of the distribution. /// The random number generator which is used to draw random samples. public LogNormal(double mu, double sigma, System.Random randomSource) { @@ -108,14 +108,14 @@ namespace MathNet.Numerics.Distributions /// a string representation of the distribution. public override string ToString() { - return "LogNormal(Mu = " + _mu + ", Sigma = " + _sigma + ")"; + return "LogNormal(μ = " + _mu + ", σ = " + _sigma + ")"; } /// /// Checks whether the parameters of the distribution are valid. /// - /// The mu of the logarithm of the distribution. - /// The standard deviation of the logarithm of the distribution. + /// The log-scale (μ) of the distribution. + /// The shape (σ) of the distribution. /// true when the parameters are valid, false otherwise. static bool IsValidParameterSet(double mu, double sigma) { @@ -125,8 +125,8 @@ namespace MathNet.Numerics.Distributions /// /// Sets the parameters of the distribution after checking their validity. /// - /// The mu of the logarithm of the distribution. - /// The standard deviation of the logarithm of the distribution. + /// The log-scale (μ) of the distribution. + /// The shape (σ) of the distribution. /// When the parameters don't pass the function. void SetParameters(double mu, double sigma) { @@ -140,16 +140,7 @@ namespace MathNet.Numerics.Distributions } /// - /// Gets or sets the random number generator which is used to draw random samples. - /// - public System.Random RandomSource - { - get { return _random; } - set { _random = value ?? new System.Random(); } - } - - /// - /// Gets or sets the mean of the logarithm of the log-normal. + /// Gets or sets the log-scale (μ) (mean of the logarithm) of the distribution. /// public double Mu { @@ -158,7 +149,7 @@ namespace MathNet.Numerics.Distributions } /// - /// Gets or sets the standard deviation of the logarithm of the log-normal. + /// Gets or sets the shape (σ) (standard deviation of the logarithm) of the distribution. /// public double Sigma { @@ -166,6 +157,15 @@ namespace MathNet.Numerics.Distributions set { SetParameters(_mu, value); } } + /// + /// Gets or sets the random number generator which is used to draw random samples. + /// + public System.Random RandomSource + { + get { return _random; } + set { _random = value ?? new System.Random(); } + } + /// /// Gets the mu of the log-normal distribution. /// @@ -324,8 +324,8 @@ namespace MathNet.Numerics.Distributions /// Generates a sample from the log-normal distribution using the Box-Muller algorithm. /// /// The random number generator to use. - /// The mu of the logarithm of the distribution. - /// The standard deviation of the logarithm of the distribution. + /// The log-scale (μ) of the distribution. + /// The shape (σ) of the distribution. /// a sample from the distribution. public static double Sample(System.Random rng, double mu, double sigma) { @@ -341,8 +341,8 @@ namespace MathNet.Numerics.Distributions /// Generates a sequence of samples from the log-normal distribution using the Box-Muller algorithm. /// /// The random number generator to use. - /// The mu of the logarithm of the distribution. - /// The standard deviation of the logarithm of the distribution. + /// The log-scale (μ) of the distribution. + /// The shape (σ) of the distribution. /// a sequence of samples from the distribution. public static IEnumerable Samples(System.Random rng, double mu, double sigma) { diff --git a/src/Numerics/Distributions/MatrixNormal.cs b/src/Numerics/Distributions/MatrixNormal.cs index bcdccb41..e4b2a91c 100644 --- a/src/Numerics/Distributions/MatrixNormal.cs +++ b/src/Numerics/Distributions/MatrixNormal.cs @@ -163,15 +163,6 @@ namespace MathNet.Numerics.Distributions _k = k; } - /// - /// Gets or sets the random number generator which is used to draw random samples. - /// - public System.Random RandomSource - { - get { return _random; } - set { _random = value ?? new System.Random(); } - } - /// /// Gets or sets the mean. (M) /// @@ -202,6 +193,15 @@ namespace MathNet.Numerics.Distributions set { SetParameters(_m, _v, value); } } + /// + /// Gets or sets the random number generator which is used to draw random samples. + /// + public System.Random RandomSource + { + get { return _random; } + set { _random = value ?? new System.Random(); } + } + /// /// Evaluates the probability density function for the matrix normal distribution. /// diff --git a/src/Numerics/Distributions/Multinomial.cs b/src/Numerics/Distributions/Multinomial.cs index 70bb9016..b241d34a 100644 --- a/src/Numerics/Distributions/Multinomial.cs +++ b/src/Numerics/Distributions/Multinomial.cs @@ -177,21 +177,12 @@ namespace MathNet.Numerics.Distributions _trials = n; } - /// - /// Gets or sets the random number generator which is used to draw random samples. - /// - public System.Random RandomSource - { - get { return _random; } - set { _random = value ?? new System.Random(); } - } - /// /// Gets or sets the proportion of ratios. /// public double[] P { - get { return (double[]) _p.Clone(); } + get { return (double[])_p.Clone(); } set { SetParameters(value, _trials); } } @@ -204,6 +195,15 @@ namespace MathNet.Numerics.Distributions set { SetParameters(_p, value); } } + /// + /// Gets or sets the random number generator which is used to draw random samples. + /// + public System.Random RandomSource + { + get { return _random; } + set { _random = value ?? new System.Random(); } + } + /// /// Gets the mean of the distribution. /// diff --git a/src/Numerics/Distributions/NegativeBinomial.cs b/src/Numerics/Distributions/NegativeBinomial.cs index e9cea310..eab6cb56 100644 --- a/src/Numerics/Distributions/NegativeBinomial.cs +++ b/src/Numerics/Distributions/NegativeBinomial.cs @@ -51,30 +51,8 @@ namespace MathNet.Numerics.Distributions System.Random _random; double _trials; - - /// - /// The p parameter of the distribution. - /// double _p; - /// - /// Gets or sets the number of trials. - /// - public double R - { - get { return _trials; } - set { SetParameters(value, _p); } - } - - /// - /// Gets or sets the probability of success. - /// - public double P - { - get { return _p; } - set { SetParameters(_trials, value); } - } - /// /// Initializes a new instance of the class. /// @@ -137,6 +115,24 @@ namespace MathNet.Numerics.Distributions _trials = r; } + /// + /// Gets or sets the number of trials. + /// + public double R + { + get { return _trials; } + set { SetParameters(value, _p); } + } + + /// + /// Gets or sets the probability of success. + /// + public double P + { + get { return _p; } + set { SetParameters(_trials, value); } + } + /// /// Gets or sets the random number generator which is used to draw random samples. /// diff --git a/src/Numerics/Distributions/Normal.cs b/src/Numerics/Distributions/Normal.cs index b239f011..7dbf7e3c 100644 --- a/src/Numerics/Distributions/Normal.cs +++ b/src/Numerics/Distributions/Normal.cs @@ -1,4 +1,4 @@ -// +// // Math.NET Numerics, part of the Math.NET Project // http://numerics.mathdotnet.com // http://github.com/mathnet/mathnet-numerics @@ -77,8 +77,8 @@ namespace MathNet.Numerics.Distributions /// Initializes a new instance of the Normal class with a particular mean and standard deviation. The distribution will /// be initialized with the default random number generator. /// - /// The mean of the normal distribution. - /// The standard deviation of the normal distribution. + /// The mean (μ) of the normal distribution. + /// The standard deviation (σ) of the normal distribution. public Normal(double mean, double stddev) { _random = new System.Random(); @@ -89,8 +89,8 @@ namespace MathNet.Numerics.Distributions /// Initializes a new instance of the Normal class with a particular mean and standard deviation. The distribution will /// be initialized with the default random number generator. /// - /// The mean of the normal distribution. - /// The standard deviation of the normal distribution. + /// The 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, System.Random randomSource) { @@ -102,8 +102,8 @@ namespace MathNet.Numerics.Distributions /// Constructs a normal distribution from a mean and standard deviation. The distribution will /// be initialized with the default random number generator. /// - /// The mean of the normal distribution. - /// The standard deviation of the normal distribution. + /// The mean (μ) of the normal distribution. + /// The standard deviation (σ) of the normal distribution. /// a normal distribution. public static Normal WithMeanStdDev(double mean, double stddev) { @@ -114,7 +114,7 @@ namespace MathNet.Numerics.Distributions /// Constructs a normal distribution from a mean and variance. The distribution will /// be initialized with the default random number generator. /// - /// The mean of the normal distribution. + /// The mean (μ) of the normal distribution. /// The variance of the normal distribution. /// a normal distribution. public static Normal WithMeanVariance(double mean, double var) @@ -126,7 +126,7 @@ namespace MathNet.Numerics.Distributions /// Constructs a normal distribution from a mean and precision. The distribution will /// be initialized with the default random number generator. /// - /// The mean of the normal distribution. + /// The mean (μ) of the normal distribution. /// The precision of the normal distribution. /// a normal distribution. public static Normal WithMeanPrecision(double mean, double precision) @@ -149,14 +149,14 @@ namespace MathNet.Numerics.Distributions /// a string representation of the distribution. public override string ToString() { - return "Normal(Mean = " + _mean + ", StdDev = " + _stdDev + ")"; + return "Normal(μ = " + _mean + ", σ = " + _stdDev + ")"; } /// /// Checks whether the parameters of the distribution are valid. /// - /// The mean of the normal distribution. - /// The standard deviation of the normal distribution. + /// The mean (μ) of the normal distribution. + /// The standard deviation (σ) of the normal distribution. /// true when the parameters are valid, false otherwise. static bool IsValidParameterSet(double mean, double stddev) { @@ -166,8 +166,8 @@ namespace MathNet.Numerics.Distributions /// /// Sets the parameters of the distribution after checking their validity. /// - /// The mean of the normal distribution. - /// The standard deviation of the normal distribution. + /// The mean (μ) of the normal distribution. + /// The standard deviation (σ) of the normal distribution. /// When the parameters don't pass the function. void SetParameters(double mean, double stddev) { @@ -181,12 +181,30 @@ namespace MathNet.Numerics.Distributions } /// - /// Gets or sets the random number generator which is used to draw random samples. + /// Gets or sets the mean (μ) of the normal distribution. /// - public System.Random RandomSource + public double Mean { - get { return _random; } - set { _random = value ?? new System.Random(); } + get { return _mean; } + set { SetParameters(value, _stdDev); } + } + + /// + /// Gets or sets the standard deviation (σ) of the normal distribution. + /// + public double StdDev + { + get { return _stdDev; } + set { SetParameters(_mean, value); } + } + + /// + /// Gets or sets the variance of the normal distribution. + /// + public double Variance + { + get { return _stdDev * _stdDev; } + set { SetParameters(_mean, Math.Sqrt(value)); } } /// @@ -194,47 +212,26 @@ namespace MathNet.Numerics.Distributions /// public double Precision { - get { return 1.0/(_stdDev*_stdDev); } - + get { return 1.0 / (_stdDev * _stdDev); } set { - var sdev = 1.0/Math.Sqrt(value); - + var sdev = 1.0 / Math.Sqrt(value); // Handle the case when the precision is -0. if (Double.IsInfinity(sdev)) { sdev = Double.PositiveInfinity; } - SetParameters(_mean, sdev); } } /// - /// Gets or sets the mean of the normal distribution. - /// - public double Mean - { - get { return _mean; } - set { SetParameters(value, _stdDev); } - } - - /// - /// Gets or sets the variance of the normal distribution. - /// - public double Variance - { - get { return _stdDev*_stdDev; } - set { SetParameters(_mean, Math.Sqrt(value)); } - } - - /// - /// Gets or sets the standard deviation of the normal distribution. + /// Gets or sets the random number generator which is used to draw random samples. /// - public double StdDev + public System.Random RandomSource { - get { return _stdDev; } - set { SetParameters(_mean, value); } + get { return _random; } + set { _random = value ?? new System.Random(); } } /// @@ -288,27 +285,27 @@ namespace MathNet.Numerics.Distributions /// /// Computes the density of the normal distribution (PDF), i.e. dP(X <= x)/dx. /// - /// The mean of the normal distribution. - /// The standard deviation of the normal distribution. + /// The mean (μ) of the normal distribution. + /// The standard deviation (σ) of the normal distribution. /// The location at which to compute the density. /// the density at . - internal static double Density(double mean, double sdev, double x) + internal static double Density(double mean, double stddev, double x) { - var d = (x - mean)/sdev; - return Math.Exp(-0.5*d*d)/(Constants.Sqrt2Pi*sdev); + var d = (x - mean)/stddev; + return Math.Exp(-0.5*d*d)/(Constants.Sqrt2Pi*stddev); } /// /// Computes the log density of the normal distribution (lnPDF), i.e. ln(dP(X <= x)/dx). /// - /// The mean of the normal distribution. - /// The standard deviation of the normal distribution. + /// The mean (μ) of the normal distribution. + /// The standard deviation (σ) of the normal distribution. /// The location at which to compute the density. /// the log density at . - internal static double DensityLn(double mean, double sdev, double x) + internal static double DensityLn(double mean, double stddev, double x) { - var d = (x - mean)/sdev; - return (-0.5*d*d) - Math.Log(sdev) - Constants.LogSqrt2Pi; + var d = (x - mean)/stddev; + return (-0.5*d*d) - Math.Log(stddev) - Constants.LogSqrt2Pi; } /// @@ -334,13 +331,13 @@ namespace MathNet.Numerics.Distributions /// /// Computes the cumulative distribution function (CDF) of the normal distribution, i.e. P(X <= x). /// - /// The mean of the normal distribution. - /// The standard deviation of the normal distribution. + /// The mean (μ) of the normal distribution. + /// The standard deviation (σ) of the normal distribution. /// The location at which to compute the cumulative density. /// the cumulative density at . - internal static double CumulativeDistribution(double mean, double sdev, double x) + internal static double CumulativeDistribution(double mean, double stddev, double x) { - return 0.5*(1.0 + SpecialFunctions.Erf((x - mean)/(sdev*Constants.Sqrt2))); + return 0.5*(1.0 + SpecialFunctions.Erf((x - mean)/(stddev*Constants.Sqrt2))); } /// @@ -388,8 +385,8 @@ namespace MathNet.Numerics.Distributions /// Samples the distribution. /// /// The random number generator to use. - /// The mean of the normal distribution from which to generate samples. - /// The standard deviation of the normal distribution from which to generate samples. + /// The mean (μ) of the normal distribution. + /// The standard deviation (σ) of the normal distribution. /// a random number from the distribution. internal static double SampleUnchecked(System.Random rnd, double mean, double stddev) { @@ -423,8 +420,8 @@ namespace MathNet.Numerics.Distributions /// Generates a sample from the normal distribution using the Box-Muller algorithm. /// /// The random number generator to use. - /// The mean of the normal distribution from which to generate samples. - /// The standard deviation of the normal distribution from which to generate samples. + /// The mean (μ) of the normal distribution. + /// The standard deviation (σ) of the normal distribution. /// a sample from the distribution. public static double Sample(System.Random rnd, double mean, double stddev) { @@ -440,8 +437,8 @@ namespace MathNet.Numerics.Distributions /// Generates a sequence of samples from the normal distribution using the Box-Muller algorithm. /// /// The random number generator to use. - /// The mean of the normal distribution from which to generate samples. - /// The standard deviation of the normal distribution from which to generate samples. + /// The mean (μ) of the normal distribution. + /// The standard deviation (σ) of the normal distribution. /// a sequence of samples from the distribution. public static IEnumerable Samples(System.Random rnd, double mean, double stddev) { diff --git a/src/Numerics/Distributions/NormalGamma.cs b/src/Numerics/Distributions/NormalGamma.cs index 52866905..ca95b769 100644 --- a/src/Numerics/Distributions/NormalGamma.cs +++ b/src/Numerics/Distributions/NormalGamma.cs @@ -180,15 +180,6 @@ namespace MathNet.Numerics.Distributions _precisionInvScale = precInvScale; } - /// - /// Gets or sets the random number generator which is used to draw random samples. - /// - public System.Random RandomSource - { - get { return _random; } - set { _random = value ?? new System.Random(); } - } - /// /// Gets or sets the location of the mean. /// @@ -225,6 +216,15 @@ namespace MathNet.Numerics.Distributions set { SetParameters(_meanLocation, _meanScale, _precisionShape, value); } } + /// + /// Gets or sets the random number generator which is used to draw random samples. + /// + public System.Random RandomSource + { + get { return _random; } + set { _random = value ?? new System.Random(); } + } + /// /// Returns the marginal distribution for the mean of the NormalGamma distribution. /// diff --git a/src/Numerics/Distributions/Pareto.cs b/src/Numerics/Distributions/Pareto.cs index 2fc0d794..8e2aafe5 100644 --- a/src/Numerics/Distributions/Pareto.cs +++ b/src/Numerics/Distributions/Pareto.cs @@ -56,8 +56,8 @@ namespace MathNet.Numerics.Distributions /// /// Initializes a new instance of the class. /// - /// The scale parameter of the distribution. - /// The shape parameter of the distribution. + /// The scale (xm) of the distribution. + /// The shape (α) of the distribution. /// If or are negative. public Pareto(double scale, double shape) { @@ -68,8 +68,8 @@ namespace MathNet.Numerics.Distributions /// /// Initializes a new instance of the class. /// - /// The scale parameter of the distribution. - /// The shape parameter of the distribution. + /// The scale (xm) of the distribution. + /// The shape (α) of the distribution. /// The random number generator which is used to draw random samples. /// If or are negative. public Pareto(double scale, double shape, System.Random randomSource) @@ -84,14 +84,14 @@ namespace MathNet.Numerics.Distributions /// a string representation of the distribution. public override string ToString() { - return "Pareto(Scale = " + _scale + ", Shape = " + _shape + ")"; + return "Pareto(xm = " + _scale + ", α = " + _shape + ")"; } /// /// Checks whether the parameters of the distribution are valid. /// - /// The scale parameter of the distribution. - /// The shape parameter of the distribution. + /// The scale (xm) of the distribution. + /// The shape (α) of the distribution. /// true when the parameters are valid, false otherwise. static bool IsValidParameterSet(double scale, double shape) { @@ -101,8 +101,8 @@ namespace MathNet.Numerics.Distributions /// /// Sets the parameters of the distribution after checking their validity. /// - /// The scale parameter of the distribution. - /// The shape parameter of the distribution. + /// The scale (xm) of the distribution. + /// The shape (α) of the distribution. /// When the parameters don't pass the function. void SetParameters(double scale, double shape) { @@ -116,16 +116,7 @@ namespace MathNet.Numerics.Distributions } /// - /// Gets or sets the random number generator which is used to draw random samples. - /// - public System.Random RandomSource - { - get { return _random; } - set { _random = value ?? new System.Random(); } - } - - /// - /// Gets or sets the scale parameter of the distribution. + /// Gets or sets the scale (xm) of the distribution. /// public double Scale { @@ -134,7 +125,7 @@ namespace MathNet.Numerics.Distributions } /// - /// Gets or sets the shape parameter of the distribution. + /// Gets or sets the shape (α) of the distribution. /// public double Shape { @@ -142,6 +133,15 @@ namespace MathNet.Numerics.Distributions set { SetParameters(_scale, value); } } + /// + /// Gets or sets the random number generator which is used to draw random samples. + /// + public System.Random RandomSource + { + get { return _random; } + set { _random = value ?? new System.Random(); } + } + /// /// Gets the mean of the distribution. /// @@ -264,8 +264,8 @@ namespace MathNet.Numerics.Distributions /// Generates a sample from the Pareto distribution without doing parameter checking. /// /// The random number generator to use. - /// The scale parameter. - /// The shape parameter. + /// The scale (xm) of the distribution. + /// The shape (α) of the distribution. /// a random number from the Pareto distribution. internal static double SampleUnchecked(System.Random rnd, double scale, double shape) { @@ -297,8 +297,8 @@ namespace MathNet.Numerics.Distributions /// Generates a sample from the distribution. /// /// The random number generator to use. - /// The scale parameter. - /// The shape parameter. + /// The scale (xm) of the distribution. + /// The shape (α) of the distribution. /// a sample from the distribution. public static double Sample(System.Random rnd, double scale, double shape) { @@ -314,8 +314,8 @@ namespace MathNet.Numerics.Distributions /// Generates a sequence of samples from the distribution. /// /// The random number generator to use. - /// The scale parameter. - /// The shape parameter. + /// The scale (xm) of the distribution. + /// The shape (α) of the distribution. /// a sequence of samples from the distribution. public static IEnumerable Samples(System.Random rnd, double scale, double shape) { diff --git a/src/Numerics/Distributions/Poisson.cs b/src/Numerics/Distributions/Poisson.cs index 2b6e41d2..5994c353 100644 --- a/src/Numerics/Distributions/Poisson.cs +++ b/src/Numerics/Distributions/Poisson.cs @@ -48,15 +48,6 @@ namespace MathNet.Numerics.Distributions double _lambda; - /// - /// Gets or sets the Poisson distribution parameter λ. - /// - public double Lambda - { - get { return _lambda; } - set { SetParameters(value); } - } - /// /// Initializes a new instance of the class. /// @@ -116,6 +107,15 @@ namespace MathNet.Numerics.Distributions _lambda = lambda; } + /// + /// Gets or sets the Poisson distribution parameter λ. + /// + public double Lambda + { + get { return _lambda; } + set { SetParameters(value); } + } + /// /// Gets or sets the random number generator which is used to draw random samples. /// diff --git a/src/Numerics/Distributions/Rayleigh.cs b/src/Numerics/Distributions/Rayleigh.cs index 204cbc83..6e1379e2 100644 --- a/src/Numerics/Distributions/Rayleigh.cs +++ b/src/Numerics/Distributions/Rayleigh.cs @@ -56,7 +56,7 @@ namespace MathNet.Numerics.Distributions /// /// Initializes a new instance of the class. /// - /// The scale parameter of the distribution. + /// The scale (σ) of the distribution. /// If is negative. public Rayleigh(double scale) { @@ -67,7 +67,7 @@ namespace MathNet.Numerics.Distributions /// /// Initializes a new instance of the class. /// - /// The scale parameter of the distribution. + /// The scale (σ) of the distribution. /// The random number generator which is used to draw random samples. /// If is negative. public Rayleigh(double scale, System.Random randomSource) @@ -82,13 +82,13 @@ namespace MathNet.Numerics.Distributions /// a string representation of the distribution. public override string ToString() { - return "Rayleigh(Scale = " + _scale + ")"; + return "Rayleigh(σ = " + _scale + ")"; } /// /// Checks whether the parameters of the distribution are valid. /// - /// The scale parameter of the distribution. + /// The scale (σ) of the distribution. /// true when the parameters are valid, false otherwise. static bool IsValidParameterSet(double scale) { @@ -98,7 +98,7 @@ namespace MathNet.Numerics.Distributions /// /// Sets the parameters of the distribution after checking their validity. /// - /// The scale parameter of the distribution. + /// The scale (σ) of the distribution. /// When the parameters don't pass the function. void SetParameters(double scale) { @@ -111,21 +111,21 @@ namespace MathNet.Numerics.Distributions } /// - /// Gets or sets the random number generator which is used to draw random samples. + /// Gets or sets the scale (σ) of the distribution. /// - public System.Random RandomSource + public double Scale { - get { return _random; } - set { _random = value ?? new System.Random(); } + get { return _scale; } + set { SetParameters(value); } } /// - /// Gets or sets the scale parameter of the distribution. + /// Gets or sets the random number generator which is used to draw random samples. /// - public double Scale + public System.Random RandomSource { - get { return _scale; } - set { SetParameters(value); } + get { return _random; } + set { _random = value ?? new System.Random(); } } /// @@ -234,7 +234,7 @@ namespace MathNet.Numerics.Distributions /// Generates a sample from the Rayleigh distribution without doing parameter checking. /// /// The random number generator to use. - /// The scale parameter. + /// The scale (σ) of the distribution. /// a random number from the Rayleigh distribution. internal static double SampleUnchecked(System.Random rnd, double scale) { @@ -266,7 +266,7 @@ namespace MathNet.Numerics.Distributions /// Generates a sample from the distribution. /// /// The random number generator to use. - /// The scale parameter. + /// The scale (σ) of the distribution. /// a sample from the distribution. public static double Sample(System.Random rnd, double scale) { @@ -282,7 +282,7 @@ namespace MathNet.Numerics.Distributions /// Generates a sequence of samples from the distribution. /// /// The random number generator to use. - /// The scale parameter. + /// The scale (σ) of the distribution. /// a sequence of samples from the distribution. public static IEnumerable Samples(System.Random rnd, double scale) { diff --git a/src/Numerics/Distributions/Stable.cs b/src/Numerics/Distributions/Stable.cs index 583b80a4..736e8b1e 100644 --- a/src/Numerics/Distributions/Stable.cs +++ b/src/Numerics/Distributions/Stable.cs @@ -51,26 +51,18 @@ namespace MathNet.Numerics.Distributions { System.Random _random; - /// - /// The stability parameter of the distribution. - /// double _alpha; - - /// - /// The skewness parameter of the distribution. - /// double _beta; - double _scale; double _location; /// /// Initializes a new instance of the class. /// - /// The stability parameter of the distribution. - /// The skewness parameter of the distribution. - /// The scale parameter of the distribution. - /// The location parameter of the distribution. + /// The stability (α) of the distribution. + /// The skewness (β) of the distribution. + /// The scale (c) of the distribution. + /// The location (μ) of the distribution. public Stable(double alpha, double beta, double scale, double location) { _random = new System.Random(); @@ -80,10 +72,10 @@ namespace MathNet.Numerics.Distributions /// /// Initializes a new instance of the class. /// - /// The stability parameter of the distribution. - /// The skewness parameter of the distribution. - /// The scale parameter of the distribution. - /// The location parameter of the distribution. + /// The stability (α) of the distribution. + /// The skewness (β) of the distribution. + /// The scale (c) of the distribution. + /// The location (μ) of the distribution. /// The random number generator which is used to draw random samples. public Stable(double alpha, double beta, double scale, double location, System.Random randomSource) { @@ -97,16 +89,16 @@ namespace MathNet.Numerics.Distributions /// a string representation of the distribution. public override string ToString() { - return "Stable(" + "Stability = " + _alpha + ", Skewness = " + _beta + ", Scale = " + _scale + ", Location = " + _location + ")"; + return "Stable(α = " + _alpha + ", β = " + _beta + ", c = " + _scale + ", μ = " + _location + ")"; } /// /// Checks whether the parameters of the distribution are valid. /// - /// The stability parameter of the distribution. - /// The skewness parameter of the distribution. - /// The scale parameter of the distribution. - /// The location parameter of the distribution. + /// The stability (α) of the distribution. + /// The skewness (β) of the distribution. + /// The scale (c) of the distribution. + /// The location (μ) of the distribution. /// true when the parameters are valid, false otherwise. static bool IsValidParameterSet(double alpha, double beta, double scale, double location) { @@ -116,10 +108,10 @@ namespace MathNet.Numerics.Distributions /// /// Sets the parameters of the distribution after checking their validity. /// - /// The stability parameter of the distribution. - /// The skewness parameter of the distribution. - /// The scale parameter of the distribution. - /// The location parameter of the distribution. + /// The stability (α) of the distribution. + /// The skewness (β) of the distribution. + /// The scale (c) of the distribution. + /// The location (μ) of the distribution. void SetParameters(double alpha, double beta, double scale, double location) { if (Control.CheckDistributionParameters && !IsValidParameterSet(alpha, beta, scale, location)) @@ -134,16 +126,7 @@ namespace MathNet.Numerics.Distributions } /// - /// Gets or sets the random number generator which is used to draw random samples. - /// - public System.Random RandomSource - { - get { return _random; } - set { _random = value ?? new System.Random(); } - } - - /// - /// Gets or sets the stability parameter of the distribution. + /// Gets or sets the stability (α) of the distribution. /// public double Alpha { @@ -152,7 +135,7 @@ namespace MathNet.Numerics.Distributions } /// - /// Gets or sets The skewness parameter of the distribution. + /// Gets or sets The skewness (β) of the distribution. /// public double Beta { @@ -161,7 +144,7 @@ namespace MathNet.Numerics.Distributions } /// - /// Gets or sets the scale parameter of the distribution. + /// Gets or sets the scale (c) of the distribution. /// public double Scale { @@ -170,7 +153,7 @@ namespace MathNet.Numerics.Distributions } /// - /// Gets or sets the location parameter of the distribution. + /// Gets or sets the location (μ) of the distribution. /// public double Location { @@ -178,6 +161,15 @@ namespace MathNet.Numerics.Distributions set { SetParameters(_alpha, _beta, _scale, value); } } + /// + /// Gets or sets the random number generator which is used to draw random samples. + /// + public System.Random RandomSource + { + get { return _random; } + set { _random = value ?? new System.Random(); } + } + /// /// Gets the mean of the distribution. /// @@ -338,8 +330,8 @@ namespace MathNet.Numerics.Distributions /// /// Computes the density of the Levy distribution. /// - /// The scale parameter of the distribution. - /// The location parameter of the distribution. + /// The scale (c) of the distribution. + /// The location (μ) of the distribution. /// The location at which to compute the density. /// the density at . static double LevyDensity(double scale, double location, double x) @@ -392,8 +384,8 @@ namespace MathNet.Numerics.Distributions /// /// Computes the cumulative distribution function of the Levy distribution. /// - /// The scale parameter. - /// The location parameter. + /// The scale (c) of the distribution. + /// The location (μ) of the distribution. /// The location at which to compute the cumulative density. /// the cumulative density at . static double LevyCumulativeDistribution(double scale, double location, double x) @@ -406,10 +398,10 @@ namespace MathNet.Numerics.Distributions /// Samples the distribution. /// /// The random number generator to use. - /// The stability parameter of the distribution. - /// The skewness parameter of the distribution. - /// The scale parameter of the distribution. - /// The location parameter of the distribution. + /// The stability (α) of the distribution. + /// The skewness (β) of the distribution. + /// The scale (c) of the distribution. + /// The location (μ) of the distribution. /// a random number from the distribution. internal static double SampleUnchecked(System.Random rnd, double alpha, double beta, double scale, double location) { @@ -464,10 +456,10 @@ namespace MathNet.Numerics.Distributions /// Generates a sample from the distribution. /// /// The random number generator to use. - /// The stability parameter of the distribution. - /// The skewness parameter of the distribution. - /// The scale parameter of the distribution. - /// The location parameter of the distribution. + /// The stability (α) of the distribution. + /// The skewness (β) of the distribution. + /// The scale (c) of the distribution. + /// The location (μ) of the distribution. /// a sample from the distribution. public static double Sample(System.Random rnd, double alpha, double beta, double scale, double location) { @@ -483,10 +475,10 @@ namespace MathNet.Numerics.Distributions /// Generates a sequence of samples from the distribution. /// /// The random number generator to use. - /// The stability parameter of the distribution. - /// The skewness parameter of the distribution. - /// The scale parameter of the distribution. - /// The location parameter of the distribution. + /// The stability (α) of the distribution. + /// The skewness (β) of the distribution. + /// The scale (c) of the distribution. + /// The location (μ) of the distribution. /// a sequence of samples from the distribution. public static IEnumerable Samples(System.Random rnd, double alpha, double beta, double scale, double location) { diff --git a/src/Numerics/Distributions/StudentT.cs b/src/Numerics/Distributions/StudentT.cs index 9b7f7782..d4f6a38d 100644 --- a/src/Numerics/Distributions/StudentT.cs +++ b/src/Numerics/Distributions/StudentT.cs @@ -142,15 +142,6 @@ namespace MathNet.Numerics.Distributions _freedom = dof; } - /// - /// Gets or sets the random number generator which is used to draw random samples. - /// - public System.Random RandomSource - { - get { return _random; } - set { _random = value ?? new System.Random(); } - } - /// /// Gets or sets the location of the Student t-distribution. /// @@ -178,6 +169,15 @@ namespace MathNet.Numerics.Distributions set { SetParameters(_location, _scale, value); } } + /// + /// Gets or sets the random number generator which is used to draw random samples. + /// + public System.Random RandomSource + { + get { return _random; } + set { _random = value ?? new System.Random(); } + } + /// /// Gets the mean of the Student t-distribution. /// diff --git a/src/Numerics/Distributions/Weibull.cs b/src/Numerics/Distributions/Weibull.cs index 90846d2b..200a39d5 100644 --- a/src/Numerics/Distributions/Weibull.cs +++ b/src/Numerics/Distributions/Weibull.cs @@ -1,4 +1,4 @@ -// +// // Math.NET Numerics, part of the Math.NET Project // http://numerics.mathdotnet.com // http://github.com/mathnet/mathnet-numerics @@ -65,8 +65,8 @@ namespace MathNet.Numerics.Distributions /// /// Initializes a new instance of the Weibull class. /// - /// The shape of the Weibull distribution. - /// The inverse scale of the Weibull distribution. + /// The shape (k) of the Weibull distribution. + /// The scale (λ) of the Weibull distribution. public Weibull(double shape, double scale) { _random = new System.Random(); @@ -76,8 +76,8 @@ namespace MathNet.Numerics.Distributions /// /// Initializes a new instance of the Weibull class. /// - /// The shape of the Weibull distribution. - /// The inverse scale of the Weibull distribution. + /// The shape (k) of the Weibull distribution. + /// The scale (λ) of the Weibull distribution. /// The random number generator which is used to draw random samples. public Weibull(double shape, double scale, System.Random randomSource) { @@ -91,14 +91,14 @@ namespace MathNet.Numerics.Distributions /// a string representation of the distribution. public override string ToString() { - return "Weibull(Shape = " + _shape + ", Scale = " + _scale + ")"; + return "Weibull(k = " + _shape + ", λ = " + _scale + ")"; } /// /// Checks whether the parameters of the distribution are valid. /// - /// The shape of the Weibull distribution. - /// The scale of the Weibull distribution. + /// The shape (k) of the Weibull distribution. + /// The scale (λ) of the Weibull distribution. /// true when the parameters positive valid floating point numbers, false otherwise. static bool IsValidParameterSet(double shape, double scale) { @@ -108,8 +108,8 @@ namespace MathNet.Numerics.Distributions /// /// Sets the parameters of the distribution after checking their validity. /// - /// The shape of the Weibull distribution. - /// The inverse scale of the Weibull distribution. + /// The shape (k) of the Weibull distribution. + /// The scale (λ) of the Weibull distribution. /// When the parameters don't pass the function. void SetParameters(double shape, double scale) { @@ -124,16 +124,7 @@ namespace MathNet.Numerics.Distributions } /// - /// Gets or sets the random number generator which is used to draw random samples. - /// - public System.Random RandomSource - { - get { return _random; } - set { _random = value ?? new System.Random(); } - } - - /// - /// Gets or sets the shape of the Weibull distribution. + /// Gets or sets the shape (k) of the Weibull distribution. /// public double Shape { @@ -142,7 +133,7 @@ namespace MathNet.Numerics.Distributions } /// - /// Gets or sets the scale of the Weibull distribution. + /// Gets or sets the scale (λ) of the Weibull distribution. /// public double Scale { @@ -150,6 +141,15 @@ namespace MathNet.Numerics.Distributions set { SetParameters(_shape, value); } } + /// + /// Gets or sets the random number generator which is used to draw random samples. + /// + public System.Random RandomSource + { + get { return _random; } + set { _random = value ?? new System.Random(); } + } + /// /// Gets the mean of the Weibull distribution. /// @@ -297,8 +297,8 @@ namespace MathNet.Numerics.Distributions /// any parameter checks. /// /// The random number generator to use. - /// The shape of the Weibull distribution. - /// The scale of the Weibull distribution. + /// The shape (k) of the Weibull distribution. + /// The scale (λ) of the Weibull distribution. /// A sample from a Weibull distributed random variable. internal static double SampleUnchecked(System.Random rnd, double shape, double scale) { @@ -331,8 +331,8 @@ namespace MathNet.Numerics.Distributions /// Generates a sample from the Weibull distribution. /// /// The random number generator to use. - /// The shape of the Weibull distribution from which to generate samples. - /// The scale of the Weibull distribution from which to generate samples. + /// The shape (k) of the Weibull distribution. + /// The scale (λ) of the Weibull distribution. /// a sample from the distribution. public static double Sample(System.Random rng, double shape, double scale) { @@ -348,8 +348,8 @@ namespace MathNet.Numerics.Distributions /// Generates a sequence of samples from the Weibull distribution. /// /// The random number generator to use. - /// The shape of the Weibull distribution from which to generate samples. - /// The scale of the Weibull distribution from which to generate samples. + /// The shape (k) of the Weibull distribution. + /// The scale (λ) of the Weibull distribution. /// a sequence of samples from the distribution. public static IEnumerable Samples(System.Random rng, double shape, double scale) { diff --git a/src/Numerics/Distributions/Wishart.cs b/src/Numerics/Distributions/Wishart.cs index 9e88d661..18ef9d22 100644 --- a/src/Numerics/Distributions/Wishart.cs +++ b/src/Numerics/Distributions/Wishart.cs @@ -55,12 +55,12 @@ namespace MathNet.Numerics.Distributions /// /// The degrees of freedom for the Wishart distribution. /// - double _nu; + double _degreeOfFreedom; /// /// The scale matrix for the Wishart distribution. /// - Matrix _s; + Matrix _scale; /// /// Caches the Cholesky factorization of the scale matrix. @@ -70,66 +70,66 @@ namespace MathNet.Numerics.Distributions /// /// Initializes a new instance of the class. /// - /// The degrees of freedom for the Wishart distribution. - /// The scale matrix for the Wishart distribution. - public Wishart(double nu, Matrix s) + /// The degrees of freedom (n) for the Wishart distribution. + /// The scale matrix (V) for the Wishart distribution. + public Wishart(double degreeOfFreedom, Matrix scale) { _random = new System.Random(); - SetParameters(nu, s); + SetParameters(degreeOfFreedom, scale); } /// /// Initializes a new instance of the class. /// - /// The degrees of freedom for the Wishart distribution. - /// The scale matrix for the Wishart distribution. + /// The degrees of freedom (n) for the Wishart distribution. + /// The scale matrix (V) for the Wishart distribution. /// The random number generator which is used to draw random samples. - public Wishart(double nu, Matrix s, System.Random randomSource) + public Wishart(double degreeOfFreedom, Matrix scale, System.Random randomSource) { _random = randomSource ?? new System.Random(); - SetParameters(nu, s); + SetParameters(degreeOfFreedom, scale); } /// /// Sets the parameters of the distribution after checking their validity. /// - /// The degrees of freedom for the Wishart distribution. - /// The scale matrix for the Wishart distribution. + /// The degrees of freedom (n) for the Wishart distribution. + /// The scale matrix (V) for the Wishart distribution. /// When the parameters don't pass the function. - void SetParameters(double nu, Matrix s) + void SetParameters(double degreeOfFreedom, Matrix scale) { - if (Control.CheckDistributionParameters && !IsValidParameterSet(nu, s)) + if (Control.CheckDistributionParameters && !IsValidParameterSet(degreeOfFreedom, scale)) { throw new ArgumentOutOfRangeException(Resources.InvalidDistributionParameters); } - _nu = nu; - _s = s; - _chol = Cholesky.Create(_s); + _degreeOfFreedom = degreeOfFreedom; + _scale = scale; + _chol = Cholesky.Create(_scale); } /// /// Checks whether the parameters of the distribution are valid. /// - /// The degrees of freedom for the Wishart distribution. - /// The scale matrix for the Wishart distribution. + /// The degrees of freedom (n) for the Wishart distribution. + /// The scale matrix (V) for the Wishart distribution. /// true when the parameters are valid, false otherwise. - static bool IsValidParameterSet(double nu, Matrix s) + static bool IsValidParameterSet(double degreeOfFreedom, Matrix scale) { - if (s.RowCount != s.ColumnCount) + if (scale.RowCount != scale.ColumnCount) { return false; } - for (var i = 0; i < s.RowCount; i++) + for (var i = 0; i < scale.RowCount; i++) { - if (s.At(i, i) <= 0.0) + if (scale.At(i, i) <= 0.0) { return false; } } - if (nu <= 0.0 || Double.IsNaN(nu)) + if (degreeOfFreedom <= 0.0 || Double.IsNaN(degreeOfFreedom)) { return false; } @@ -138,21 +138,21 @@ namespace MathNet.Numerics.Distributions } /// - /// Gets or sets the degrees of freedom for the Wishart distribution. + /// Gets or sets the degrees of freedom (n) for the Wishart distribution. /// - public double Nu + public double DegreeOfFreedom { - get { return _nu; } - set { SetParameters(value, _s); } + get { return _degreeOfFreedom; } + set { SetParameters(value, _scale); } } /// - /// Gets or sets the scale matrix for the Wishart distribution. + /// Gets or sets the scale matrix (V) for the Wishart distribution. /// - public Matrix S + public Matrix Scale { - get { return _s; } - set { SetParameters(_nu, value); } + get { return _scale; } + set { SetParameters(_degreeOfFreedom, value); } } /// @@ -161,7 +161,7 @@ namespace MathNet.Numerics.Distributions /// a string representation of the distribution. public override string ToString() { - return "Wishart(Nu = " + _nu + ", Rows = " + _s.RowCount + ", Columns = " + _s.ColumnCount + ")"; + return "Wishart(DegreeOfFreedom = " + _degreeOfFreedom + ", Rows = " + _scale.RowCount + ", Columns = " + _scale.ColumnCount + ")"; } /// @@ -187,7 +187,7 @@ namespace MathNet.Numerics.Distributions /// The mean of the distribution. public Matrix Mean { - get { return _nu*_s; } + get { return _degreeOfFreedom*_scale; } } /// @@ -196,7 +196,7 @@ namespace MathNet.Numerics.Distributions /// The mode of the distribution. public Matrix Mode { - get { return (_nu - _s.RowCount - 1.0)*_s; } + get { return (_degreeOfFreedom - _scale.RowCount - 1.0)*_scale; } } /// @@ -207,12 +207,12 @@ namespace MathNet.Numerics.Distributions { get { - var res = _s.CreateMatrix(_s.RowCount, _s.ColumnCount); + var res = _scale.CreateMatrix(_scale.RowCount, _scale.ColumnCount); for (var i = 0; i < res.RowCount; i++) { for (var j = 0; j < res.ColumnCount; j++) { - res.At(i, j, _nu*((_s.At(i, j)*_s.At(i, j)) + (_s.At(i, i)*_s.At(j, j)))); + res.At(i, j, _degreeOfFreedom*((_scale.At(i, j)*_scale.At(i, j)) + (_scale.At(i, i)*_scale.At(j, j)))); } } @@ -228,11 +228,11 @@ namespace MathNet.Numerics.Distributions /// the density at . public double Density(Matrix x) { - var p = _s.RowCount; + var p = _scale.RowCount; if (x.RowCount != p || x.ColumnCount != p) { - throw Matrix.DimensionsDontMatch(x, _s, "x"); + throw Matrix.DimensionsDontMatch(x, _scale, "x"); } var dX = x.Determinant(); @@ -242,13 +242,13 @@ namespace MathNet.Numerics.Distributions var gp = Math.Pow(Constants.Pi, p*(p - 1.0)/4.0); for (var j = 1; j <= p; j++) { - gp *= SpecialFunctions.Gamma((_nu + 1.0 - j)/2.0); + gp *= SpecialFunctions.Gamma((_degreeOfFreedom + 1.0 - j)/2.0); } - return Math.Pow(dX, (_nu - p - 1.0)/2.0) + return Math.Pow(dX, (_degreeOfFreedom - 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) + /Math.Pow(2.0, _degreeOfFreedom*p/2.0) + /Math.Pow(_chol.Determinant, _degreeOfFreedom/2.0) /gp; } @@ -261,7 +261,7 @@ namespace MathNet.Numerics.Distributions /// A random number from this distribution. public Matrix Sample() { - return DoSample(RandomSource, _nu, _s, _chol); + return DoSample(RandomSource, _degreeOfFreedom, _scale, _chol); } /// @@ -271,37 +271,37 @@ namespace MathNet.Numerics.Distributions /// Applied Statistics, Vol. 21, No. 3 (1972), pp. 341-345 /// /// The random number generator to use. - /// The degrees of freedom. - /// The scale matrix. + /// The degrees of freedom (n) for the Wishart distribution. + /// The scale matrix (V) for the Wishart distribution. /// a sequence of samples from the distribution. - public static Matrix Sample(System.Random rnd, double nu, Matrix s) + public static Matrix Sample(System.Random rnd, double degreeOfFreedom, Matrix scale) { - if (Control.CheckDistributionParameters && !IsValidParameterSet(nu, s)) + if (Control.CheckDistributionParameters && !IsValidParameterSet(degreeOfFreedom, scale)) { throw new ArgumentOutOfRangeException(Resources.InvalidDistributionParameters); } - return DoSample(rnd, nu, s, Cholesky.Create(s)); + return DoSample(rnd, degreeOfFreedom, scale, Cholesky.Create(scale)); } /// /// Samples the distribution. /// /// The random number generator to use. - /// The nu parameter to use. - /// The S parameter to use. + /// The degrees of freedom (n) for the Wishart distribution. + /// The scale matrix (V) for the Wishart distribution. /// The cholesky decomposition to use. /// a random number from the distribution. - static Matrix DoSample(System.Random rnd, double nu, Matrix s, Cholesky chol) + static Matrix DoSample(System.Random rnd, double degreeOfFreedom, Matrix scale, Cholesky chol) { - var count = s.RowCount; + var count = scale.RowCount; // First generate a lower triangular matrix with Sqrt(Chi-Squares) on the diagonal // and normal distributed variables in the lower triangle. var a = new DenseMatrix(count, count); for (var d = 0; d < count; d++) { - a.At(d, d, Math.Sqrt(Gamma.Sample(rnd, (nu - d)/2.0, 0.5))); + a.At(d, d, Math.Sqrt(Gamma.Sample(rnd, (degreeOfFreedom - d)/2.0, 0.5))); } for (var i = 1; i < count; i++) diff --git a/src/Numerics/Distributions/Zipf.cs b/src/Numerics/Distributions/Zipf.cs index 6ca4a08f..f62ee110 100644 --- a/src/Numerics/Distributions/Zipf.cs +++ b/src/Numerics/Distributions/Zipf.cs @@ -120,15 +120,6 @@ namespace MathNet.Numerics.Distributions _n = n; } - /// - /// Gets or sets the random number generator which is used to draw random samples. - /// - public System.Random RandomSource - { - get { return _random; } - set { _random = value ?? new System.Random(); } - } - /// /// Gets or sets the s parameter of the distribution. /// @@ -147,6 +138,15 @@ namespace MathNet.Numerics.Distributions set { SetParameters(_s, value); } } + /// + /// Gets or sets the random number generator which is used to draw random samples. + /// + public System.Random RandomSource + { + get { return _random; } + set { _random = value ?? new System.Random(); } + } + /// /// Gets the mean of the distribution. /// diff --git a/src/UnitTests/DistributionTests/Continuous/BetaTests.cs b/src/UnitTests/DistributionTests/Continuous/BetaTests.cs index ff5971e6..6381b4b8 100644 --- a/src/UnitTests/DistributionTests/Continuous/BetaTests.cs +++ b/src/UnitTests/DistributionTests/Continuous/BetaTests.cs @@ -1,4 +1,4 @@ -// +// // Math.NET Numerics, part of the Math.NET Project // http://numerics.mathdotnet.com // http://github.com/mathnet/mathnet-numerics @@ -90,8 +90,8 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous [Test] public void ValidateToString() { - var n = new Beta(1.0, 2.0); - Assert.AreEqual("Beta(A = 1, B = 2)", n.ToString()); + var n = new Beta(1d, 2d); + Assert.AreEqual("Beta(α = 1, β = 2)", n.ToString()); } /// diff --git a/src/UnitTests/DistributionTests/Continuous/CauchyTests.cs b/src/UnitTests/DistributionTests/Continuous/CauchyTests.cs index 90331e19..0c9c8396 100644 --- a/src/UnitTests/DistributionTests/Continuous/CauchyTests.cs +++ b/src/UnitTests/DistributionTests/Continuous/CauchyTests.cs @@ -1,4 +1,4 @@ -// +// // Math.NET Numerics, part of the Math.NET Project // http://numerics.mathdotnet.com // http://github.com/mathnet/mathnet-numerics @@ -95,8 +95,8 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous [Test] public void ValidateToString() { - var n = new Cauchy(1.0, 2.0); - Assert.AreEqual("Cauchy(Location = 1, Scale = 2)", n.ToString()); + var n = new Cauchy(1d, 2d); + Assert.AreEqual("Cauchy(x0 = 1, γ = 2)", n.ToString()); } /// diff --git a/src/UnitTests/DistributionTests/Continuous/ContinuousUniformTests.cs b/src/UnitTests/DistributionTests/Continuous/ContinuousUniformTests.cs index 51f72bff..363a47d5 100644 --- a/src/UnitTests/DistributionTests/Continuous/ContinuousUniformTests.cs +++ b/src/UnitTests/DistributionTests/Continuous/ContinuousUniformTests.cs @@ -55,8 +55,8 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous public void CanCreateContinuousUniform() { var n = new ContinuousUniform(); - Assert.AreEqual(0.0, n.Lower); - Assert.AreEqual(1.0, n.Upper); + Assert.AreEqual(0.0, n.LowerBound); + Assert.AreEqual(1.0, n.UpperBound); } /// @@ -74,8 +74,8 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous public void CanCreateContinuousUniform(double lower, double upper) { var n = new ContinuousUniform(lower, upper); - Assert.AreEqual(lower, n.Lower); - Assert.AreEqual(upper, n.Upper); + Assert.AreEqual(lower, n.LowerBound); + Assert.AreEqual(upper, n.UpperBound); } /// @@ -115,7 +115,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous { new ContinuousUniform { - Lower = lower + LowerBound = lower }; } @@ -126,7 +126,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous public void SetBadLowerFails() { var n = new ContinuousUniform(); - Assert.Throws(() => n.Lower = 3.0); + Assert.Throws(() => n.LowerBound = 3.0); } /// @@ -140,7 +140,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous { new ContinuousUniform { - Upper = upper + UpperBound = upper }; } @@ -151,7 +151,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous public void SetBadUpperFails() { var n = new ContinuousUniform(); - Assert.Throws(() => n.Upper = -1.0); + Assert.Throws(() => n.UpperBound = -1.0); } /// diff --git a/src/UnitTests/DistributionTests/Continuous/ErlangTests.cs b/src/UnitTests/DistributionTests/Continuous/ErlangTests.cs index 2ce6978b..d934b075 100644 --- a/src/UnitTests/DistributionTests/Continuous/ErlangTests.cs +++ b/src/UnitTests/DistributionTests/Continuous/ErlangTests.cs @@ -1,4 +1,4 @@ -// +// // Math.NET Numerics, part of the Math.NET Project // http://numerics.mathdotnet.com // http://github.com/mathnet/mathnet-numerics @@ -61,7 +61,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous { var n = new Erlang(shape, invScale); Assert.AreEqual(shape, n.Shape); - Assert.AreEqual(invScale, n.InvScale); + Assert.AreEqual(invScale, n.Rate); } /// @@ -92,9 +92,9 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous [TestCase(10, Double.PositiveInfinity)] public void CanCreateErlangWithShapeInvScale(int shape, double invScale) { - var n = Erlang.WithShapeInvScale(shape, invScale); + var n = Erlang.WithShapeRate(shape, invScale); Assert.AreEqual(shape, n.Shape); - Assert.AreEqual(invScale, n.InvScale); + Assert.AreEqual(invScale, n.Rate); } /// @@ -121,8 +121,8 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous [Test] public void ValidateToString() { - var n = new Erlang(1, 2.0); - Assert.AreEqual("Erlang(Shape = 1, Inverse Scale = 2)", n.ToString()); + var n = new Erlang(1, 2d); + Assert.AreEqual("Erlang(Shape = 1, λ = 2)", n.ToString()); } /// @@ -193,7 +193,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous { new Erlang(1, 1.0) { - InvScale = invScale + Rate = invScale }; } @@ -204,7 +204,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous public void SetInvScaleFailsWithNegativeInvScale() { var n = new Erlang(1, 1.0); - Assert.Throws(() => n.InvScale = -1.0); + Assert.Throws(() => n.Rate = -1.0); } /// diff --git a/src/UnitTests/DistributionTests/Continuous/ExponentialTests.cs b/src/UnitTests/DistributionTests/Continuous/ExponentialTests.cs index 2659468e..5205dcd5 100644 --- a/src/UnitTests/DistributionTests/Continuous/ExponentialTests.cs +++ b/src/UnitTests/DistributionTests/Continuous/ExponentialTests.cs @@ -1,4 +1,4 @@ -// +// // Math.NET Numerics, part of the Math.NET Project // http://numerics.mathdotnet.com // http://github.com/mathnet/mathnet-numerics @@ -58,7 +58,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous public void CanCreateExponential(double lambda) { var n = new Exponential(lambda); - Assert.AreEqual(lambda, n.Lambda); + Assert.AreEqual(lambda, n.Rate); } /// @@ -79,8 +79,8 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous [Test] public void ValidateToString() { - var n = new Exponential(2.0); - Assert.AreEqual("Exponential(Lambda = 2)", n.ToString()); + var n = new Exponential(2d); + Assert.AreEqual("Exponential(λ = 2)", n.ToString()); } /// @@ -97,7 +97,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous { new Exponential(1.0) { - Lambda = lambda + Rate = lambda }; } @@ -108,7 +108,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous public void SetLambdaFailsWithNegativeLambda() { var n = new Exponential(1.0); - Assert.Throws(() => n.Lambda = -1.0); + Assert.Throws(() => n.Rate = -1.0); } /// diff --git a/src/UnitTests/DistributionTests/Continuous/GammaTests.cs b/src/UnitTests/DistributionTests/Continuous/GammaTests.cs index 85df4664..a7e6b2bf 100644 --- a/src/UnitTests/DistributionTests/Continuous/GammaTests.cs +++ b/src/UnitTests/DistributionTests/Continuous/GammaTests.cs @@ -1,4 +1,4 @@ -// +// // Math.NET Numerics, part of the Math.NET Project // http://numerics.mathdotnet.com // http://github.com/mathnet/mathnet-numerics @@ -63,7 +63,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous { var n = new Gamma(shape, invScale); Assert.AreEqual(shape, n.Shape); - Assert.AreEqual(invScale, n.InvScale); + Assert.AreEqual(invScale, n.Rate); } /// @@ -94,9 +94,9 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous [TestCase(10.0, Double.PositiveInfinity)] public void CanCreateGammaWithShapeInvScale(double shape, double invScale) { - var n = Gamma.WithShapeInvScale(shape, invScale); + var n = Gamma.WithShapeRate(shape, invScale); Assert.AreEqual(shape, n.Shape); - Assert.AreEqual(invScale, n.InvScale); + Assert.AreEqual(invScale, n.Rate); } /// @@ -123,8 +123,8 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous [Test] public void ValidateToString() { - var n = new Gamma(1.0, 2.0); - Assert.AreEqual("Gamma(Shape = 1, Inverse Scale = 2)", n.ToString()); + var n = new Gamma(1d, 2d); + Assert.AreEqual("Gamma(α = 1, β = 2)", n.ToString()); } /// @@ -197,7 +197,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous { new Gamma(1.0, 1.0) { - InvScale = invScale + Rate = invScale }; } @@ -208,7 +208,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous public void SetInvScaleFailsWithNegativeInvScale() { var n = new Gamma(1.0, 1.0); - Assert.Throws(() => n.InvScale = -1.0); + Assert.Throws(() => n.Rate = -1.0); } /// diff --git a/src/UnitTests/DistributionTests/Continuous/InverseGammaTests.cs b/src/UnitTests/DistributionTests/Continuous/InverseGammaTests.cs index 91921ebc..3de4c931 100644 --- a/src/UnitTests/DistributionTests/Continuous/InverseGammaTests.cs +++ b/src/UnitTests/DistributionTests/Continuous/InverseGammaTests.cs @@ -1,4 +1,4 @@ -// +// // Math.NET Numerics, part of the Math.NET Project // http://numerics.mathdotnet.com // http://github.com/mathnet/mathnet-numerics @@ -87,8 +87,8 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous [Test] public void ValidateToString() { - var n = new InverseGamma(1.1, 2.1); - Assert.AreEqual(String.Format("InverseGamma(Shape = {0}, Inverse Scale = {1})", n.Shape, n.Scale), n.ToString()); + var n = new InverseGamma(1.1d, 2.1d); + Assert.AreEqual("InverseGamma(α = 1.1, β = 2.1)", n.ToString()); } /// diff --git a/src/UnitTests/DistributionTests/Continuous/LaplaceTests.cs b/src/UnitTests/DistributionTests/Continuous/LaplaceTests.cs index 5eb5225d..6a06af3a 100644 --- a/src/UnitTests/DistributionTests/Continuous/LaplaceTests.cs +++ b/src/UnitTests/DistributionTests/Continuous/LaplaceTests.cs @@ -1,4 +1,4 @@ -// +// // Math.NET Numerics, part of the Math.NET Project // http://numerics.mathdotnet.com // http://github.com/mathnet/mathnet-numerics @@ -81,8 +81,8 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous [Test] public void ValidateToString() { - var n = new Laplace(-1.0, 2.0); - Assert.AreEqual("Laplace(Location = -1, Scale = 2)", n.ToString()); + var n = new Laplace(-1d, 2d); + Assert.AreEqual("Laplace(μ = -1, b = 2)", n.ToString()); } /// diff --git a/src/UnitTests/DistributionTests/Continuous/LogNormalTests.cs b/src/UnitTests/DistributionTests/Continuous/LogNormalTests.cs index 3edec8f8..c8503de8 100644 --- a/src/UnitTests/DistributionTests/Continuous/LogNormalTests.cs +++ b/src/UnitTests/DistributionTests/Continuous/LogNormalTests.cs @@ -1,4 +1,4 @@ -// +// // Math.NET Numerics, part of the Math.NET Project // http://numerics.mathdotnet.com // http://github.com/mathnet/mathnet-numerics @@ -86,8 +86,8 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous [Test] public void ValidateToString() { - var n = new LogNormal(1.0, 2.0); - Assert.AreEqual("LogNormal(Mu = 1, Sigma = 2)", n.ToString()); + var n = new LogNormal(1d, 2d); + Assert.AreEqual("LogNormal(μ = 1, σ = 2)", n.ToString()); } /// diff --git a/src/UnitTests/DistributionTests/Continuous/NormalTests.cs b/src/UnitTests/DistributionTests/Continuous/NormalTests.cs index fc16a6cd..a0a68323 100644 --- a/src/UnitTests/DistributionTests/Continuous/NormalTests.cs +++ b/src/UnitTests/DistributionTests/Continuous/NormalTests.cs @@ -1,4 +1,4 @@ -// +// // Math.NET Numerics, part of the Math.NET Project // http://numerics.mathdotnet.com // http://github.com/mathnet/mathnet-numerics @@ -151,8 +151,8 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous [Test] public void ValidateToString() { - var n = new Normal(1.0, 2.0); - Assert.AreEqual("Normal(Mean = 1, StdDev = 2)", n.ToString()); + var n = new Normal(1d, 2d); + Assert.AreEqual("Normal(μ = 1, σ = 2)", n.ToString()); } /// diff --git a/src/UnitTests/DistributionTests/Continuous/ParetoTests.cs b/src/UnitTests/DistributionTests/Continuous/ParetoTests.cs index 7cb1bfc4..8f554a45 100644 --- a/src/UnitTests/DistributionTests/Continuous/ParetoTests.cs +++ b/src/UnitTests/DistributionTests/Continuous/ParetoTests.cs @@ -1,4 +1,4 @@ -// +// // Math.NET Numerics, part of the Math.NET Project // http://numerics.mathdotnet.com // http://github.com/mathnet/mathnet-numerics @@ -87,8 +87,8 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous [Test] public void ValidateToString() { - var n = new Pareto(1.0, 2.0); - Assert.AreEqual("Pareto(Scale = 1, Shape = 2)", n.ToString()); + var n = new Pareto(1d, 2d); + Assert.AreEqual("Pareto(xm = 1, α = 2)", n.ToString()); } /// diff --git a/src/UnitTests/DistributionTests/Continuous/RayleighTests.cs b/src/UnitTests/DistributionTests/Continuous/RayleighTests.cs index c30ed9fc..f37d01d5 100644 --- a/src/UnitTests/DistributionTests/Continuous/RayleighTests.cs +++ b/src/UnitTests/DistributionTests/Continuous/RayleighTests.cs @@ -1,4 +1,4 @@ -// +// // Math.NET Numerics, part of the Math.NET Project // http://numerics.mathdotnet.com // http://github.com/mathnet/mathnet-numerics @@ -79,8 +79,8 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous [Test] public void ValidateToString() { - var n = new Rayleigh(2.0); - Assert.AreEqual("Rayleigh(Scale = 2)", n.ToString()); + var n = new Rayleigh(2d); + Assert.AreEqual("Rayleigh(σ = 2)", n.ToString()); } /// diff --git a/src/UnitTests/DistributionTests/Continuous/StableTests.cs b/src/UnitTests/DistributionTests/Continuous/StableTests.cs index bf9a0a8c..dfb0dcdb 100644 --- a/src/UnitTests/DistributionTests/Continuous/StableTests.cs +++ b/src/UnitTests/DistributionTests/Continuous/StableTests.cs @@ -1,4 +1,4 @@ -// +// // Math.NET Numerics, part of the Math.NET Project // http://numerics.mathdotnet.com // http://github.com/mathnet/mathnet-numerics @@ -103,8 +103,8 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous [Test] public void ValidateToString() { - var n = new Stable(1.2, 0.3, 1.0, 2.0); - Assert.AreEqual(String.Format("Stable(Stability = {0}, Skewness = {1}, Scale = {2}, Location = {3})", n.Alpha, n.Beta, n.Scale, n.Location), n.ToString()); + var n = new Stable(1.2d, 0.3d, 1d, 2d); + Assert.AreEqual("Stable(α = 1.2, β = 0.3, c = 1, μ = 2)", n.ToString()); } /// diff --git a/src/UnitTests/DistributionTests/Continuous/WeibullTests.cs b/src/UnitTests/DistributionTests/Continuous/WeibullTests.cs index 852e0066..c67426fb 100644 --- a/src/UnitTests/DistributionTests/Continuous/WeibullTests.cs +++ b/src/UnitTests/DistributionTests/Continuous/WeibullTests.cs @@ -1,4 +1,4 @@ -// +// // Math.NET Numerics, part of the Math.NET Project // http://numerics.mathdotnet.com // http://github.com/mathnet/mathnet-numerics @@ -89,8 +89,8 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous [Test] public void ValidateToString() { - var n = new Weibull(1.0, 2.0); - Assert.AreEqual("Weibull(Shape = 1, Scale = 2)", n.ToString()); + var n = new Weibull(1d, 2d); + Assert.AreEqual("Weibull(k = 1, λ = 2)", n.ToString()); } /// diff --git a/src/UnitTests/DistributionTests/Discrete/ConwayMaxwellPoissonTests.cs b/src/UnitTests/DistributionTests/Discrete/ConwayMaxwellPoissonTests.cs index 64f1d60e..bc0a2b69 100644 --- a/src/UnitTests/DistributionTests/Discrete/ConwayMaxwellPoissonTests.cs +++ b/src/UnitTests/DistributionTests/Discrete/ConwayMaxwellPoissonTests.cs @@ -1,4 +1,4 @@ -// +// // Math.NET Numerics, part of the Math.NET Project // http://numerics.mathdotnet.com // http://github.com/mathnet/mathnet-numerics @@ -50,7 +50,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete /// Can create ConwayMaxwellPoisson. /// /// Lambda value. - /// Nu parameter. + /// DegreeOfFreedom parameter. [TestCase(0.1, 0.0)] [TestCase(1.0, 2.5)] [TestCase(2.5, 3.0)] @@ -78,8 +78,8 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete [Test] public void ValidateToString() { - var d = new ConwayMaxwellPoisson(1.0, 2.0); - Assert.AreEqual("ConwayMaxwellPoisson(Lambda = 1, Nu = 2)", d.ToString()); + var d = new ConwayMaxwellPoisson(1d, 2d); + Assert.AreEqual("ConwayMaxwellPoisson(λ = 1, ν = 2)", d.ToString()); } /// @@ -99,9 +99,9 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete } /// - /// Can set Nu. + /// Can set DegreeOfFreedom. /// - /// Nu parameter. + /// DegreeOfFreedom parameter. [TestCase(0.0)] [TestCase(3.0)] [TestCase(10.0)] @@ -129,9 +129,9 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete } /// - /// Set Nu with bad values fails. + /// Set DegreeOfFreedom with bad values fails. /// - /// Nu parameter. + /// DegreeOfFreedom parameter. [TestCase(-0.1)] [TestCase(-1.0)] [TestCase(-10.0)] @@ -186,7 +186,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete /// Validate mean. /// /// Lambda value. - /// Nu parameter. + /// DegreeOfFreedom parameter. /// Expected value. [TestCase(1, 1, 1.0)] [TestCase(2, 1, 2.0)] @@ -224,7 +224,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete /// Validate probability. /// /// Lambda value. - /// Nu parameter. + /// DegreeOfFreedom parameter. /// Input X value. /// Expected value. [TestCase(1.0, 1.0, 1, 0.367879441171442)] @@ -243,7 +243,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete /// Validate probability log. /// /// Lambda value. - /// Nu parameter. + /// DegreeOfFreedom parameter. /// Input X value. /// Expected value. [TestCase(1.0, 1.0, 1, -1.0)] @@ -283,7 +283,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete /// Validate cumulative distribution. /// /// Lambda value. - /// Nu parameter. + /// DegreeOfFreedom parameter. /// Input X value. /// Expected value. [TestCase(1.0, 1.0, 1, 0.735758882342885)] diff --git a/src/UnitTests/DistributionTests/Multivariate/InverseWishartTests.cs b/src/UnitTests/DistributionTests/Multivariate/InverseWishartTests.cs index 24a90a34..28677e8c 100644 --- a/src/UnitTests/DistributionTests/Multivariate/InverseWishartTests.cs +++ b/src/UnitTests/DistributionTests/Multivariate/InverseWishartTests.cs @@ -1,4 +1,4 @@ -// +// // Math.NET Numerics, part of the Math.NET Project // http://numerics.mathdotnet.com // http://github.com/mathnet/mathnet-numerics @@ -50,7 +50,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Multivariate /// /// Can create inverse Wishart. /// - /// Nu parameter. + /// DegreeOfFreedom parameter. /// Scale matrix order. [TestCase(0.1, 2)] [TestCase(1.0, 5)] @@ -60,12 +60,12 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Multivariate var matrix = MatrixLoader.GenerateRandomPositiveDefiniteDenseMatrix(order); var d = new InverseWishart(nu, matrix); - Assert.AreEqual(nu, d.Nu); - for (var i = 0; i < d.S.RowCount; i++) + Assert.AreEqual(nu, d.DegreeOfFreedom); + for (var i = 0; i < d.Scale.RowCount; i++) { - for (var j = 0; j < d.S.ColumnCount; j++) + for (var j = 0; j < d.Scale.ColumnCount; j++) { - Assert.AreEqual(matrix[i, j], d.S[i, j]); + Assert.AreEqual(matrix[i, j], d.Scale[i, j]); } } } @@ -73,7 +73,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Multivariate /// /// Fail create inverse Wishart with bad parameters. /// - /// Nu parameter. + /// DegreeOfFreedom parameter. /// Scale matrix order. [TestCase(0.1, 2)] [TestCase(1.0, 5)] @@ -89,7 +89,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Multivariate /// /// Fail create inverse Wishart with bad parameters. /// - /// Nu parameter. + /// DegreeOfFreedom parameter. /// Scale matrix order. [TestCase(-1.0, 2)] [TestCase(Double.NaN, 5)] @@ -135,8 +135,8 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Multivariate [Test] public void ValidateToString() { - var d = new InverseWishart(1.0, MatrixLoader.GenerateRandomPositiveDefiniteDenseMatrix(2)); - Assert.AreEqual("InverseWishart(Nu = 1, Rows = 2, Columns = 2)", d.ToString()); + var d = new InverseWishart(1d, MatrixLoader.GenerateRandomPositiveDefiniteDenseMatrix(2)); + Assert.AreEqual("InverseWishart(ν = 1, Rows = 2, Columns = 2)", d.ToString()); } /// @@ -149,13 +149,13 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Multivariate public void CanGetNu(double nu) { var d = new InverseWishart(nu, MatrixLoader.GenerateRandomPositiveDefiniteDenseMatrix(2)); - Assert.AreEqual(nu, d.Nu); + Assert.AreEqual(nu, d.DegreeOfFreedom); } /// - /// Can set Nu. + /// Can set DegreeOfFreedom. /// - /// Nu parameter. + /// DegreeOfFreedom parameter. [TestCase(1.0)] [TestCase(2.0)] [TestCase(5.0)] @@ -163,7 +163,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Multivariate { new InverseWishart(1.0, MatrixLoader.GenerateRandomPositiveDefiniteDenseMatrix(2)) { - Nu = nu + DegreeOfFreedom = nu }; } @@ -181,7 +181,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Multivariate { for (var j = 0; j < Order; j++) { - Assert.AreEqual(matrix[i, j], d.S[i, j]); + Assert.AreEqual(matrix[i, j], d.Scale[i, j]); } } } @@ -194,14 +194,14 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Multivariate { new InverseWishart(1.0, MatrixLoader.GenerateRandomPositiveDefiniteDenseMatrix(2)) { - S = MatrixLoader.GenerateRandomPositiveDefiniteDenseMatrix(2) + Scale = MatrixLoader.GenerateRandomPositiveDefiniteDenseMatrix(2) }; } /// /// Validate mean. /// - /// Nu parameter. + /// DegreeOfFreedom parameter. /// Scale matrix order. [TestCase(0.1, 2)] [TestCase(1.0, 5)] @@ -211,11 +211,11 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Multivariate var d = new InverseWishart(nu, MatrixLoader.GenerateRandomPositiveDefiniteDenseMatrix(order)); var mean = d.Mean; - for (var i = 0; i < d.S.RowCount; i++) + for (var i = 0; i < d.Scale.RowCount; i++) { - for (var j = 0; j < d.S.ColumnCount; j++) + for (var j = 0; j < d.Scale.ColumnCount; j++) { - Assert.AreEqual(d.S[i, j] * (1.0 / (nu - d.S.RowCount - 1.0)), mean[i, j]); + Assert.AreEqual(d.Scale[i, j] * (1.0 / (nu - d.Scale.RowCount - 1.0)), mean[i, j]); } } } @@ -223,7 +223,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Multivariate /// /// Validate mode. /// - /// Nu parameter. + /// DegreeOfFreedom parameter. /// Scale matrix order. [TestCase(0.1, 2)] [TestCase(1.0, 5)] @@ -233,11 +233,11 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Multivariate var d = new InverseWishart(nu, MatrixLoader.GenerateRandomPositiveDefiniteDenseMatrix(order)); var mode = d.Mode; - for (var i = 0; i < d.S.RowCount; i++) + for (var i = 0; i < d.Scale.RowCount; i++) { - for (var j = 0; j < d.S.ColumnCount; j++) + for (var j = 0; j < d.Scale.ColumnCount; j++) { - Assert.AreEqual(d.S[i, j] * (1.0 / (nu + d.S.RowCount + 1.0)), mode[i, j]); + Assert.AreEqual(d.Scale[i, j] * (1.0 / (nu + d.Scale.RowCount + 1.0)), mode[i, j]); } } } @@ -245,7 +245,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Multivariate /// /// Validate variance. /// - /// Nu parameter. + /// DegreeOfFreedom parameter. /// Scale matrix order. [TestCase(0.1, 2)] [TestCase(1.0, 5)] @@ -255,12 +255,12 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Multivariate var d = new InverseWishart(nu, MatrixLoader.GenerateRandomPositiveDefiniteDenseMatrix(order)); var variance = d.Variance; - for (var i = 0; i < d.S.RowCount; i++) + for (var i = 0; i < d.Scale.RowCount; i++) { - for (var j = 0; j < d.S.ColumnCount; j++) + for (var j = 0; j < d.Scale.ColumnCount; j++) { - var num1 = ((nu - d.S.RowCount + 1) * d.S[i, j] * d.S[i, j]) + ((nu - d.S.RowCount - 1) * d.S[i, i] * d.S[j, j]); - var num2 = (nu - d.S.RowCount) * (nu - d.S.RowCount - 1) * (nu - d.S.RowCount - 1) * (nu - d.S.RowCount - 3); + var num1 = ((nu - d.Scale.RowCount + 1) * d.Scale[i, j] * d.Scale[i, j]) + ((nu - d.Scale.RowCount - 1) * d.Scale[i, i] * d.Scale[j, j]); + var num2 = (nu - d.Scale.RowCount) * (nu - d.Scale.RowCount - 1) * (nu - d.Scale.RowCount - 1) * (nu - d.Scale.RowCount - 3); Assert.AreEqual(num1 / num2, variance[i, j]); } } @@ -269,7 +269,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Multivariate /// /// Validate density. /// - /// Nu parameter. + /// DegreeOfFreedom parameter. /// Expected value. [TestCase(1.0, 0.03228684517430723)] [TestCase(2.0, 0.018096748360719193)] diff --git a/src/UnitTests/DistributionTests/Multivariate/NormalGammaTests.cs b/src/UnitTests/DistributionTests/Multivariate/NormalGammaTests.cs index 1275c68e..a04c28b6 100644 --- a/src/UnitTests/DistributionTests/Multivariate/NormalGammaTests.cs +++ b/src/UnitTests/DistributionTests/Multivariate/NormalGammaTests.cs @@ -264,7 +264,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Multivariate var ng = new NormalGamma(meanLocation, meanScale, precShape, precInvScale); var pm = ng.PrecisionMarginal(); Assert.AreEqual(precShape, pm.Shape); - Assert.AreEqual(precInvScale, pm.InvScale); + Assert.AreEqual(precInvScale, pm.Rate); } /// diff --git a/src/UnitTests/DistributionTests/Multivariate/WishartTests.cs b/src/UnitTests/DistributionTests/Multivariate/WishartTests.cs index 5b12c4c7..9708b26c 100644 --- a/src/UnitTests/DistributionTests/Multivariate/WishartTests.cs +++ b/src/UnitTests/DistributionTests/Multivariate/WishartTests.cs @@ -50,7 +50,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Multivariate /// /// Can create wishart. /// - /// Nu parameter. + /// DegreeOfFreedom parameter. /// Scale matrix order. [TestCase(0.1, 2)] [TestCase(1.0, 5)] @@ -61,12 +61,12 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Multivariate var d = new Wishart(nu, matrix); - Assert.AreEqual(nu, d.Nu); - for (var i = 0; i < d.S.RowCount; i++) + Assert.AreEqual(nu, d.DegreeOfFreedom); + for (var i = 0; i < d.Scale.RowCount; i++) { - for (var j = 0; j < d.S.ColumnCount; j++) + for (var j = 0; j < d.Scale.ColumnCount; j++) { - Assert.AreEqual(matrix[i, j], d.S[i, j]); + Assert.AreEqual(matrix[i, j], d.Scale[i, j]); } } } @@ -74,7 +74,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Multivariate /// /// Fail create Wishart with bad parameters. /// - /// Nu parameter. + /// DegreeOfFreedom parameter. /// Scale matrix order. [TestCase(0.0, 2)] [TestCase(0.1, 5)] @@ -91,7 +91,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Multivariate /// /// Fail create Wishart with bad parameters. /// - /// Nu parameter. + /// DegreeOfFreedom parameter. /// Scale matrix order. [TestCase(-1.0, 2)] [TestCase(Double.NaN, 5)] @@ -140,26 +140,26 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Multivariate public void ValidateToString() { var d = new Wishart(1.0, MatrixLoader.GenerateRandomPositiveDefiniteDenseMatrix(2)); - Assert.AreEqual("Wishart(Nu = 1, Rows = 2, Columns = 2)", d.ToString()); + Assert.AreEqual("Wishart(DegreeOfFreedom = 1, Rows = 2, Columns = 2)", d.ToString()); } /// - /// Can get Nu. + /// Can get DegreeOfFreedom. /// - /// Nu parameter. + /// DegreeOfFreedom parameter. [TestCase(1.0)] [TestCase(2.0)] [TestCase(5.0)] public void CanGetNu(double nu) { var d = new Wishart(nu, MatrixLoader.GenerateRandomPositiveDefiniteDenseMatrix(2)); - Assert.AreEqual(nu, d.Nu); + Assert.AreEqual(nu, d.DegreeOfFreedom); } /// - /// Can set Nu. + /// Can set DegreeOfFreedom. /// - /// Nu parameter. + /// DegreeOfFreedom parameter. [TestCase(1.0)] [TestCase(2.0)] [TestCase(5.0)] @@ -167,7 +167,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Multivariate { new Wishart(1.0, MatrixLoader.GenerateRandomPositiveDefiniteDenseMatrix(2)) { - Nu = nu + DegreeOfFreedom = nu }; } @@ -185,7 +185,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Multivariate { for (var j = 0; j < Order; j++) { - Assert.AreEqual(matrix[i, j], d.S[i, j]); + Assert.AreEqual(matrix[i, j], d.Scale[i, j]); } } } @@ -198,14 +198,14 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Multivariate { new Wishart(1.0, MatrixLoader.GenerateRandomPositiveDefiniteDenseMatrix(2)) { - S = MatrixLoader.GenerateRandomPositiveDefiniteDenseMatrix(2) + Scale = MatrixLoader.GenerateRandomPositiveDefiniteDenseMatrix(2) }; } /// /// Validate mean. /// - /// Nu parameter. + /// DegreeOfFreedom parameter. /// Scale matrix order. [TestCase(0.1, 2)] [TestCase(1.0, 5)] @@ -215,11 +215,11 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Multivariate var d = new Wishart(nu, MatrixLoader.GenerateRandomPositiveDefiniteDenseMatrix(order)); var mean = d.Mean; - for (var i = 0; i < d.S.RowCount; i++) + for (var i = 0; i < d.Scale.RowCount; i++) { - for (var j = 0; j < d.S.ColumnCount; j++) + for (var j = 0; j < d.Scale.ColumnCount; j++) { - Assert.AreEqual(nu * d.S[i, j], mean[i, j]); + Assert.AreEqual(nu * d.Scale[i, j], mean[i, j]); } } } @@ -227,7 +227,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Multivariate /// /// Validate mode. /// - /// Nu parameter. + /// DegreeOfFreedom parameter. /// Scale matrix order. [TestCase(0.1, 2)] [TestCase(1.0, 5)] @@ -237,11 +237,11 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Multivariate var d = new Wishart(nu, MatrixLoader.GenerateRandomPositiveDefiniteDenseMatrix(order)); var mode = d.Mode; - for (var i = 0; i < d.S.RowCount; i++) + for (var i = 0; i < d.Scale.RowCount; i++) { - for (var j = 0; j < d.S.ColumnCount; j++) + for (var j = 0; j < d.Scale.ColumnCount; j++) { - Assert.AreEqual((nu - d.S.RowCount - 1.0) * d.S[i, j], mode[i, j]); + Assert.AreEqual((nu - d.Scale.RowCount - 1.0) * d.Scale[i, j], mode[i, j]); } } } @@ -249,7 +249,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Multivariate /// /// Validate variance. /// - /// Nu parameter. + /// DegreeOfFreedom parameter. /// Scale matrix order. [TestCase(0.1, 2)] [TestCase(1.0, 5)] @@ -259,11 +259,11 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Multivariate var d = new Wishart(nu, MatrixLoader.GenerateRandomPositiveDefiniteDenseMatrix(order)); var variance = d.Variance; - for (var i = 0; i < d.S.RowCount; i++) + for (var i = 0; i < d.Scale.RowCount; i++) { - for (var j = 0; j < d.S.ColumnCount; j++) + for (var j = 0; j < d.Scale.ColumnCount; j++) { - Assert.AreEqual(nu * ((d.S[i, j] * d.S[i, j]) + (d.S[i, i] * d.S[j, j])), variance[i, j]); + Assert.AreEqual(nu * ((d.Scale[i, j] * d.Scale[i, j]) + (d.Scale[i, i] * d.Scale[j, j])), variance[i, j]); } } } @@ -271,7 +271,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Multivariate /// /// Validate density. /// - /// Nu parameter. + /// DegreeOfFreedom parameter. /// Expected value. [TestCase(1.0, 0.014644982561926487)] [TestCase(2.0, 0.041042499311949421)]