Monday, 19 August 2013

Query exponentially weighted moving average

Query exponentially weighted moving average

I would like to query the value of an exponentially weighted moving
average at particular points. An inefficient way to do this is as follows.
l is the list of times of events and queries has the times at which I want
the value of this average.
a=0.01
l = [3.0,7.0,10.0,20.0,200.0]
y = [0]*1000
for item in l:
y[int(item)]=1
s = [0]*1000
for i in xrange(1000):
s[i] = a*y[i-1]+(1-a)*s[i-1]
queries = [23,68,103]
for q in queries:
print s[q]
In practice l will be very large and the range of values in l will also be
huge. How can you find the values at the times in queries more
efficiently, and especially without computing the potentially huge lists y
and s explicitly. I need it to be in pure python so I can use pypy.

No comments:

Post a Comment