Skip to content
This repository
Browse code

More efficient S.D.Normal.normalFromSample

Traverse sample only twice. Estimation os standard deviation
recalculated mean.

Almost 2x performance gain
  • Loading branch information...
commit 53b2e075bcf852c32bea25001fb0c3c1efa08dde 1 parent 07c9555
Aleksey Khudyakov Shimuuar authored

Showing 1 changed file with 4 additions and 1 deletion. Show diff stats Hide diff stats

  1. +4 1 Statistics/Distribution/Normal.hs
5 Statistics/Distribution/Normal.hs
@@ -88,7 +88,10 @@ normalDistr m sd
88 88 -- sample. Variance is estimated using maximum likelihood method
89 89 -- (biased estimation).
90 90 normalFromSample :: S.Sample -> NormalDistribution
91   -normalFromSample a = normalDistr (S.mean a) (S.stdDev a)
  91 +normalFromSample xs
  92 + = normalDistr m (sqrt v)
  93 + where
  94 + (m,v) = S.meanVariance xs
92 95
93 96 density :: NormalDistribution -> Double -> Double
94 97 density d x = exp (-xm * xm / (2 * sd * sd)) / ndPdfDenom d

0 comments on commit 53b2e07

Please sign in to comment.
Something went wrong with that request. Please try again.