[Haskell-cafe] operating on a hundred files at once
Ketil Malde
ketil at ii.uib.no
Tue Apr 10 02:30:43 EDT 2007
On Tue, 2007-04-10 at 13:16 +1000, Duncan Coutts wrote:
> Note, that like in your original we read each file twice, once for the
> mean and once for the variance.
As an aside, you can calculate both mean and variance in one pass (and
constant space) by calculating the sum of elements 'x', the sum of
squared elements 'x2', and keeping track of the number of elements 'n'.
mean = x/n
var = (x2-mean*mean*n)/(n-1)
If you track the sum of cubed elements (x3) and the powers of four (x4),
you also get kurtosis and skew in a similar manner.
-k
More information about the Haskell-Cafe
mailing list