diff --git a/LICENSE.md b/LICENSE.md index 8ee4a876..2b976972 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,7 +1,7 @@ Math.NET Numerics License (MIT/X11) =================================== -Copyright (c) 2002-2013 Math.NET +Copyright (c) 2002-2014 Math.NET Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation diff --git a/MathNet.Numerics.sln.DotSettings b/MathNet.Numerics.sln.DotSettings index ef16aa28..213f7deb 100644 --- a/MathNet.Numerics.sln.DotSettings +++ b/MathNet.Numerics.sln.DotSettings @@ -1,4 +1,5 @@  + True <?xml version="1.0" encoding="utf-16"?><Profile name="Full Cleanup (Math.NET)"><CSArrangeThisQualifier>True</CSArrangeThisQualifier><CSRemoveCodeRedundancies>True</CSRemoveCodeRedundancies><CSUseAutoProperty>True</CSUseAutoProperty><CSMakeFieldReadonly>True</CSMakeFieldReadonly><CSUpdateFileHeader>True</CSUpdateFileHeader><CSOptimizeUsings><OptimizeUsings>True</OptimizeUsings><EmbraceInRegion>False</EmbraceInRegion><RegionName></RegionName></CSOptimizeUsings><CSShortenReferences>True</CSShortenReferences><CSReformatCode>True</CSReformatCode><XMLReformatCode>True</XMLReformatCode><CssAlphabetizeProperties>True</CssAlphabetizeProperties><CssReformatCode>True</CssReformatCode><JsReformatCode>True</JsReformatCode><JsInsertSemicolon>True</JsInsertSemicolon><VBFormatDocComments>True</VBFormatDocComments><VBReformatCode>True</VBReformatCode><VBShortenReferences>True</VBShortenReferences><VBOptimizeImports>True</VBOptimizeImports><HtmlReformatCode>True</HtmlReformatCode><AspOptimizeRegisterDirectives>True</AspOptimizeRegisterDirectives><CSReorderTypeMembers>True</CSReorderTypeMembers><CSUseVar><BehavourStyle>CAN_CHANGE_BOTH</BehavourStyle><LocalVariableStyle>IMPLICIT_WHEN_INITIALIZER_HAS_TYPE</LocalVariableStyle><ForeachVariableStyle>ALWAYS_EXPLICIT</ForeachVariableStyle></CSUseVar></Profile> Full Cleanup (Math.NET) False @@ -48,11 +49,14 @@ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. </copyright> + AVX CDF DFT FFT + IA ILU ILUTP + IX LU MAE MC @@ -66,6 +70,7 @@ OTHER DEALINGS IN THE SOFTWARE. SAS SPSS SSD + SSE SVD TFQMR WH diff --git a/src/Numerics/Distributions/Triangular.cs b/src/Numerics/Distributions/Triangular.cs index 24e51994..d853f874 100644 --- a/src/Numerics/Distributions/Triangular.cs +++ b/src/Numerics/Distributions/Triangular.cs @@ -138,7 +138,7 @@ namespace MathNet.Numerics.Distributions /// public double Mean { - get { return (_lower + _upper + _mode) / 3.0; } + get { return (_lower + _upper + _mode)/3.0; } } /// @@ -151,7 +151,7 @@ namespace MathNet.Numerics.Distributions var a = _lower; var b = _upper; var c = _mode; - return (a * a + b * b + c * c - a * b - a * c - b * c) / 18.0; + return (a*a + b*b + c*c - a*b - a*c - b*c)/18.0; } } @@ -169,7 +169,7 @@ namespace MathNet.Numerics.Distributions /// public double Entropy { - get { return 0.5 + Math.Log((_upper - _lower) / 2); } + get { return 0.5 + Math.Log((_upper - _lower)/2); } } /// @@ -182,9 +182,9 @@ namespace MathNet.Numerics.Distributions var a = _lower; var b = _upper; var c = _mode; - var q = Math.Sqrt(2) * (a + b - 2 * c) * (2 * a - b - c) * (a - 2 * b + c); - var d = 5 * Math.Pow(a * a + b * b + c * c - a * b - a * c - b * c, 3.0 / 2); - return q / d; + var q = Math.Sqrt(2)*(a + b - 2*c)*(2*a - b - c)*(a - 2*b + c); + var d = 5*Math.Pow(a*a + b*b + c*c - a*b - a*c - b*c, 3.0/2); + return q/d; } } @@ -208,9 +208,9 @@ namespace MathNet.Numerics.Distributions var a = _lower; var b = _upper; var c = _mode; - return c >= (a + b) / 2 - ? a + Math.Sqrt((b - a) * (c - a) / 2) - : b - Math.Sqrt((b - a) * (b - c) / 2); + return c >= (a + b)/2 + ? a + Math.Sqrt((b - a)*(c - a)/2) + : b - Math.Sqrt((b - a)*(b - c)/2); } } @@ -311,8 +311,8 @@ namespace MathNet.Numerics.Distributions var b = upper; var c = mode; - if (a <= x && x <= c) return 2 * (x - a) / ((b - a) * (c - a)); - if (c < x & x <= b) return 2 * (b - x) / ((b - a) * (b - c)); + if (a <= x && x <= c) return 2*(x - a)/((b - a)*(c - a)); + if (c < x & x <= b) return 2*(b - x)/((b - a)*(b - c)); return 0; } @@ -342,15 +342,15 @@ namespace MathNet.Numerics.Distributions public static double CDF(double lower, double upper, double mode, double x) { if (upper < mode) throw new ArgumentOutOfRangeException("upper", Resources.InvalidDistributionParameters); - if (mode < lower) throw new ArgumentOutOfRangeException("lower", Resources.InvalidDistributionParameters); // TODO: Is "lower" the appropriate argument here? + if (lower > mode) throw new ArgumentOutOfRangeException("lower", Resources.InvalidDistributionParameters); var a = lower; var b = upper; var c = mode; if (x < a) return 0; - if (a <= x && x <= c) return (x - a) * (x - a) / ((b - a) * (c - a)); - if (c < x & x <= b) return 1 - (b - x) * (b - x) / ((b - a) * (b - c)); + if (a <= x && x <= c) return (x - a)*(x - a)/((b - a)*(c - a)); + if (c < x & x <= b) return 1 - (b - x)*(b - x)/((b - a)*(b - c)); return 1; } @@ -367,7 +367,7 @@ namespace MathNet.Numerics.Distributions public static double InvCDF(double lower, double upper, double mode, double p) { if (upper < mode) throw new ArgumentOutOfRangeException("upper", Resources.InvalidDistributionParameters); - if (mode < lower) throw new ArgumentOutOfRangeException("lower", Resources.InvalidDistributionParameters); // TODO: Is "lower" the appropriate argument here? + if (lower > mode) throw new ArgumentOutOfRangeException("lower", Resources.InvalidDistributionParameters); var a = lower; var b = upper; @@ -375,8 +375,8 @@ namespace MathNet.Numerics.Distributions if (p <= 0) return lower; // Taken from http://www.ntrand.com/triangular-distribution/ - if (p < (c - a) / (b - a)) return a + Math.Sqrt(p * (c - a) * (b - a)); - if (p < 1) return b - Math.Sqrt((1 - p) * (b - c) * (b - a)); + if (p < (c - a)/(b - a)) return a + Math.Sqrt(p*(c - a)*(b - a)); + if (p < 1) return b - Math.Sqrt((1 - p)*(b - c)*(b - a)); return upper; } @@ -395,9 +395,9 @@ namespace MathNet.Numerics.Distributions var c = mode; var u = rnd.NextDouble(); - return u < (c - a) / (b - a) - ? a + Math.Sqrt(u * (b - a) * (c - a)) - : b - Math.Sqrt((1 - u) * (b - a) * (b - c)); ; + return u < (c - a)/(b - a) + ? a + Math.Sqrt(u*(b - a)*(c - a)) + : b - Math.Sqrt((1 - u)*(b - a)*(b - c)); } /// @@ -417,4 +417,4 @@ namespace MathNet.Numerics.Distributions } } -} \ No newline at end of file +} diff --git a/src/Numerics/Financial/AbsoluteRiskMeasures.cs b/src/Numerics/Financial/AbsoluteRiskMeasures.cs index 3e156068..85c00cbd 100644 --- a/src/Numerics/Financial/AbsoluteRiskMeasures.cs +++ b/src/Numerics/Financial/AbsoluteRiskMeasures.cs @@ -37,7 +37,7 @@ namespace MathNet.Numerics.Financial { public static class AbsoluteRiskMeasures { - //Note: The following statistics would be condidered an absolute risk statistic in the finance realm as well. + //Note: The following statistics would be considered an absolute risk statistic in the finance realm as well. // Standard Deviation // Annualized Standard Deviation = Math.Sqrt(Monthly Standard Deviation x ( 12 )) // Skewness diff --git a/src/Numerics/LinearRegression/WeightedRegression.cs b/src/Numerics/LinearRegression/WeightedRegression.cs index 0271e874..715d8306 100644 --- a/src/Numerics/LinearRegression/WeightedRegression.cs +++ b/src/Numerics/LinearRegression/WeightedRegression.cs @@ -64,7 +64,7 @@ namespace MathNet.Numerics.LinearRegression /// Predictor matrix X /// Response vector Y /// Weight matrix W, usually diagonal with an entry for each predictor (row). - /// True if an intercept should be added as first artificial perdictor value. Default = false. + /// True if an intercept should be added as first artificial predictor value. Default = false. public static T[] Weighted(T[][] x, T[] y, T[] w, bool intercept = false) where T : struct, IEquatable, IFormattable { var predictor = Matrix.Build.DenseOfRowArrays(x); @@ -82,7 +82,7 @@ namespace MathNet.Numerics.LinearRegression /// /// List of sample vectors (predictor) together with their response. /// List of weights, one for each sample. - /// True if an intercept should be added as first artificial perdictor value. Default = false. + /// True if an intercept should be added as first artificial predictor value. Default = false. public static T[] Weighted(IEnumerable> samples, T[] weights, bool intercept = false) where T : struct, IEquatable, IFormattable { var xy = samples.UnpackSinglePass(); diff --git a/src/Numerics/Providers/LinearAlgebra/Mkl/MklLinearAlgebraProvider.cs b/src/Numerics/Providers/LinearAlgebra/Mkl/MklLinearAlgebraProvider.cs index 98064d4e..981162b0 100644 --- a/src/Numerics/Providers/LinearAlgebra/Mkl/MklLinearAlgebraProvider.cs +++ b/src/Numerics/Providers/LinearAlgebra/Mkl/MklLinearAlgebraProvider.cs @@ -72,10 +72,10 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Mkl /// public partial class MklLinearAlgebraProvider : ManagedLinearAlgebraProvider { - int _nativeRevision = 0; - bool _nativeIX86 = false; - bool _nativeX64 = false; - bool _nativeIA64 = false; + int _nativeRevision; + bool _nativeIX86; + bool _nativeX64; + bool _nativeIA64; readonly MklConsistency _consistency; readonly MklPrecision _precision; @@ -113,7 +113,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Mkl { // TODO: Choose x86 or x64 based on Environment.Is64BitProcess - int a = 0, b = 0, linearAlgebra = 0; + int a, b, linearAlgebra; try { a = SafeNativeMethods.query_capability(0); diff --git a/src/Numerics/SpecialFunctions/Gamma.cs b/src/Numerics/SpecialFunctions/Gamma.cs index ff2ace6f..e59da9d0 100644 --- a/src/Numerics/SpecialFunctions/Gamma.cs +++ b/src/Numerics/SpecialFunctions/Gamma.cs @@ -265,9 +265,13 @@ namespace MathNet.Numerics const double big = 4503599627370496.0; const double bigInv = 2.22044604925031308085e-16; - if (a < 0d || x < 0d) + if (a < 0d) { - throw new ArgumentOutOfRangeException("a,x", Properties.Resources.ArgumentNotNegative); + throw new ArgumentOutOfRangeException("a", Properties.Resources.ArgumentNotNegative); + } + if (x < 0d) + { + throw new ArgumentOutOfRangeException("x", Properties.Resources.ArgumentNotNegative); } if (a.AlmostEqual(0.0)) @@ -379,9 +383,13 @@ namespace MathNet.Numerics return double.NaN; } - if (a < 0 || a.AlmostEqual(0.0) || y0 < 0 || y0 > 1) + if (a < 0 || a.AlmostEqual(0.0)) + { + throw new ArgumentOutOfRangeException("a"); + } + if (y0 < 0 || y0 > 1) { - throw new ArgumentOutOfRangeException("a,y0", Properties.Resources.ArgumentNotNegative); + throw new ArgumentOutOfRangeException("y0"); } if (y0.AlmostEqual(0.0)) diff --git a/src/Numerics/Statistics/DescriptiveStatistics.cs b/src/Numerics/Statistics/DescriptiveStatistics.cs index 2b6aa1c9..88e49fb6 100644 --- a/src/Numerics/Statistics/DescriptiveStatistics.cs +++ b/src/Numerics/Statistics/DescriptiveStatistics.cs @@ -28,11 +28,11 @@ // OTHER DEALINGS IN THE SOFTWARE. // +using System; +using System.Collections.Generic; + namespace MathNet.Numerics.Statistics { - using System; - using System.Collections.Generic; - /// /// Computes the basic statistics of data set. The class meets the /// NIST standard of accuracy for mean, variance, and standard deviation @@ -153,7 +153,7 @@ namespace MathNet.Numerics.Statistics /// Computes descriptive statistics from a stream of data values. /// /// A sequence of datapoints. - private void Compute(IEnumerable data) + void Compute(IEnumerable data) { double mean = 0; double variance = 0; @@ -165,20 +165,26 @@ namespace MathNet.Numerics.Statistics foreach (var xi in data) { double delta = xi - mean; - double scaleDelta = delta / ++n; - double scaleDeltaSqr = scaleDelta * scaleDelta; - double tmpDelta = delta * (n - 1); + double scaleDelta = delta/++n; + double scaleDeltaSqr = scaleDelta*scaleDelta; + double tmpDelta = delta*(n - 1); mean += scaleDelta; - kurtosis += tmpDelta * scaleDelta * scaleDeltaSqr * (n * n - 3 * n + 3) - + 6 * scaleDeltaSqr * variance - 4 * scaleDelta * skewness; + kurtosis += tmpDelta*scaleDelta*scaleDeltaSqr*(n*n - 3*n + 3) + + 6*scaleDeltaSqr*variance - 4*scaleDelta*skewness; - skewness += tmpDelta * scaleDeltaSqr * (n - 2) - 3 * scaleDelta * variance; - variance += tmpDelta * scaleDelta; + skewness += tmpDelta*scaleDeltaSqr*(n - 2) - 3*scaleDelta*variance; + variance += tmpDelta*scaleDelta; - if (minimum > xi) { minimum = xi; } - if (maximum < xi) { maximum = xi; } + if (minimum > xi) + { + minimum = xi; + } + if (maximum < xi) + { + maximum = xi; + } } SetStatistics(mean, variance, skewness, kurtosis, minimum, maximum, n); } @@ -189,7 +195,7 @@ namespace MathNet.Numerics.Statistics /// Computes descriptive statistics from a stream of nullable data values. /// /// A sequence of datapoints. - private void Compute(IEnumerable data) + void Compute(IEnumerable data) { double mean = 0; double variance = 0; @@ -203,19 +209,25 @@ namespace MathNet.Numerics.Statistics if (xi.HasValue) { double delta = xi.Value - mean; - double scaleDelta = delta / ++n; - double scaleDeltaSqr = scaleDelta * scaleDelta; - double tmpDelta = delta * (n - 1); + double scaleDelta = delta/++n; + double scaleDeltaSqr = scaleDelta*scaleDelta; + double tmpDelta = delta*(n - 1); mean += scaleDelta; - kurtosis += tmpDelta * scaleDelta * scaleDeltaSqr * (n * n - 3 * n + 3) - + 6 * scaleDeltaSqr * variance - 4 * scaleDelta * skewness; + kurtosis += tmpDelta*scaleDelta*scaleDeltaSqr*(n*n - 3*n + 3) + + 6*scaleDeltaSqr*variance - 4*scaleDelta*skewness; - skewness += tmpDelta * scaleDeltaSqr * (n - 2) - 3 * scaleDelta * variance; - variance += tmpDelta * scaleDelta; - if (minimum > xi) { minimum = xi.Value; } - if (maximum < xi) { maximum = xi.Value; } + skewness += tmpDelta*scaleDeltaSqr*(n - 2) - 3*scaleDelta*variance; + variance += tmpDelta*scaleDelta; + if (minimum > xi) + { + minimum = xi.Value; + } + if (maximum < xi) + { + maximum = xi.Value; + } } } @@ -224,10 +236,10 @@ namespace MathNet.Numerics.Statistics } /// - /// Computes descriptive statistics from a stream of data values using high accuracy. + /// Computes descriptive statistics from a stream of data values. /// /// A sequence of datapoints. - private void ComputeDecimal(IEnumerable data) + void ComputeDecimal(IEnumerable data) { decimal mean = 0; decimal variance = 0; @@ -236,22 +248,29 @@ namespace MathNet.Numerics.Statistics decimal minimum = Decimal.MaxValue; decimal maximum = Decimal.MinValue; int n = 0; - foreach (decimal xi in data) + foreach (double x in data) { + decimal xi = (decimal)x; decimal delta = xi - mean; - decimal scaleDelta = delta / ++n; - decimal scaleDeltaSQR = scaleDelta * scaleDelta; - decimal tmpDelta = delta * (n - 1); + decimal scaleDelta = delta/++n; + decimal scaleDeltaSQR = scaleDelta*scaleDelta; + decimal tmpDelta = delta*(n - 1); mean += scaleDelta; - kurtosis += tmpDelta * scaleDelta * scaleDeltaSQR * (n * n - 3 * n + 3) - + 6 * scaleDeltaSQR * variance - 4 * scaleDelta * skewness; + kurtosis += tmpDelta*scaleDelta*scaleDeltaSQR*(n*n - 3*n + 3) + + 6*scaleDeltaSQR*variance - 4*scaleDelta*skewness; - skewness += tmpDelta * scaleDeltaSQR * (n - 2) - 3 * scaleDelta * variance; - variance += tmpDelta * scaleDelta; - if (minimum > xi) { minimum = xi; } - if (maximum < xi) { maximum = xi; } + skewness += tmpDelta*scaleDeltaSQR*(n - 2) - 3*scaleDelta*variance; + variance += tmpDelta*scaleDelta; + if (minimum > xi) + { + minimum = xi; + } + if (maximum < xi) + { + maximum = xi; + } } SetStatistics((double)mean, (double)variance, (double)skewness, (double)kurtosis, (double)minimum, (double)maximum, n); @@ -259,10 +278,10 @@ namespace MathNet.Numerics.Statistics } /// - /// Computes descriptive statistics from a stream of nullable data values using high accuracy. + /// Computes descriptive statistics from a stream of nullable data values. /// /// A sequence of datapoints. - private void ComputeDecimal(IEnumerable data) + void ComputeDecimal(IEnumerable data) { decimal mean = 0; decimal variance = 0; @@ -271,24 +290,31 @@ namespace MathNet.Numerics.Statistics decimal minimum = Decimal.MaxValue; decimal maximum = Decimal.MinValue; int n = 0; - foreach (decimal? xi in data) + foreach (double? x in data) { - if (xi.HasValue) + if (x.HasValue) { - decimal delta = xi.Value - mean; - decimal scaleDelta = delta / ++n; - decimal scaleDeltaSQR = scaleDelta * scaleDelta; - decimal tmpDelta = delta * (n - 1); + decimal xi = (decimal)x.Value; + decimal delta = xi - mean; + decimal scaleDelta = delta/++n; + decimal scaleDeltaSQR = scaleDelta*scaleDelta; + decimal tmpDelta = delta*(n - 1); mean += scaleDelta; - kurtosis += tmpDelta * scaleDelta * scaleDeltaSQR * (n * n - 3 * n + 3) - + 6 * scaleDeltaSQR * variance - 4 * scaleDelta * skewness; + kurtosis += tmpDelta*scaleDelta*scaleDeltaSQR*(n*n - 3*n + 3) + + 6*scaleDeltaSQR*variance - 4*scaleDelta*skewness; - skewness += tmpDelta * scaleDeltaSQR * (n - 2) - 3 * scaleDelta * variance; - variance += tmpDelta * scaleDelta; - if (minimum > xi) { minimum = xi.Value; } - if (maximum < xi) { maximum = xi.Value; } + skewness += tmpDelta*scaleDeltaSQR*(n - 2) - 3*scaleDelta*variance; + variance += tmpDelta*scaleDelta; + if (minimum > xi) + { + minimum = xi; + } + if (maximum < xi) + { + maximum = xi; + } } } SetStatistics((double)mean, (double)variance, (double)skewness, (double)kurtosis, (double)minimum, (double)maximum, n); @@ -305,7 +331,7 @@ namespace MathNet.Numerics.Statistics /// For setting Minimum. /// For setting Maximum. /// For setting Count. - private void SetStatistics(double mean, double variance, double skewness, double kurtosis, double minimum, double maximum, int n) + void SetStatistics(double mean, double variance, double skewness, double kurtosis, double minimum, double maximum, int n) { Mean = mean; Count = n; @@ -315,24 +341,23 @@ namespace MathNet.Numerics.Statistics Maximum = maximum; if (n > 1) { - Variance = variance / (n - 1); + Variance = variance/(n - 1); StandardDeviation = Math.Sqrt(Variance); } if (Variance != 0) { if (n > 2) { - Skewness = (double)n / ((n - 1) * (n - 2)) * (skewness / (Variance * StandardDeviation)); + Skewness = (double)n/((n - 1)*(n - 2))*(skewness/(Variance*StandardDeviation)); } if (n > 3) { - Kurtosis = ((double)n * n - 1) / ((n - 2) * (n - 3)) - * (n * kurtosis / (variance * variance) - 3 + 6.0 / (n + 1)); + Kurtosis = ((double)n*n - 1)/((n - 2)*(n - 3)) + *(n*kurtosis/(variance*variance) - 3 + 6.0/(n + 1)); } } } } } - }