Browse Source

bugfix: adding data equal to the lower bound of a histogram threw an exception while lower values were fitted appropriately

netstandard
Volker Breuer 11 years ago
parent
commit
518a79045c
  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.
LazySort();
if (d < LowerBound)
if (d <= LowerBound)
{
// Make the lower bound just slightly smaller than the datapoint so it is contained in this bucket.
_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);
}
/// <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>
/// Small dataset histogram without bounds.
/// </summary>

Loading…
Cancel
Save