Calculate rolling / moving average in C++

前端 未结 10 2082
攒了一身酷
攒了一身酷 2020-12-02 08:09

I know this is achievable with boost as per:

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

But I really would

10条回答
  •  不思量自难忘°
    2020-12-02 08:51

    You simply need a circular array (circular buffer) of 1000 elements, where you add the element to the previous element and store it.

    It becomes an increasing sum, where you can always get the sum between any two pairs of elements, and divide by the number of elements between them, to yield the average.

提交回复
热议问题