|
|
|
@ -3,9 +3,9 @@ |
|
|
|
// http://numerics.mathdotnet.com
|
|
|
|
// http://github.com/mathnet/mathnet-numerics
|
|
|
|
// http://mathnetnumerics.codeplex.com
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// Copyright (c) 2009-2015 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
|
|
|
|
@ -14,10 +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
|
|
|
|
@ -28,10 +28,6 @@ |
|
|
|
// OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
// </copyright>
|
|
|
|
|
|
|
|
using System; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Diagnostics; |
|
|
|
using System.Runtime.InteropServices; |
|
|
|
using MathNet.Numerics.Distributions; |
|
|
|
using MathNet.Numerics.Random; |
|
|
|
using MathNet.Numerics.Statistics; |
|
|
|
@ -39,17 +35,18 @@ using NUnit.Framework; |
|
|
|
|
|
|
|
namespace MathNet.Numerics.UnitTests.StatisticsTests |
|
|
|
{ |
|
|
|
#if !PORTABLE
|
|
|
|
[TestFixture, Category("Statistics")] |
|
|
|
public class MovingStatisticsTests |
|
|
|
{ |
|
|
|
[Test] |
|
|
|
public void QuickTest() |
|
|
|
public void StabilityTest() |
|
|
|
{ |
|
|
|
var data = new double[1000000]; |
|
|
|
(new Normal(50, 10, new SystemRandomSource(0))).Samples(data); |
|
|
|
Normal.Samples(new SystemRandomSource(0), data, 50, 10); |
|
|
|
|
|
|
|
var ms = new MovingStatistics(5, data); |
|
|
|
ms.PushRange(new[] { 11.11, 22.22, 33.33, 44.44, 55.55 }); |
|
|
|
|
|
|
|
Assert.AreEqual(5, ms.Count); |
|
|
|
Assert.AreEqual(11.11, ms.Minimum); |
|
|
|
Assert.AreEqual(55.55, ms.Maximum); |
|
|
|
@ -61,6 +58,51 @@ namespace MathNet.Numerics.UnitTests.StatisticsTests |
|
|
|
//AssertHelpers.AlmostEqualRelative(stats0.Variance, ms.Variance, 14);
|
|
|
|
//AssertHelpers.AlmostEqualRelative(stats0.StandardDeviation, ms.StandardDeviation, 14);
|
|
|
|
} |
|
|
|
|
|
|
|
[Test] |
|
|
|
public void NaNTest() |
|
|
|
{ |
|
|
|
var ms = new MovingStatistics(3); |
|
|
|
Assert.That(ms.Minimum, Is.NaN); |
|
|
|
Assert.That(ms.Maximum, Is.NaN); |
|
|
|
Assert.That(ms.Mean, Is.NaN); |
|
|
|
Assert.That(ms.StandardDeviation, Is.NaN); |
|
|
|
|
|
|
|
ms.Push(1.0); |
|
|
|
Assert.That(ms.Minimum, Is.Not.NaN); |
|
|
|
Assert.That(ms.Maximum, Is.Not.NaN); |
|
|
|
Assert.That(ms.Mean, Is.Not.NaN); |
|
|
|
Assert.That(ms.StandardDeviation, Is.NaN); |
|
|
|
|
|
|
|
ms.Push(2.0); |
|
|
|
Assert.That(ms.Minimum, Is.Not.NaN); |
|
|
|
Assert.That(ms.Maximum, Is.Not.NaN); |
|
|
|
Assert.That(ms.Mean, Is.Not.NaN); |
|
|
|
Assert.That(ms.StandardDeviation, Is.Not.NaN); |
|
|
|
|
|
|
|
ms.Push(double.NaN); |
|
|
|
Assert.That(ms.Minimum, Is.NaN); |
|
|
|
Assert.That(ms.Maximum, Is.NaN); |
|
|
|
Assert.That(ms.Mean, Is.NaN); |
|
|
|
Assert.That(ms.StandardDeviation, Is.NaN); |
|
|
|
|
|
|
|
ms.Push(1.0); |
|
|
|
Assert.That(ms.Minimum, Is.NaN); |
|
|
|
Assert.That(ms.Maximum, Is.NaN); |
|
|
|
Assert.That(ms.Mean, Is.NaN); |
|
|
|
Assert.That(ms.StandardDeviation, Is.NaN); |
|
|
|
|
|
|
|
ms.Push(2.0); |
|
|
|
Assert.That(ms.Minimum, Is.NaN); |
|
|
|
Assert.That(ms.Maximum, Is.NaN); |
|
|
|
Assert.That(ms.Mean, Is.NaN); |
|
|
|
Assert.That(ms.StandardDeviation, Is.NaN); |
|
|
|
|
|
|
|
ms.Push(3.0); |
|
|
|
Assert.That(ms.Minimum, Is.Not.NaN); |
|
|
|
Assert.That(ms.Maximum, Is.Not.NaN); |
|
|
|
Assert.That(ms.Mean, Is.Not.NaN); |
|
|
|
Assert.That(ms.StandardDeviation, Is.Not.NaN); |
|
|
|
} |
|
|
|
} |
|
|
|
#endif
|
|
|
|
} |
|
|
|
|