histogram - added another upper bin to include cases which have max values
authorFriedrich Beckmann <friedrich.beckmann@gmx.de>
Tue, 16 Feb 2016 09:30:32 +0000 (10:30 +0100)
committerFriedrich Beckmann <friedrich.beckmann@gmx.de>
Tue, 16 Feb 2016 09:30:32 +0000 (10:30 +0100)
This fixes the problem that cases which have values exactly at the upper
bin limit of the upper bin are not included in the binning. The fix
is based on the idea from John to just add another bin when the bin
limit is just equal to the maximum case value.

src/math/histogram.c

index 60adaa92d1b1c92e65763223cd26ce6ec9fb621a..8aaa16f9e0a684bca8333fee51d6c6874319a69b 100644 (file)
@@ -119,6 +119,15 @@ hist_find_pretty_no_of_bins(double bin_width_in, double min, double max,
   nbins = ceil((max-*adjusted_min)/binwidth);
   *adjusted_max = nbins*binwidth + *adjusted_min;
 
+  /* adjusted_max should never be smaller than max but if it is equal
+     then the gsl_histogram will not add the cases which have max value */
+  if (*adjusted_max <= max)
+    {
+      *adjusted_max += binwidth;
+      nbins++;
+    }
+  assert (*adjusted_min <= min);
+
   return nbins;
 }