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

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to