summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexeyKhudyakov <>2013-12-26 18:22:00 (GMT)
committerhdiff <hdiff@hdiff.luite.com>2013-12-26 18:22:00 (GMT)
commit6f900c8ddabc37d98266abc8cbe823937ffec0c4 (patch)
treee741765bb2e49cd74bdae575cd6d3d9fe225378d
parent0d8cbb5e7bec869e79c79f68236a92906ecc487d (diff)
version 0.10.5.20.10.5.2
-rw-r--r--ChangeLog7
-rw-r--r--Statistics/Sample/Histogram.hs12
-rw-r--r--statistics.cabal2
3 files changed, 18 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index 247f20a..08bf513 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+
+Changes in 0.10.5.2
+
+ * histogram correctly chooses range when all elements in the sample are same
+ (bug #57)
+
+
Changes in 0.10.5.1
* Bug fix for S.Distributions.Normal.standard introduced in 0.10.5.0 (Bug #56)
diff --git a/Statistics/Sample/Histogram.hs b/Statistics/Sample/Histogram.hs
index e779a5c..e639de6 100644
--- a/Statistics/Sample/Histogram.hs
+++ b/Statistics/Sample/Histogram.hs
@@ -19,7 +19,7 @@ module Statistics.Sample.Histogram
, range
) where
-import Numeric.MathFunctions.Constants (m_epsilon)
+import Numeric.MathFunctions.Constants (m_epsilon,m_tiny)
import Statistics.Function (minMax)
import qualified Data.Vector.Generic as G
import qualified Data.Vector.Generic.Mutable as GM
@@ -84,13 +84,21 @@ histogram_ numBins lo hi xs0 = G.create (GM.replicate numBins 0 >>= bin xs0)
-- The upper and lower bounds used are @(lo-d, hi+d)@, where
--
-- @d = (maximum sample - minimum sample) / ((bins - 1) * 2)@
+--
+-- If all elements in the sample are the same and equal to @x@ range
+-- is set to @(x - |x|/10, x + |x|/10)@. And if @x@ is equal to 0 range
+-- is set to @(-1,1)@. This is needed to avoid creating histogram with
+-- zero bin size.
range :: (G.Vector v Double) =>
Int -- ^ Number of bins (must be positive).
-> v Double -- ^ Sample data (cannot be empty).
- -> (Double, Double)
+ -> (Double, Double)
range numBins xs
| numBins < 1 = error "Statistics.Histogram.range: invalid bin count"
| G.null xs = error "Statistics.Histogram.range: empty sample"
+ | lo == hi = case abs lo / 10 of
+ a | a < m_tiny -> (-1,1)
+ | otherwise -> (lo - a, lo + a)
| otherwise = (lo-d, hi+d)
where
d | numBins == 1 = 0
diff --git a/statistics.cabal b/statistics.cabal
index 74d95ff..609aa8b 100644
--- a/statistics.cabal
+++ b/statistics.cabal
@@ -1,5 +1,5 @@
name: statistics
-version: 0.10.5.1
+version: 0.10.5.2
synopsis: A library of statistical types, data, and functions
description:
This library provides a number of common functions and types useful