Cumulative standard deviation: Difference between revisions
Content added Content deleted
m (→only show standard deviation: aligned statements.) |
m (→{{header|AppleScript}}: Tidying) |
||
Line 459: | Line 459: | ||
=={{header|AppleScript}}== |
=={{header|AppleScript}}== |
||
Accumulation |
Accumulation over a fold: |
||
<lang AppleScript>-- |
<lang AppleScript>-------------- CUMULATIVE STANDARD DEVIATION ------------- |
||
-- stdDevInc :: Accumulator -> Num -> Index -> Accumulator |
|||
-- stdDevInc :: {sum:, squaresSum:, stages:} -> Real -> Integer |
-- stdDevInc :: {sum:, squaresSum:, stages:} -> Real -> Integer |
||
-- -> {sum:, squaresSum:, stages:} |
-- -> {sum:, squaresSum:, stages:} |
||
Line 474: | Line 476: | ||
--------------------------- TEST ------------------------- |
|||
-- TEST |
|||
on run |
on run |
||
set |
set xs to [2, 4, 4, 4, 5, 5, 7, 9] |
||
stages of foldl(stdDevInc, ¬ |
stages of foldl(stdDevInc, ¬ |
||
{sum:0, squaresSum:0, stages:[]}, |
{sum:0, squaresSum:0, stages:[]}, xs) |
||
--> {0.0, 1.0, 0.942809041582, 0.866025403784, 0.979795897113, 1.0, 1.399708424448, 2.0} |
--> {0.0, 1.0, 0.942809041582, 0.866025403784, 0.979795897113, 1.0, 1.399708424448, 2.0} |
||
Line 486: | Line 488: | ||
-------------------- GENERIC FUNCTIONS ------------------- |
|||
-- foldl :: (a -> b -> a) -> a -> [b] -> a |
-- foldl :: (a -> b -> a) -> a -> [b] -> a |
||
Line 499: | Line 501: | ||
end tell |
end tell |
||
end foldl |
end foldl |
||
-- Lift 2nd class handler function into 1st class script wrapper |
-- Lift 2nd class handler function into 1st class script wrapper |