Permalink
Browse files

Avoid overflow of exponent in calculation of geometric mean

Fixes #38 by Alex Lang
  • Loading branch information...
1 parent 66da636 commit 8d9bf871c52bde878a684a25eeb9204044618db3 @Shimuuar Shimuuar committed Aug 31, 2012
Showing with 1 addition and 4 deletions.
  1. +1 −4 Statistics/Sample.hs
View
@@ -101,10 +101,7 @@ harmonicMean = fini . G.foldl' go (T 0 0)
-- | /O(n)/ Geometric mean of a sample containing no negative values.
geometricMean :: (G.Vector v Double) => v Double -> Double
-geometricMean = fini . G.foldl' go (T 1 0)
- where
- fini (T p n) = p ** (1 / fromIntegral n)
- go (T p n) a = T (p * a) (n + 1)
+geometricMean = exp . mean . G.map log
{-# INLINE geometricMean #-}
-- | Compute the /k/th central moment of a sample. The central moment

0 comments on commit 8d9bf87

Please sign in to comment.