我正在查看 boost::accumulator 框架,特别是一些 rolling_window 计算。
#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);
正如您在此处看到的,我已将 window_size 设置为 3,以便它仅保持最后三个样本的平均值。
我能否在运行时修改该大小,也许是基于用户设置?
如果是这样,并且我增加了 window_size,如果累加器已经看到超过我的新 window_size,它是否有额外的内部状态,或者我是否必须等待额外的值?
最佳答案
重置 boost 累加器的最佳方法是将其分配给一个新累加器。例如:
typedef accumulator_set<int, ... template crazyness tags ... > window_acc;
window_acc acc;
acc(1);
acc(2);
...
// reset
acc = window_acc();
实际上,这里首选 swap,但是 accumulator_set 没有 swap 成员 =\
关于c++ - 使用 boost::accumulators,如何重置滚动窗口大小,它是否保留额外的历史记录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5195990/