A histogram is defined by the following struct,
- This is the number of histogram bins
double * range
- The ranges of the bins are stored in an array of n+1 elements pointed to by range.
double * bin
- The counts for each bin are stored in an array of n elements pointed to by bin. The bins are floating-point numbers, so you can increment them by non-integer values if necessary.
The range for bin[i] is given by range[i] to range[i+1]. For n bins there are n+1 entries in the array range. Each bin is inclusive at the lower end and exclusive at the upper end. Mathematically this means that the bins are defined by the following inequality,
bin[i] corresponds to range[i] <= x < range[i+1]
Here is a diagram of the correspondence between ranges and bins on the number-line for x,
[ bin )[ bin )[ bin )[ bin )[ bin ) ---|---------|---------|---------|---------|---------|--- x r r r r r r
In this picture the values of the range array are denoted by r. On the left-hand side of each bin the square bracket ‘[’ denotes an inclusive lower bound ( r <= x), and the round parentheses ‘)’ on the right-hand side denote an exclusive upper bound (x < r). Thus any samples which fall on the upper end of the histogram are excluded. If you want to include this value for the last bin you will need to add an extra bin to your histogram.
gsl_histogram struct and its associated functions are defined
in the header file gsl_histogram.h.