How to resolve the algorithm Cumulative standard deviation step by step in the Clojure programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Cumulative standard deviation step by step in the Clojure programming language
Table of Contents
Problem Statement
Write a stateful function, class, generator or co-routine that takes a series of floating point numbers, one at a time, and returns the running standard deviation of the series. The task implementation should use the most natural programming style of those listed for the function in the implementation language; the task must state which is being used. Do not apply Bessel's correction; the returned standard deviation should always be computed as if the sample seen so far is the entire population.
Use this to compute the standard deviation of this demonstration set,
{ 2 , 4 , 4 , 4 , 5 , 5 , 7 , 9 }
{\displaystyle {2,4,4,4,5,5,7,9}}
, which is
2
{\displaystyle 2}
.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Cumulative standard deviation step by step in the Clojure programming language
Source code in the clojure programming language
(defn stateful-std-deviation[x]
(letfn [(std-dev[x]
(let [v (deref (find-var (symbol (str *ns* "/v"))))]
(swap! v conj x)
(let [m (/ (reduce + @v) (count @v))]
(Math/sqrt (/ (reduce + (map #(* (- m %) (- m %)) @v)) (count @v))))))]
(when (nil? (resolve 'v))
(intern *ns* 'v (atom [])))
(std-dev x)))
You may also check:How to resolve the algorithm Determine if a string is numeric step by step in the F# programming language
You may also check:How to resolve the algorithm Walk a directory/Recursively step by step in the ooRexx programming language
You may also check:How to resolve the algorithm Haversine formula step by step in the tbas programming language
You may also check:How to resolve the algorithm Matrix multiplication step by step in the Nim programming language
You may also check:How to resolve the algorithm Roots of unity step by step in the Mathematica/Wolfram Language programming language