2018-10-03 18:59:01 +00:00
|
|
|
# setup: import numpy as np ; N = 1000 ; a = np.arange(0,1,N)
|
|
|
|
# run: smoothing(a, .4)
|
|
|
|
# from: http://www.parakeetpython.com/
|
|
|
|
|
|
|
|
# pythran export smoothing(float[], float)
|
2018-04-05 22:07:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
def smoothing(x, alpha):
|
2018-10-03 18:59:01 +00:00
|
|
|
"""
|
|
|
|
Exponential smoothing of a time series
|
|
|
|
For x = 10**6 floats
|
|
|
|
- Python runtime: 9 seconds
|
|
|
|
- Parakeet runtime: .01 seconds
|
|
|
|
"""
|
|
|
|
s = x.copy()
|
|
|
|
for i in range(1, len(x)):
|
|
|
|
s[i] = alpha * x[i] + (1 - alpha) * s[i - 1]
|
|
|
|
return s
|