【问题标题】:Using boost::accumulators, how can I reset a rolling window size, does it keep extra history?使用 boost::accumulators,我如何重置滚动窗口大小,它会保留额外的历史记录吗?
【发布时间】:2011-07-08 22:25:57
【问题描述】:

我正在研究 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 更多的值,它是否有额外的内部状态,还是我必须等待额外的值?

【问题讨论】:

    标签: c++ boost


    【解决方案1】:

    重置升压累加器的最佳方法是将其分配给新的。例如:

    typedef accumulator_set<int, ... template crazyness tags ... > window_acc;
    
    window_acc acc;
    acc(1);
    acc(2);
    ...
    // reset
    acc = window_acc();
    

    其实这里首选swap,但是accumulator_set没有swap成员=\

    【讨论】:

    • 这将有效地重新开始,是的;这样我需要重新积累数据?我可以以某种方式保留数据并覆盖新的计算吗?
    • @sdg:啊,我明白了。我不这么认为:\您必须手动处理累加器的内部结构。我建议在这里滚动你自己的滚动平均值,使用循环缓冲区或双端队列来获得你想要的。
    • 如果有像STL容器这样清晰的功能就好了。
    猜你喜欢
    • 1970-01-01
    • 2011-02-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多