Cumulative standard deviation: Difference between revisions

m
Line 1,904:
 
 
Or, perhaps more simply, as a map-accumulation over an indexed list:
 
<lang Haskell>import Data.List (mapAccumL)
 
-------------- CUMULATIVE STANDARD DEVIATION -------------
 
cumulativeStdDevns :: [Float] -> [Float]
cumulativeStdDevns xs = snd $ mapAccumL go (0, 0) $ zip [1.0 ..] xs
where
go (s, q) (i, x) =
let _s = s + x
_q = q + (x ^ 2)
in ((_s, _q), sqrt _i((_q =/ fromIntegrali) - ((_s / i) ^ 2)))
in ((_s, _q), sqrt ((_q / _i) - ((_s / _i) ^ 2)))
 
 
--------------------------- TEST -------------------------
main :: IO ()
9,655

edits