Skip to content

Commit

Permalink
Fix off-by-one in mean/stddev accumulators
Browse files Browse the repository at this point in the history
  • Loading branch information
olorin committed Apr 4, 2016
1 parent a880367 commit 2921657
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/Warden/Numeric.hs
Original file line number Diff line number Diff line change
Expand Up @@ -136,18 +136,18 @@ combineVariance (MeanAcc muHat) (MeanAcc mu1, Variance var1, KAcc c1) (MeanAcc m
t2 = c2' * (var2 + (mu2 ** two)) in
Variance $ ((t1 + t2) / (c1' + c2')) - (muHat ** two)
where
c1' = fromIntegral c1
c1' = fromIntegral $ c1 - 1

c2' = fromIntegral c2
c2' = fromIntegral $ c2 - 1

two = 2.0 :: Double
{-# INLINE combineVariance #-}

-- | Combine mean of two subsets, given subset means and size.
combineMeanAcc :: (MeanAcc, KAcc) -> (MeanAcc, KAcc) -> MeanAcc
combineMeanAcc (MeanAcc mu1, KAcc c1) (MeanAcc mu2, KAcc c2) =
let c1' = fromIntegral c1
c2' = fromIntegral c2 in
let c1' = fromIntegral $ c1 - 1
c2' = fromIntegral $ c2 - 1 in
MeanAcc $ ((mu1 * c1') + (mu2 * c2')) / (c1' + c2')
{-# INLINE combineMeanAcc #-}

Expand Down

0 comments on commit 2921657

Please sign in to comment.