Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
393 views
in Technique[技术] by (71.8m points)

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

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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 =


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...