diff --git a/src/Numerics/Distributions/Cauchy.cs b/src/Numerics/Distributions/Cauchy.cs index ea09afd3..84060c9d 100644 --- a/src/Numerics/Distributions/Cauchy.cs +++ b/src/Numerics/Distributions/Cauchy.cs @@ -279,7 +279,7 @@ namespace MathNet.Numerics.Distributions /// public static double PDF(double location, double scale, double x) { - if (scale <= 0.0) throw new ArgumentOutOfRangeException("scale", Resources.InvalidDistributionParameters); + if (scale <= 0.0) throw new ArgumentException(Resources.InvalidDistributionParameters); return 1.0/(Constants.Pi*scale*(1.0 + (((x - location)/scale)*((x - location)/scale)))); } @@ -294,7 +294,7 @@ namespace MathNet.Numerics.Distributions /// public static double PDFLn(double location, double scale, double x) { - if (scale <= 0.0) throw new ArgumentOutOfRangeException("scale", Resources.InvalidDistributionParameters); + if (scale <= 0.0) throw new ArgumentException(Resources.InvalidDistributionParameters); return -Math.Log(Constants.Pi*scale*(1.0 + (((x - location)/scale)*((x - location)/scale)))); } @@ -309,7 +309,7 @@ namespace MathNet.Numerics.Distributions /// public static double CDF(double location, double scale, double x) { - if (scale <= 0.0) throw new ArgumentOutOfRangeException("scale", Resources.InvalidDistributionParameters); + if (scale <= 0.0) throw new ArgumentException(Resources.InvalidDistributionParameters); return Math.Atan((x - location)/scale)/Constants.Pi + 0.5; } @@ -325,7 +325,7 @@ namespace MathNet.Numerics.Distributions /// public static double InvCDF(double location, double scale, double p) { - if (scale <= 0.0) throw new ArgumentOutOfRangeException("scale", Resources.InvalidDistributionParameters); + if (scale <= 0.0) throw new ArgumentException(Resources.InvalidDistributionParameters); return p <= 0.0 ? double.NegativeInfinity : p >= 1.0 ? double.PositiveInfinity : location + scale*Math.Tan((p - 0.5)*Constants.Pi); @@ -340,7 +340,7 @@ namespace MathNet.Numerics.Distributions /// a sample from the distribution. public static double Sample(System.Random rnd, double location, double scale) { - if (scale <= 0.0) throw new ArgumentOutOfRangeException("scale", Resources.InvalidDistributionParameters); + if (scale <= 0.0) throw new ArgumentException(Resources.InvalidDistributionParameters); return location + scale*Math.Tan(Constants.Pi*(rnd.NextDouble() - 0.5)); } @@ -354,7 +354,7 @@ namespace MathNet.Numerics.Distributions /// a sequence of samples from the distribution. public static IEnumerable Samples(System.Random rnd, double location, double scale) { - if (scale <= 0.0) throw new ArgumentOutOfRangeException("scale", Resources.InvalidDistributionParameters); + if (scale <= 0.0) throw new ArgumentException(Resources.InvalidDistributionParameters); while (true) { diff --git a/src/Numerics/Distributions/Chi.cs b/src/Numerics/Distributions/Chi.cs index f9f4bfca..09e518e3 100644 --- a/src/Numerics/Distributions/Chi.cs +++ b/src/Numerics/Distributions/Chi.cs @@ -276,7 +276,7 @@ namespace MathNet.Numerics.Distributions /// public static double PDF(double freedom, double x) { - if (freedom <= 0.0) throw new ArgumentOutOfRangeException("freedom", Resources.InvalidDistributionParameters); + if (freedom <= 0.0) throw new ArgumentException(Resources.InvalidDistributionParameters); 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); } @@ -290,7 +290,7 @@ namespace MathNet.Numerics.Distributions /// public static double PDFLn(double freedom, double x) { - if (freedom <= 0.0) throw new ArgumentOutOfRangeException("freedom", Resources.InvalidDistributionParameters); + if (freedom <= 0.0) throw new ArgumentException(Resources.InvalidDistributionParameters); 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); } @@ -304,7 +304,7 @@ namespace MathNet.Numerics.Distributions /// public static double CDF(double freedom, double x) { - if (freedom <= 0.0) throw new ArgumentOutOfRangeException("freedom", Resources.InvalidDistributionParameters); + if (freedom <= 0.0) throw new ArgumentException(Resources.InvalidDistributionParameters); return SpecialFunctions.GammaLowerIncomplete(freedom/2.0, x*x/2.0)/SpecialFunctions.Gamma(freedom/2.0); } @@ -317,7 +317,7 @@ namespace MathNet.Numerics.Distributions /// a sample from the distribution. public static double Sample(System.Random rnd, int freedom) { - if (freedom <= 0) throw new ArgumentOutOfRangeException("freedom", Resources.InvalidDistributionParameters); + if (freedom <= 0) throw new ArgumentException(Resources.InvalidDistributionParameters); return SampleUnchecked(rnd, freedom); } @@ -330,7 +330,7 @@ namespace MathNet.Numerics.Distributions /// a sequence of samples from the distribution. public static IEnumerable Samples(System.Random rnd, int freedom) { - if (freedom <= 0) throw new ArgumentOutOfRangeException("freedom", Resources.InvalidDistributionParameters); + if (freedom <= 0) throw new ArgumentException(Resources.InvalidDistributionParameters); while (true) { diff --git a/src/Numerics/Distributions/Exponential.cs b/src/Numerics/Distributions/Exponential.cs index 56c81872..e6fc1194 100644 --- a/src/Numerics/Distributions/Exponential.cs +++ b/src/Numerics/Distributions/Exponential.cs @@ -273,7 +273,7 @@ namespace MathNet.Numerics.Distributions /// public static double PDF(double rate, double x) { - if (rate < 0.0) throw new ArgumentOutOfRangeException("rate", Resources.InvalidDistributionParameters); + if (rate < 0.0) throw new ArgumentException(Resources.InvalidDistributionParameters); return x < 0.0 ? 0.0 : rate*Math.Exp(-rate*x); } @@ -287,7 +287,7 @@ namespace MathNet.Numerics.Distributions /// public static double PDFLn(double rate, double x) { - if (rate < 0.0) throw new ArgumentOutOfRangeException("rate", Resources.InvalidDistributionParameters); + if (rate < 0.0) throw new ArgumentException(Resources.InvalidDistributionParameters); return Math.Log(rate) - (rate*x); } @@ -301,7 +301,7 @@ namespace MathNet.Numerics.Distributions /// public static double CDF(double rate, double x) { - if (rate < 0.0) throw new ArgumentOutOfRangeException("rate", Resources.InvalidDistributionParameters); + if (rate < 0.0) throw new ArgumentException(Resources.InvalidDistributionParameters); return x < 0.0 ? 0.0 : 1.0 - Math.Exp(-rate*x); } @@ -316,7 +316,7 @@ namespace MathNet.Numerics.Distributions /// public static double InvCDF(double rate, double p) { - if (rate < 0.0) throw new ArgumentOutOfRangeException("rate", Resources.InvalidDistributionParameters); + if (rate < 0.0) throw new ArgumentException(Resources.InvalidDistributionParameters); return p >= 1.0 ? double.PositiveInfinity : -Math.Log(1 - p)/rate; } @@ -329,7 +329,7 @@ namespace MathNet.Numerics.Distributions /// A random number from this distribution. public static double Sample(System.Random rnd, double rate) { - if (rate < 0.0) throw new ArgumentOutOfRangeException("rate", Resources.InvalidDistributionParameters); + if (rate < 0.0) throw new ArgumentException(Resources.InvalidDistributionParameters); return SampleUnchecked(rnd, rate); } @@ -342,7 +342,7 @@ namespace MathNet.Numerics.Distributions /// a sequence of samples from the distribution. public static IEnumerable Samples(System.Random rnd, double rate) { - if (rate < 0.0) throw new ArgumentOutOfRangeException("rate", Resources.InvalidDistributionParameters); + if (rate < 0.0) throw new ArgumentException(Resources.InvalidDistributionParameters); while (true) { diff --git a/src/Numerics/Distributions/Rayleigh.cs b/src/Numerics/Distributions/Rayleigh.cs index 400dbc9d..c1e2648a 100644 --- a/src/Numerics/Distributions/Rayleigh.cs +++ b/src/Numerics/Distributions/Rayleigh.cs @@ -261,7 +261,7 @@ namespace MathNet.Numerics.Distributions /// public static double PDF(double scale, double x) { - if (scale <= 0.0) throw new ArgumentOutOfRangeException("scale", Resources.InvalidDistributionParameters); + if (scale <= 0.0) throw new ArgumentException(Resources.InvalidDistributionParameters); return (x/(scale*scale))*Math.Exp(-x*x/(2.0*scale*scale)); } @@ -275,7 +275,7 @@ namespace MathNet.Numerics.Distributions /// public static double PDFLn(double scale, double x) { - if (scale <= 0.0) throw new ArgumentOutOfRangeException("scale", Resources.InvalidDistributionParameters); + if (scale <= 0.0) throw new ArgumentException(Resources.InvalidDistributionParameters); return Math.Log(x/(scale*scale)) - (x*x/(2.0*scale*scale)); } @@ -289,7 +289,7 @@ namespace MathNet.Numerics.Distributions /// public static double CDF(double scale, double x) { - if (scale <= 0.0) throw new ArgumentOutOfRangeException("scale", Resources.InvalidDistributionParameters); + if (scale <= 0.0) throw new ArgumentException(Resources.InvalidDistributionParameters); return 1.0 - Math.Exp(-x*x/(2.0*scale*scale)); } @@ -304,7 +304,7 @@ namespace MathNet.Numerics.Distributions /// public static double InvCDF(double scale, double p) { - if (scale <= 0.0) throw new ArgumentOutOfRangeException("scale", Resources.InvalidDistributionParameters); + if (scale <= 0.0) throw new ArgumentException(Resources.InvalidDistributionParameters); return scale*Math.Sqrt(-2*Math.Log(1 - p)); } @@ -317,7 +317,7 @@ namespace MathNet.Numerics.Distributions /// a sample from the distribution. public static double Sample(System.Random rnd, double scale) { - if (scale <= 0.0) throw new ArgumentOutOfRangeException("scale", Resources.InvalidDistributionParameters); + if (scale <= 0.0) throw new ArgumentException(Resources.InvalidDistributionParameters); return scale*Math.Sqrt(-2.0*Math.Log(rnd.NextDouble())); } @@ -330,7 +330,7 @@ namespace MathNet.Numerics.Distributions /// a sequence of samples from the distribution. public static IEnumerable Samples(System.Random rnd, double scale) { - if (scale <= 0.0) throw new ArgumentOutOfRangeException("scale", Resources.InvalidDistributionParameters); + if (scale <= 0.0) throw new ArgumentException(Resources.InvalidDistributionParameters); while (true) {