This project has moved. For the latest updates, please go here.

DescriptiveStatistics basic operation question

Jan 9, 2013 at 9:34 PM
Edited Jan 9, 2013 at 9:34 PM


I realize this is probably a basic question, but I could not find it elsewhere. Could someone explain to me why this assertion always fails?
            var sampleData = new MathNet.Numerics.Distributions.Normal(100, 10).Samples().Take(100);
            var statisticsOnSampleData = new DescriptiveStatistics(sampleData);
            var statistics = new DescriptiveStatistics(sampleData);
            Assert.AreEqual(statisticsOnSampleData.Maximum, statistics.Maximum);

For example, in the test I just ran I got:

  Expected: 140.76833900997369d
  But was:  130.09605112204633d

Which is too big of a difference for overflow.

Jan 9, 2013 at 9:48 PM

Note that sampleData is an enumerable that will generate different samples on each enumeration. Lines 2 and 3 thus operate on different data.

If you use sampleData2 = sampleData.ToArray() or sampleData.ToList() instead, both statistics should be equivalent.

Marked as answer by cdrnet on 10/3/2013 at 5:51 PM
Jan 9, 2013 at 10:08 PM

Thanks. That clears it up.