|
Boost Users : |
Subject: Re: [Boost-users] [Accumulators] Questions about the library
From: adish (adishavit_at_[hidden])
Date: 2009-06-26 15:08:13
Hi,
> > By UDT do you mean User Defined Type? ...
> Yes, I mean writing a class/struct. I had to overload '<', '>', '+=' and '/' and I use it for variance, mean, median, min, max and my implementation of percentile. Remember to specialize std::numeric_limits for the UDT you write. Else, the min and/or max will have values that you have not added in the accumulator (garbage values). I had a tough time debugging it and finding the solution. Also, on Windows, you need to derive your specialization from _Num_base.
Thanks for the tips, I'll give it a try.
> As for implementing a generic rolling type:
> 1. You need to store your values in a circular buffer.
> 2. Each time you add a value into the buffer, pass the contents to a pristine accumulator. This may be sub optimal but works. Especially for those calculations where it is not easy to remove the effect of the first data that you want to pop. I had to do it this way because I was dealing with time series. If I want a rolling computation for a 1 hour window, I might add 1 sample and may have to remove more than 1 sample to ensure first-last is 1 hour window in the buffer.
Yes, I guess that would be the simplest way to do it, though there are
"incremental" O(1) algorithms that do not require recomputing the
whole series every time (at the cost of at least O(n)).
These are the ones I am interested in (see e.g. here: <http://
en.wikipedia.org/wiki/Algorithms_for_calculating_variance>).
Thanks,
Adi
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net