diff --git a/src/Numerics/Numerics-Net35.csproj b/src/Numerics/Numerics-Net35.csproj
index 9742a3a5..243118dc 100644
--- a/src/Numerics/Numerics-Net35.csproj
+++ b/src/Numerics/Numerics-Net35.csproj
@@ -80,6 +80,7 @@
+
diff --git a/src/Numerics/Numerics.csproj b/src/Numerics/Numerics.csproj
index 9bfd671b..550e7822 100644
--- a/src/Numerics/Numerics.csproj
+++ b/src/Numerics/Numerics.csproj
@@ -81,6 +81,7 @@
+
diff --git a/src/Numerics/Statistics/DescriptiveStatistics.cs b/src/Numerics/Statistics/DescriptiveStatistics.cs
index cf098eb8..4c847c20 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-2013 Math.NET
+// 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
@@ -30,6 +30,7 @@
using System;
using System.Collections.Generic;
+using System.Runtime.Serialization;
namespace MathNet.Numerics.Statistics
{
@@ -38,8 +39,15 @@ namespace MathNet.Numerics.Statistics
/// NIST standard of accuracy for mean, variance, and standard deviation
/// (the only statistics they provide exact values for) and exceeds them
/// in increased accuracy mode.
+ /// Recommendation: consider to use RunningStatistics instead.
///
- /// Consider to use RunningStatistics instead.
+ ///
+ /// This type declares a DataContract for out of the box ephemeral serialization
+ /// with engines like DataContractSerializer, Protocol Buffers and FsPickler,
+ /// but does not guarantee any compatibility between versions.
+ /// It is not recommended to rely on this mechanism for durable persistance.
+ ///
+ [DataContract(Namespace = "urn:MathNet/Numerics")]
public class DescriptiveStatistics
{
///
@@ -104,24 +112,28 @@ namespace MathNet.Numerics.Statistics
/// Gets the size of the sample.
///
/// The size of the sample.
+ [DataMember(Order = 1)]
public long Count { get; private set; }
///
/// Gets the sample mean.
///
/// The sample mean.
+ [DataMember(Order = 2)]
public double Mean { get; private set; }
///
/// Gets the unbiased population variance estimator (on a dataset of size N will use an N-1 normalizer).
///
/// The sample variance.
+ [DataMember(Order = 3)]
public double Variance { get; private set; }
///
/// Gets the unbiased population standard deviation (on a dataset of size N will use an N-1 normalizer).
///
/// The sample standard deviation.
+ [DataMember(Order = 4)]
public double StandardDeviation { get; private set; }
///
@@ -129,6 +141,7 @@ namespace MathNet.Numerics.Statistics
///
/// The sample skewness.
/// Returns zero if is less than three.
+ [DataMember(Order = 5)]
public double Skewness { get; private set; }
///
@@ -136,18 +149,21 @@ namespace MathNet.Numerics.Statistics
///
/// The sample kurtosis.
/// Returns zero if is less than four.
+ [DataMember(Order = 6)]
public double Kurtosis { get; private set; }
///
/// Gets the maximum sample value.
///
/// The maximum sample value.
+ [DataMember(Order = 7)]
public double Maximum { get; private set; }
///
/// Gets the minimum sample value.
///
/// The minimum sample value.
+ [DataMember(Order = 8)]
public double Minimum { get; private set; }
///
diff --git a/src/Numerics/Statistics/Histogram.cs b/src/Numerics/Statistics/Histogram.cs
index b86b44b2..8e9b2610 100644
--- a/src/Numerics/Statistics/Histogram.cs
+++ b/src/Numerics/Statistics/Histogram.cs
@@ -28,18 +28,26 @@
// OTHER DEALINGS IN THE SOFTWARE.
//
+using System;
+using System.Collections.Generic;
+using System.Runtime.Serialization;
+using System.Text;
+using MathNet.Numerics.Properties;
+
namespace MathNet.Numerics.Statistics
{
- using System;
- using System.Collections.Generic;
- using System.Text;
- using Properties;
-
///
/// A consists of a series of s,
/// each representing a region limited by a lower bound (exclusive) and an upper bound (inclusive).
///
+ ///
+ /// This type declares a DataContract for out of the box ephemeral serialization
+ /// with engines like DataContractSerializer, Protocol Buffers and FsPickler,
+ /// but does not guarantee any compatibility between versions.
+ /// It is not recommended to rely on this mechanism for durable persistance.
+ ///
[Serializable]
+ [DataContract(Namespace = "urn:MathNet/Numerics")]
public class Bucket :
#if PORTABLE
IComparable
@@ -71,11 +79,13 @@ namespace MathNet.Numerics.Statistics
///
/// Lower Bound of the Bucket.
///
+ [DataMember(Order = 1)]
public double LowerBound { get; set; }
///
/// Upper Bound of the Bucket.
///
+ [DataMember(Order = 2)]
public double UpperBound { get; set; }
///
@@ -84,6 +94,7 @@ namespace MathNet.Numerics.Statistics
///
/// Value may be NaN if this was constructed as a argument.
///
+ [DataMember(Order = 3)]
public double Count { get; set; }
///
@@ -245,16 +256,19 @@ namespace MathNet.Numerics.Statistics
/// A class which computes histograms of data.
///
[Serializable]
+ [DataContract(Namespace = "urn:MathNet/Numerics")]
public class Histogram
{
///
/// Contains all the Buckets of the Histogram.
///
+ [DataMember(Order = 1)]
private readonly List _buckets;
///
/// Indicates whether the elements of buckets are currently sorted.
///
+ [DataMember(Order = 2)]
private bool _areBucketsSorted;
///
diff --git a/src/Numerics/Statistics/RunningStatistics.cs b/src/Numerics/Statistics/RunningStatistics.cs
index 297792ba..37152f1e 100644
--- a/src/Numerics/Statistics/RunningStatistics.cs
+++ b/src/Numerics/Statistics/RunningStatistics.cs
@@ -1,4 +1,4 @@
-//
+//
// Math.NET Numerics, part of the Math.NET Project
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
@@ -33,6 +33,7 @@
using System;
using System.Collections.Generic;
+using System.Runtime.Serialization;
namespace MathNet.Numerics.Statistics
{
@@ -40,15 +41,35 @@ namespace MathNet.Numerics.Statistics
/// Running statistics accumulator, allows updating by adding values
/// or by combining two accumulators.
///
+ ///
+ /// This type declares a DataContract for out of the box ephemeral serialization
+ /// with engines like DataContractSerializer, Protocol Buffers and FsPickler,
+ /// but does not guarantee any compatibility between versions.
+ /// It is not recommended to rely on this mechanism for durable persistance.
+ ///
+ [DataContract(Namespace = "urn:MathNet/Numerics")]
public class RunningStatistics
{
+ [DataMember(Order = 1)]
long _n;
+
+ [DataMember(Order = 2)]
+ double _min = double.PositiveInfinity;
+
+ [DataMember(Order = 3)]
+ double _max = double.NegativeInfinity;
+
+ [DataMember(Order = 4)]
double _m1;
+
+ [DataMember(Order = 5)]
double _m2;
+
+ [DataMember(Order = 6)]
double _m3;
+
+ [DataMember(Order = 7)]
double _m4;
- double _min = double.PositiveInfinity;
- double _max = double.NegativeInfinity;
public RunningStatistics()
{
diff --git a/src/UnitTests/StatisticsTests/StatisticsSerializationTests.cs b/src/UnitTests/StatisticsTests/StatisticsSerializationTests.cs
new file mode 100644
index 00000000..908401de
--- /dev/null
+++ b/src/UnitTests/StatisticsTests/StatisticsSerializationTests.cs
@@ -0,0 +1,81 @@
+using System.IO;
+using System.Runtime.Serialization;
+using MathNet.Numerics.Statistics;
+using NUnit.Framework;
+
+namespace MathNet.Numerics.UnitTests.StatisticsTests
+{
+ [TestFixture]
+ public class StatisticsSerializationTests
+ {
+ [Test]
+ public void RunningStatisticsDataContractSerializationTest()
+ {
+ var expected = new RunningStatistics(new[] { 1.0, 2.0, 3.0 });
+
+ var serializer = new DataContractSerializer(typeof(RunningStatistics));
+ var stream = new MemoryStream();
+ serializer.WriteObject(stream, expected);
+
+ stream.Position = 0;
+ var actual = (RunningStatistics)serializer.ReadObject(stream);
+
+ Assert.That(actual.Count, Is.EqualTo(expected.Count));
+ Assert.That(actual.Maximum, Is.EqualTo(expected.Maximum));
+ Assert.That(actual.Mean, Is.EqualTo(expected.Mean));
+ }
+
+ [Test]
+ public void RunningStatisticsWithInfinityNaNDataContractSerializationTest()
+ {
+ var expected = new RunningStatistics(new[] { 1.0, 2.0, 3.0, double.PositiveInfinity, double.NaN });
+
+ var serializer = new DataContractSerializer(typeof(RunningStatistics));
+ var stream = new MemoryStream();
+ serializer.WriteObject(stream, expected);
+
+ stream.Position = 0;
+ var actual = (RunningStatistics)serializer.ReadObject(stream);
+
+ Assert.That(actual.Count, Is.EqualTo(expected.Count));
+ Assert.That(actual.Maximum, Is.EqualTo(expected.Maximum));
+ Assert.That(actual.Mean, Is.EqualTo(expected.Mean));
+ }
+
+ [Test]
+ public void DescriptiveStatisticsDataContractSerializationTest()
+ {
+ var expected = new DescriptiveStatistics(new[] { 1.0, 2.0, 3.0 });
+
+ var serializer = new DataContractSerializer(typeof(DescriptiveStatistics));
+ var stream = new MemoryStream();
+ serializer.WriteObject(stream, expected);
+
+ stream.Position = 0;
+ var actual = (DescriptiveStatistics)serializer.ReadObject(stream);
+
+ Assert.That(actual.Count, Is.EqualTo(expected.Count));
+ Assert.That(actual.Maximum, Is.EqualTo(expected.Maximum));
+ Assert.That(actual.Mean, Is.EqualTo(expected.Mean));
+ }
+
+ [Test]
+ public void HistogramDataContractSerializationTest()
+ {
+ var expected = new Histogram(new[] { 1.0, 2.0, 3.0, 4.0 }, 2);
+
+ var serializer = new DataContractSerializer(typeof(Histogram));
+ var stream = new MemoryStream();
+ serializer.WriteObject(stream, expected);
+
+ stream.Position = 0;
+ var actual = (Histogram)serializer.ReadObject(stream);
+
+ Assert.That(actual.BucketCount, Is.EqualTo(expected.BucketCount));
+ Assert.That(actual.DataCount, Is.EqualTo(expected.DataCount));
+ Assert.That(actual.LowerBound, Is.EqualTo(expected.LowerBound));
+ Assert.That(actual[0].Width, Is.EqualTo(expected[0].Width));
+ Assert.That(actual[0].UpperBound, Is.EqualTo(expected[0].UpperBound));
+ }
+ }
+}
diff --git a/src/UnitTests/UnitTests-Net35.csproj b/src/UnitTests/UnitTests-Net35.csproj
index fbb5e800..d65607e1 100644
--- a/src/UnitTests/UnitTests-Net35.csproj
+++ b/src/UnitTests/UnitTests-Net35.csproj
@@ -59,6 +59,8 @@
+
+
diff --git a/src/UnitTests/UnitTests-Portable259.csproj b/src/UnitTests/UnitTests-Portable259.csproj
index 0858525a..63417c71 100644
--- a/src/UnitTests/UnitTests-Portable259.csproj
+++ b/src/UnitTests/UnitTests-Portable259.csproj
@@ -44,6 +44,8 @@
+
+
diff --git a/src/UnitTests/UnitTests-Portable328.csproj b/src/UnitTests/UnitTests-Portable328.csproj
index 55d26134..62762c12 100644
--- a/src/UnitTests/UnitTests-Portable328.csproj
+++ b/src/UnitTests/UnitTests-Portable328.csproj
@@ -44,6 +44,8 @@
+
+
diff --git a/src/UnitTests/UnitTests-Portable47.csproj b/src/UnitTests/UnitTests-Portable47.csproj
index 23f4369d..d8a896eb 100644
--- a/src/UnitTests/UnitTests-Portable47.csproj
+++ b/src/UnitTests/UnitTests-Portable47.csproj
@@ -52,6 +52,8 @@
{49205185-621E-FFB9-2104-887C9F1BBD13}
Numerics-Portable47
+
+
diff --git a/src/UnitTests/UnitTests-Portable7.csproj b/src/UnitTests/UnitTests-Portable7.csproj
index 1e091034..9d801adc 100644
--- a/src/UnitTests/UnitTests-Portable7.csproj
+++ b/src/UnitTests/UnitTests-Portable7.csproj
@@ -52,6 +52,8 @@
{25E6E93B-56A2-4F14-8458-03665F122B3F}
Numerics-Portable7
+
+
diff --git a/src/UnitTests/UnitTests-Portable78.csproj b/src/UnitTests/UnitTests-Portable78.csproj
index 5fb33db7..8393adcc 100644
--- a/src/UnitTests/UnitTests-Portable78.csproj
+++ b/src/UnitTests/UnitTests-Portable78.csproj
@@ -52,6 +52,8 @@
{2EBD6F22-9BD6-4AF2-A21B-7198C9C5571F}
Numerics-Portable78
+
+
diff --git a/src/UnitTests/UnitTests.csproj b/src/UnitTests/UnitTests.csproj
index 91b8405d..b64c0ed7 100644
--- a/src/UnitTests/UnitTests.csproj
+++ b/src/UnitTests/UnitTests.csproj
@@ -75,6 +75,8 @@
{B7CAE5F4-A23F-4438-B5BE-41226618B695}
Numerics
+
+
@@ -398,6 +400,7 @@
+