[Haskell-cafe] operating on a hundred files at once

Jefferson Heard jeff at renci.org
Tue Apr 10 10:15:00 EDT 2007

Thanks, Ketil.  I knew I could calcuate the mean in constant space, but
I didn't think about the variance.  Much appreciated.

On Tue, 2007-04-10 at 08:30 +0200, Ketil Malde wrote:
> 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