Cumulative standard deviation: Difference between revisions
m
→{{header|Haskell}}: Tidying
m (→{{header|Haskell}}: Tidying) |
|||
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
--------------------------- TEST -------------------------
main :: IO ()
|