palavrix / moa

Automatically exported from code.google.com/p/moa
0 stars 0 forks source link

Bug in GaussianEstimator mean and variance calculations #9

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Reproducing problem:

GaussianEstimator estimator = new GaussianEstimator();
estimator.addObservation(7.0, 2.0);
estimator.addObservation(9.0, 2.0);
System.out.println(estimator.getMean()); // prints 7.5, expected 8.0
System.out.println(estimator.getVariance()); // prints 1.0, expected 1.333

MOA Version: 3a28638d4f55 May 2, 2012

Patch attached.

I am pretty sure the variance calculation in addObservation(GaussianEstimator) 
is also wrong, but I don't know how to fix it.

Original issue reported on code.google.com by hdd...@gmail.com on 14 Nov 2012 at 9:38

Attachments:

GoogleCodeExporter commented 8 years ago
Changed on the repository in Jan 17, 2013

We followed

Incremental calculation of weighted mean and variance by Tony Finch
http://nfs-uxsup.csx.cam.ac.uk/~fanf2/hermes/doc/antiforgery/stats.pdf

mean = mean + weight *(value - lastMean)/weightSum
varianceSum = varianceSum + weight * (value - lastMean) * (value - mean)

Original comment by abi...@gmail.com on 22 Aug 2013 at 1:39