From 3c4d20f30c43eb58b13c1da9ed58774b202101d9 Mon Sep 17 00:00:00 2001 From: Christoph Ruegg Date: Wed, 20 Mar 2013 18:21:23 +0100 Subject: [PATCH] Statistics: cosmetics --- .../Statistics/DescriptiveStatistics.cs | 2 +- src/Numerics/Statistics/Percentile.cs | 7 +++- src/Numerics/Statistics/Statistics.cs | 2 +- .../StatisticsTests/CorrelationTests.cs | 8 +++- .../DescriptiveStatisticsTests.cs | 8 +++- .../StatisticsTests/HistogramTests.cs | 28 +++++++------ .../StatisticsTests/PercentileTests.cs | 39 ++++++++++--------- src/UnitTests/StatisticsTests/StatTestData.cs | 8 +++- .../StatisticsTests/StatisticsTests.cs | 18 +++++---- 9 files changed, 74 insertions(+), 46 deletions(-) diff --git a/src/Numerics/Statistics/DescriptiveStatistics.cs b/src/Numerics/Statistics/DescriptiveStatistics.cs index 6bf2eb03..1a8e58eb 100644 --- a/src/Numerics/Statistics/DescriptiveStatistics.cs +++ b/src/Numerics/Statistics/DescriptiveStatistics.cs @@ -4,7 +4,7 @@ // http://github.com/mathnet/mathnet-numerics // http://mathnetnumerics.codeplex.com // -// Copyright (c) 2009-2010 Math.NET +// Copyright (c) 2009-2013 Math.NET // // Permission is hereby granted, free of charge, to any person // obtaining a copy of this software and associated documentation diff --git a/src/Numerics/Statistics/Percentile.cs b/src/Numerics/Statistics/Percentile.cs index 019e85e4..674c03d4 100644 --- a/src/Numerics/Statistics/Percentile.cs +++ b/src/Numerics/Statistics/Percentile.cs @@ -3,7 +3,9 @@ // http://numerics.mathdotnet.com // http://github.com/mathnet/mathnet-numerics // http://mathnetnumerics.codeplex.com -// Copyright (c) 2009-2010 Math.NET +// +// Copyright (c) 2009-2013 Math.NET +// // Permission is hereby granted, free of charge, to any person // obtaining a copy of this software and associated documentation // files (the "Software"), to deal in the Software without @@ -12,8 +14,10 @@ // copies of the Software, and to permit persons to whom the // Software is furnished to do so, subject to the following // conditions: +// // The above copyright notice and this permission notice shall be // included in all copies or substantial portions of the Software. +// // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND @@ -23,6 +27,7 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR // OTHER DEALINGS IN THE SOFTWARE. // + namespace MathNet.Numerics.Statistics { using System; diff --git a/src/Numerics/Statistics/Statistics.cs b/src/Numerics/Statistics/Statistics.cs index bba51a97..dd2d3baf 100644 --- a/src/Numerics/Statistics/Statistics.cs +++ b/src/Numerics/Statistics/Statistics.cs @@ -4,7 +4,7 @@ // http://github.com/mathnet/mathnet-numerics // http://mathnetnumerics.codeplex.com // -// Copyright (c) 2009-2010 Math.NET +// Copyright (c) 2009-2013 Math.NET // // Permission is hereby granted, free of charge, to any person // obtaining a copy of this software and associated documentation diff --git a/src/UnitTests/StatisticsTests/CorrelationTests.cs b/src/UnitTests/StatisticsTests/CorrelationTests.cs index 82214de5..b03ad1f3 100644 --- a/src/UnitTests/StatisticsTests/CorrelationTests.cs +++ b/src/UnitTests/StatisticsTests/CorrelationTests.cs @@ -3,7 +3,9 @@ // http://numerics.mathdotnet.com // http://github.com/mathnet/mathnet-numerics // http://mathnetnumerics.codeplex.com -// Copyright (c) 2009-2010 Math.NET +// +// Copyright (c) 2009-2013 Math.NET +// // Permission is hereby granted, free of charge, to any person // obtaining a copy of this software and associated documentation // files (the "Software"), to deal in the Software without @@ -12,8 +14,10 @@ // copies of the Software, and to permit persons to whom the // Software is furnished to do so, subject to the following // conditions: +// // The above copyright notice and this permission notice shall be // included in all copies or substantial portions of the Software. +// // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND @@ -44,7 +48,7 @@ namespace MathNet.Numerics.UnitTests.StatisticsTests /// /// Statistics data. /// - private readonly IDictionary _data = new Dictionary(); + readonly IDictionary _data = new Dictionary(); /// /// Initializes a new instance of the CorrelationTests class. diff --git a/src/UnitTests/StatisticsTests/DescriptiveStatisticsTests.cs b/src/UnitTests/StatisticsTests/DescriptiveStatisticsTests.cs index a87c2161..ae22faf3 100644 --- a/src/UnitTests/StatisticsTests/DescriptiveStatisticsTests.cs +++ b/src/UnitTests/StatisticsTests/DescriptiveStatisticsTests.cs @@ -3,7 +3,9 @@ // http://numerics.mathdotnet.com // http://github.com/mathnet/mathnet-numerics // http://mathnetnumerics.codeplex.com -// Copyright (c) 2009-2010 Math.NET +// +// Copyright (c) 2009-2013 Math.NET +// // Permission is hereby granted, free of charge, to any person // obtaining a copy of this software and associated documentation // files (the "Software"), to deal in the Software without @@ -12,8 +14,10 @@ // copies of the Software, and to permit persons to whom the // Software is furnished to do so, subject to the following // conditions: +// // The above copyright notice and this permission notice shall be // included in all copies or substantial portions of the Software. +// // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND @@ -43,7 +47,7 @@ namespace MathNet.Numerics.UnitTests.StatisticsTests /// /// Statistics data. /// - private readonly IDictionary _data = new Dictionary(); + readonly IDictionary _data = new Dictionary(); /// /// Initializes a new instance of the DescriptiveStatisticsTests class. diff --git a/src/UnitTests/StatisticsTests/HistogramTests.cs b/src/UnitTests/StatisticsTests/HistogramTests.cs index f648ddc7..629f828e 100644 --- a/src/UnitTests/StatisticsTests/HistogramTests.cs +++ b/src/UnitTests/StatisticsTests/HistogramTests.cs @@ -3,7 +3,9 @@ // http://numerics.mathdotnet.com // http://github.com/mathnet/mathnet-numerics // http://mathnetnumerics.codeplex.com -// Copyright (c) 2009-2010 Math.NET +// +// Copyright (c) 2009-2013 Math.NET +// // Permission is hereby granted, free of charge, to any person // obtaining a copy of this software and associated documentation // files (the "Software"), to deal in the Software without @@ -12,8 +14,10 @@ // copies of the Software, and to permit persons to whom the // Software is furnished to do so, subject to the following // conditions: +// // The above copyright notice and this permission notice shall be // included in all copies or substantial portions of the Software. +// // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND @@ -40,7 +44,7 @@ namespace MathNet.Numerics.UnitTests.StatisticsTests /// /// Datatset array. /// - private readonly double[] _smallDataset = { 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5 }; + readonly double[] _smallDataset = {0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5}; /// /// Can create empty bucket. @@ -48,7 +52,7 @@ namespace MathNet.Numerics.UnitTests.StatisticsTests [Test] public void CanCreateEmptyBucket() { - new Bucket(0.0, 1.0); + var b = new Bucket(0.0, 1.0); } /// @@ -57,7 +61,7 @@ namespace MathNet.Numerics.UnitTests.StatisticsTests [Test] public void CanCreateFilledBucket() { - new Bucket(0.0, 1.0, 10.0); + var b = new Bucket(0.0, 1.0, 10.0); } /// @@ -140,7 +144,7 @@ namespace MathNet.Numerics.UnitTests.StatisticsTests [Test] public void CanCreateEmptyHistogram() { - new Histogram(); + var h = new Histogram(); } /// @@ -263,7 +267,7 @@ namespace MathNet.Numerics.UnitTests.StatisticsTests [Test] public void CanCreateEqualSpacedHistogram() { - new Histogram(new[] { 1.0, 5.0, 10.0 }, 2); + var h = new Histogram(new[] {1.0, 5.0, 10.0}, 2); } /// @@ -281,7 +285,7 @@ namespace MathNet.Numerics.UnitTests.StatisticsTests [Test] public void CanCreateEqualSpacedHistogramWithGivenLowerAndUpperBound() { - new Histogram(new[] { 1.0, 5.0, 10.0 }, 2, 0.0, 20.0); + var h = new Histogram(new[] {1.0, 5.0, 10.0}, 2, 0.0, 20.0); } /// @@ -290,7 +294,7 @@ namespace MathNet.Numerics.UnitTests.StatisticsTests [Test] public void CanAddDataSingle() { - var h = new Histogram(new[] { 1.0, 5.0, 10.0 }, 2); + var h = new Histogram(new[] {1.0, 5.0, 10.0}, 2); h.AddData(7.0); Assert.AreEqual(2, h[1].Count); } @@ -301,8 +305,8 @@ namespace MathNet.Numerics.UnitTests.StatisticsTests [Test] public void CanAddDataList() { - var h = new Histogram(new[] { 1.0, 5.0, 10.0 }, 2); - h.AddData(new[] { 7.0, 8.0 }); + var h = new Histogram(new[] {1.0, 5.0, 10.0}, 2); + h.AddData(new[] {7.0, 8.0}); Assert.AreEqual(3, h[1].Count); } @@ -312,7 +316,7 @@ namespace MathNet.Numerics.UnitTests.StatisticsTests [Test] public void AddDataIncreasesUpperBound() { - var h = new Histogram(new[] { 1.0, 5.0, 10.0 }, 2); + var h = new Histogram(new[] {1.0, 5.0, 10.0}, 2); h.AddData(20.0); Assert.AreEqual(2, h[1].Count); } @@ -323,7 +327,7 @@ namespace MathNet.Numerics.UnitTests.StatisticsTests [Test] public void AddDataDecreasesLowerBound() { - var h = new Histogram(new[] { 1.0, 5.0, 10.0 }, 2); + var h = new Histogram(new[] {1.0, 5.0, 10.0}, 2); h.AddData(0.0); Assert.AreEqual(3, h[0].Count); } diff --git a/src/UnitTests/StatisticsTests/PercentileTests.cs b/src/UnitTests/StatisticsTests/PercentileTests.cs index 940ffcf0..cc448e28 100644 --- a/src/UnitTests/StatisticsTests/PercentileTests.cs +++ b/src/UnitTests/StatisticsTests/PercentileTests.cs @@ -3,7 +3,9 @@ // http://numerics.mathdotnet.com // http://github.com/mathnet/mathnet-numerics // http://mathnetnumerics.codeplex.com -// Copyright (c) 2009-2010 Math.NET +// +// Copyright (c) 2009-2013 Math.NET +// // Permission is hereby granted, free of charge, to any person // obtaining a copy of this software and associated documentation // files (the "Software"), to deal in the Software without @@ -12,8 +14,10 @@ // copies of the Software, and to permit persons to whom the // Software is furnished to do so, subject to the following // conditions: +// // The above copyright notice and this permission notice shall be // included in all copies or substantial portions of the Software. +// // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND @@ -26,7 +30,6 @@ namespace MathNet.Numerics.UnitTests.StatisticsTests { - using System; using NUnit.Framework; using Statistics; @@ -39,7 +42,7 @@ namespace MathNet.Numerics.UnitTests.StatisticsTests /// /// Data array /// - private static readonly double[] Data = { 95.1772, 95.1567, 95.1937, 95.1959, 95.1442, 95.061, 95.1591, 95.1195, 95.1065, 95.0925, 95.199, 95.1682 }; + static readonly double[] Data = {95.1772, 95.1567, 95.1937, 95.1959, 95.1442, 95.061, 95.1591, 95.1195, 95.1065, 95.0925, 95.199, 95.1682}; /// /// Can compute percentile using NIST method. @@ -48,9 +51,9 @@ namespace MathNet.Numerics.UnitTests.StatisticsTests public void CanComputePercentileUsingNistMethod() { var percentile = new Percentile(Data) - { - Method = PercentileMethod.Nist - }; + { + Method = PercentileMethod.Nist + }; Assert.AreEqual(95.19807, percentile.Compute(.9)); } @@ -61,9 +64,9 @@ namespace MathNet.Numerics.UnitTests.StatisticsTests public void CanComputePercentileUsingExcelMethod() { var percentile = new Percentile(Data) - { - Method = PercentileMethod.Excel - }; + { + Method = PercentileMethod.Excel + }; Assert.AreEqual(95.19568, percentile.Compute(.9)); } @@ -74,9 +77,9 @@ namespace MathNet.Numerics.UnitTests.StatisticsTests public void CanComputePercentileUsingNearestMethod() { var percentile = new Percentile(Data) - { - Method = PercentileMethod.Nearest - }; + { + Method = PercentileMethod.Nearest + }; Assert.AreEqual(95.1959, percentile.Compute(.9)); } @@ -86,12 +89,12 @@ namespace MathNet.Numerics.UnitTests.StatisticsTests [Test] public void CanComputePercentileUsingInterpolationMethod() { - var data = new double[] { 1, 2, 3, 4, 5 }; + var data = new double[] {1, 2, 3, 4, 5}; var percentile = new Percentile(data) - { - Method = PercentileMethod.Interpolation - }; - var values = new[] { .25, .5, .75 }; + { + Method = PercentileMethod.Interpolation + }; + var values = new[] {.25, .5, .75}; var percentiles = percentile.Compute(values); Assert.AreEqual(1.75, percentiles[0]); Assert.AreEqual(3.0, percentiles[1]); @@ -104,7 +107,7 @@ namespace MathNet.Numerics.UnitTests.StatisticsTests [Test] public void EmptyDataSetReturnsNaN() { - var data = new double[] { }; + var data = new double[] {}; var percentile = new Percentile(data); Assert.IsTrue(double.IsNaN(percentile.Compute(0))); } diff --git a/src/UnitTests/StatisticsTests/StatTestData.cs b/src/UnitTests/StatisticsTests/StatTestData.cs index 41da4526..4a1d9434 100644 --- a/src/UnitTests/StatisticsTests/StatTestData.cs +++ b/src/UnitTests/StatisticsTests/StatTestData.cs @@ -3,7 +3,9 @@ // http://numerics.mathdotnet.com // http://github.com/mathnet/mathnet-numerics // http://mathnetnumerics.codeplex.com -// Copyright (c) 2009-2010 Math.NET +// +// Copyright (c) 2009-2013 Math.NET +// // Permission is hereby granted, free of charge, to any person // obtaining a copy of this software and associated documentation // files (the "Software"), to deal in the Software without @@ -12,8 +14,10 @@ // copies of the Software, and to permit persons to whom the // Software is furnished to do so, subject to the following // conditions: +// // The above copyright notice and this permission notice shall be // included in all copies or substantial portions of the Software. +// // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND @@ -110,7 +114,7 @@ namespace MathNet.Numerics.UnitTests.StatisticsTests /// /// Parameter name. /// Parameter value. - private static double GetValue(string str) + static double GetValue(string str) { var start = str.IndexOf(":"); var value = str.Substring(start + 1).Trim(); diff --git a/src/UnitTests/StatisticsTests/StatisticsTests.cs b/src/UnitTests/StatisticsTests/StatisticsTests.cs index d29bed68..393eb214 100644 --- a/src/UnitTests/StatisticsTests/StatisticsTests.cs +++ b/src/UnitTests/StatisticsTests/StatisticsTests.cs @@ -3,7 +3,9 @@ // http://numerics.mathdotnet.com // http://github.com/mathnet/mathnet-numerics // http://mathnetnumerics.codeplex.com -// Copyright (c) 2009-2010 Math.NET +// +// Copyright (c) 2009-2013 Math.NET +// // Permission is hereby granted, free of charge, to any person // obtaining a copy of this software and associated documentation // files (the "Software"), to deal in the Software without @@ -12,8 +14,10 @@ // copies of the Software, and to permit persons to whom the // Software is furnished to do so, subject to the following // conditions: +// // The above copyright notice and this permission notice shall be // included in all copies or substantial portions of the Software. +// // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND @@ -45,7 +49,7 @@ namespace MathNet.Numerics.UnitTests.StatisticsTests /// /// Statistics data. /// - private readonly IDictionary _data = new Dictionary(); + readonly IDictionary _data = new Dictionary(); /// /// Initializes a new instance of the StatisticsTests class. @@ -170,7 +174,7 @@ namespace MathNet.Numerics.UnitTests.StatisticsTests [Test] public void ShortMinMax() { - var samples = new[] { -1.0, 5, 0, -3, 10, -0.5, 4 }; + var samples = new[] {-1.0, 5, 0, -3, 10, -0.5, 4}; Assert.That(samples.Minimum(), Is.EqualTo(-3), "Min"); Assert.That(samples.Maximum(), Is.EqualTo(10), "Max"); } @@ -182,7 +186,7 @@ namespace MathNet.Numerics.UnitTests.StatisticsTests public void ShortOrderMedian() { // -3 -1 -0.5 0 1 4 5 6 10 - var samples = new[] { -1, 5, 0, -3, 10, -0.5, 4, 1, 6 }; + var samples = new[] {-1, 5, 0, -3, 10, -0.5, 4, 1, 6}; Assert.That(samples.Median(), Is.EqualTo(1), "Median"); Assert.That(Statistics.OrderStatistic(samples, 1), Is.EqualTo(-3), "Order-1"); Assert.That(Statistics.OrderStatistic(samples, 3), Is.EqualTo(-0.5), "Order-3"); @@ -200,9 +204,9 @@ namespace MathNet.Numerics.UnitTests.StatisticsTests { // Test around 10^9, potential stability issues var gaussian = new Distributions.Normal(1e+9, 2) - { - RandomSource = new Numerics.Random.MersenneTwister(100) - }; + { + RandomSource = new Numerics.Random.MersenneTwister(100) + }; AssertHelpers.AlmostEqual(1e+9, gaussian.Samples().Take(10000).Mean(), 11); AssertHelpers.AlmostEqual(4d, gaussian.Samples().Take(10000).Variance(), 1);