Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using boost::accumulators, how can I reset a rolling window size, does it keep extra history?

Tags:

c++

boost

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?

like image 401
sdg Avatar asked Mar 04 '11 15:03

sdg


1 Answers

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 =\

like image 115
Inverse Avatar answered Oct 11 '22 14:10

Inverse