This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Moving Average

Tags: None
(comma "," separated)
pbarny
Registered Member
Posts
3
Karma
0

Moving Average

Thu Nov 14, 2013 3:23 pm
I am trying to find an elegant way to calculate a moving average. Until now I have implemented it using the usual way with loops using std::vector, but since I have to use Eigen for some other calculations I thought that it would be a good idea to use Eigen through out the program. Since I am new to Eigen it would be great to get some pointers to what ways a moving average could be implemented taking advantage of Eigen's features. Any ideas?
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS

Re: Moving Average

Thu Nov 14, 2013 3:47 pm
Your question is too vague. What is the dimensionality? Regular sampling? What about the weighting scheme? etc. Anyway, I think you will still need the main outer loop. The inner one is basically a dot product.
pbarny
Registered Member
Posts
3
Karma
0

Re: Moving Average

Thu Nov 14, 2013 5:49 pm
OK, I am looking for the most simple - the moving mean. I have looked into using
Code: Select all
vector.segment(i,n);
but can't figure out how to get the sum and divide by length of the moving mean. Hope this helps.
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS

Re: Moving Average  Topic is solved

Thu Nov 14, 2013 11:05 pm
something like that:

for(i...)
res(i) = vector.segment(i,n).mean();

?
pbarny
Registered Member
Posts
3
Karma
0

Re: Moving Average

Fri Nov 15, 2013 10:15 am
Exactly! Works great.


Bookmarks



Who is online

Registered users: Bing [Bot], Google [Bot], Yahoo [Bot]