12

I am looking at the boost::accumulator framework, specifically a couple of the rolling_window calculations.

#include <boost/accumulators/accumulators.hpp>
#include <boost/accumulators/statistics/stats.hpp>
#include <boost/accumulators/statistics/rolling_mean.hpp>
accumulator_set<int, stats<tag::rolling_mean> > acc(tag::rolling_window::window_size = 3);

As you see here, I have set the window_size to be three, such that it is maintaining the mean average of the last three samples only.

Can I amend that size at run-time, perhaps based on a user setting?

If so, and I increase the window_size does the accumulator have extra internal state if it had already seen more than my new window_size, or would I have to wait for the extra values?

sdg
  • 4,645
  • 3
  • 32
  • 26

1 Answers1

7

The best way to reset a boost accumulator is to assign it to a new one. For example:

typedef accumulator_set<int, ... template crazyness tags ... > window_acc;

window_acc acc;
acc(1);
acc(2);
...
// reset
acc = window_acc();

Actually, swap would be preferred here, but accumulator_set doesn't have a swap member =\

Inverse
  • 4,408
  • 2
  • 26
  • 35
  • That would effective start-over, yes; such that I need to re-accumulate data? Can I somehow keep the data and overlay a new computation? – sdg Mar 04 '11 at 18:28
  • @sdg: Ahh I see. I dont think so :\ You'd have to mess around with the internals of the accumulator manually. I would recommend rolling your own rolling average here, with a circular buffer or deque to get what you want. – Inverse Mar 04 '11 at 18:59
  • It would be nice if it had a clear function like STL containers. – gast128 Apr 12 '19 at 09:40