Browse Source

Statistics: cosmetics

v2
Christoph Ruegg 14 years ago
parent
commit
3c4d20f30c
  1. 2
      src/Numerics/Statistics/DescriptiveStatistics.cs
  2. 7
      src/Numerics/Statistics/Percentile.cs
  3. 2
      src/Numerics/Statistics/Statistics.cs
  4. 8
      src/UnitTests/StatisticsTests/CorrelationTests.cs
  5. 8
      src/UnitTests/StatisticsTests/DescriptiveStatisticsTests.cs
  6. 28
      src/UnitTests/StatisticsTests/HistogramTests.cs
  7. 39
      src/UnitTests/StatisticsTests/PercentileTests.cs
  8. 8
      src/UnitTests/StatisticsTests/StatTestData.cs
  9. 18
      src/UnitTests/StatisticsTests/StatisticsTests.cs

2
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

7
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.
// </copyright>
namespace MathNet.Numerics.Statistics
{
using System;

2
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

8
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
/// <summary>
/// Statistics data.
/// </summary>
private readonly IDictionary<string, StatTestData> _data = new Dictionary<string, StatTestData>();
readonly IDictionary<string, StatTestData> _data = new Dictionary<string, StatTestData>();
/// <summary>
/// Initializes a new instance of the CorrelationTests class.

8
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
/// <summary>
/// Statistics data.
/// </summary>
private readonly IDictionary<string, StatTestData> _data = new Dictionary<string, StatTestData>();
readonly IDictionary<string, StatTestData> _data = new Dictionary<string, StatTestData>();
/// <summary>
/// Initializes a new instance of the DescriptiveStatisticsTests class.

28
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
/// <summary>
/// Datatset array.
/// </summary>
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};
/// <summary>
/// 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);
}
/// <summary>
@ -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);
}
/// <summary>
@ -140,7 +144,7 @@ namespace MathNet.Numerics.UnitTests.StatisticsTests
[Test]
public void CanCreateEmptyHistogram()
{
new Histogram();
var h = new Histogram();
}
/// <summary>
@ -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);
}
/// <summary>
@ -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);
}
/// <summary>
@ -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);
}

39
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
/// <summary>
/// Data array
/// </summary>
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};
/// <summary>
/// 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)));
}

8
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
/// </summary>
/// <param name="str">Parameter name.</param>
/// <returns>Parameter value.</returns>
private static double GetValue(string str)
static double GetValue(string str)
{
var start = str.IndexOf(":");
var value = str.Substring(start + 1).Trim();

18
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
/// <summary>
/// Statistics data.
/// </summary>
private readonly IDictionary<string, StatTestData> _data = new Dictionary<string, StatTestData>();
readonly IDictionary<string, StatTestData> _data = new Dictionary<string, StatTestData>();
/// <summary>
/// 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);

Loading…
Cancel
Save