bos/statistics — Issue #29: Value at upper bound causes error in histogram_ and kde_
Author: twanvl
Created: 2012-02-13 20:29:27+00:00
State: open

A value equal to the upper bound of `histogram_` causes an array index out of bounds exception (or maybe an access violation, since unsafe operations are used). By extension, this error also occurs in `kde_`, since it calls `histogram_`.

```haskell
import Statistics.Sample.Histogram
import Data.Vector.Unboxed as U
> histogram_ 10 0.0 1.0 (U.fromList [1.0]) :: U.Vector Double
fromList *** Exception: .\Data\Vector\Generic\Mutable.hs:576 (read): index out of bounds (10,10)
```

This happens because the calculated bin will be `truncate 1.0/(1.0/10) = 10`, which is just outside the bounds. Using a value of `1.0-epsilon` in the list or a bound of `1.0+epsilon` does not produce the error.

The reason I encountered this problem is because I was computing the kde of values known to be in the range [0...1].

To save future debugging time, could you add a note to the documentation of `kde_` saying something like "Sample data not strictly inside the bounds will cause an error"?

And for `histogram_`, which does include such a warning:
"Sample data that falls above the upper bound will cause an error."
should be changed to the longer but slightly more correct:
"Sample data that falls above *or on* the upper bound will cause an error."