|
|
@ -28,10 +28,6 @@ |
|
|
// OTHER DEALINGS IN THE SOFTWARE.
|
|
|
// OTHER DEALINGS IN THE SOFTWARE.
|
|
|
// </copyright>
|
|
|
// </copyright>
|
|
|
|
|
|
|
|
|
using System; |
|
|
|
|
|
using System.Collections.Generic; |
|
|
|
|
|
using System.Diagnostics; |
|
|
|
|
|
using System.Runtime.InteropServices; |
|
|
|
|
|
using MathNet.Numerics.Distributions; |
|
|
using MathNet.Numerics.Distributions; |
|
|
using MathNet.Numerics.Random; |
|
|
using MathNet.Numerics.Random; |
|
|
using MathNet.Numerics.Statistics; |
|
|
using MathNet.Numerics.Statistics; |
|
|
@ -39,17 +35,18 @@ using NUnit.Framework; |
|
|
|
|
|
|
|
|
namespace MathNet.Numerics.UnitTests.StatisticsTests |
|
|
namespace MathNet.Numerics.UnitTests.StatisticsTests |
|
|
{ |
|
|
{ |
|
|
#if !PORTABLE
|
|
|
|
|
|
[TestFixture, Category("Statistics")] |
|
|
[TestFixture, Category("Statistics")] |
|
|
public class MovingStatisticsTests |
|
|
public class MovingStatisticsTests |
|
|
{ |
|
|
{ |
|
|
[Test] |
|
|
[Test] |
|
|
public void QuickTest() |
|
|
public void StabilityTest() |
|
|
{ |
|
|
{ |
|
|
var data = new double[1000000]; |
|
|
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); |
|
|
var ms = new MovingStatistics(5, data); |
|
|
ms.PushRange(new[] { 11.11, 22.22, 33.33, 44.44, 55.55 }); |
|
|
ms.PushRange(new[] { 11.11, 22.22, 33.33, 44.44, 55.55 }); |
|
|
|
|
|
|
|
|
Assert.AreEqual(5, ms.Count); |
|
|
Assert.AreEqual(5, ms.Count); |
|
|
Assert.AreEqual(11.11, ms.Minimum); |
|
|
Assert.AreEqual(11.11, ms.Minimum); |
|
|
Assert.AreEqual(55.55, ms.Maximum); |
|
|
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.Variance, ms.Variance, 14);
|
|
|
//AssertHelpers.AlmostEqualRelative(stats0.StandardDeviation, ms.StandardDeviation, 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
|
|
|
|
|
|
} |
|
|
} |
|
|
|