计算滚动/用C均线++ [英] Calculate rolling / moving average in C++

查看:161
本文介绍了计算滚动/用C均线++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这是可以实现与升压按:

I know this is achievable with boost as per:

<一个href=\"http://stackoverflow.com/questions/5195990/using-boostaccumulators-how-can-i-reset-a-rolling-window-size-does-it-keep-e\">Using提高::蓄电池,我怎么能重置滚动窗口的大小,它保持额外的历史?

但我真的想避免使用boost。我用Google搜索,并没有发现任何合适的或可读的例子。

But I really would like to avoid using boost. I have googled and not found any suitable or readable examples.

基本上我想跟踪浮动使用最新的1000个号码作为数据采样点数字流的持续流的移动平均线。

Basically I want to track the moving average of an ongoing stream of a stream of floating point numbers using the most recent 1000 numbers as a data sample.

什么是实现这一目标的最简单的方法?

What is the easiest way to achieve this?

我尝试使用一个圆形阵列,指数移动平均线和更简单的移动平均线,发现从圆形排列的结果适合我的需要最好的。

I experimented with using a circular array, exponential moving average and a more simple moving average and found that the results from the circular array suited my needs best.

推荐答案

您只需要1000元,在这里你的元素添加到previous元素,并将其存储的圆形阵列...它成为越来越总和,在这里你总是可以得到的总和任意两个元素对之间,以及它们之间的元素数量划分,以产生平均水平。

You simply need a circular array 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.

这篇关于计算滚动/用C均线++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆