|
Boost : |
From: Michael Stevens (list-boost_at_[hidden])
Date: 2006-11-23 15:13:19
On Tuesday, 21. November 2006 18:49, Matthias Troyer wrote:
> On 20 Nov 2006, at 00:44, Michael Stevens wrote:
> > The 'variance' accumulator has a lazy calculation of variance using
> > the
> > formula \sigma_n^2 = M_n^{(2)} - \mu_n^2. This formal is
> > specifically
> > cited for it poor performance in the presence of rounding error.
> > Indeed it
> > may even return negative results.
>
> That's exactly why there is not only the lazy version but also an
> accurate one
Looking at variance.hpp there is a 'lazy' version and a 'iterative' version.
The naming confused me. I was expecting lazy to have access to all the da and
so be the most accurate. I guess my comments with regard to the lazy version
are simply a matter of documenting the poor numerics.
The iterative formal is via (n-1)/n * variance[n-1] + 1/(n-1) *
(difference)^2. This is still numerically different from accumalating the
differences squared iteratively and applying the 1/n is the result.
I guess there is always a good reason to apply build ones own implementation
to meet specific numericical requirements.
Thanks,
Michael
-- ___________________________________ Michael Stevens Systems Engineering 34128 Kassel, Germany Phone/Fax: +49 561 5218038 Navigation Systems, Estimation and Bayesian Filtering http://bayesclasses.sf.net ___________________________________
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk