Browse Source

Merge pull request #353 from vkb/histogram_boundary_fix

Histogram: Adding data equal to the lower bound
netstandard
Christoph Ruegg 11 years ago
parent
commit
8879f15f7d
  1. 2
      src/Numerics/Statistics/Histogram.cs
  2. 12
      src/UnitTests/StatisticsTests/HistogramTests.cs

2
src/Numerics/Statistics/Histogram.cs

@ -344,7 +344,7 @@ namespace MathNet.Numerics.Statistics
// Sort if needed. // Sort if needed.
LazySort(); LazySort();
if (d < LowerBound) if (d <= LowerBound)
{ {
// Make the lower bound just slightly smaller than the datapoint so it is contained in this bucket. // Make the lower bound just slightly smaller than the datapoint so it is contained in this bucket.
_buckets[0].LowerBound = d.Decrement(); _buckets[0].LowerBound = d.Decrement();

12
src/UnitTests/StatisticsTests/HistogramTests.cs

@ -348,6 +348,18 @@ namespace MathNet.Numerics.UnitTests.StatisticsTests
Assert.AreEqual(3, h[0].Count); Assert.AreEqual(3, h[0].Count);
} }
/// <summary>
/// Add data equal to the lower bound of a histogram.
/// </summary>
[Test]
public void AddDataEqualToLowerBound()
{
var h = new Histogram(new[] { 1.0, 5.0, 10.0 }, 3, 0.0, 10.0);
Assert.DoesNotThrow(() => h.AddData(0.0));
Assert.AreEqual(2, h[0].Count);
}
/// <summary> /// <summary>
/// Small dataset histogram without bounds. /// Small dataset histogram without bounds.
/// </summary> /// </summary>

Loading…
Cancel
Save