[SciPy-User] scikits.timeseries: cmov_average() strange result for dtype int
Georges Schutz
georges.schutz@internet...
Thu Apr 15 11:07:55 CDT 2010
Hello all
first thank you all for your great work and the really useful scikits
extensions.
While analysing the behaviour of the lib.moving_funcs of
scikits.timeseries I encountered a strange but explainable behaviour
using the cmov_average() method in the case of integer data.
cmov_average() should do a "centralized" moving average on a
time-series. This seams also OK for float data but in the case of
integer data the behaviour is not as one could expect form numerical
point of view.
Here two examples to illustrate what I mean:
1) TS = [-- 4 4 4 0 0 0 --]
as Integer: cmov_average(TS,3) -> [-- 4 4 2 1 0 0 --]
as float: cmov_average(TS,3) -> [-- 4.0 4.0 2.667 1.333 0.0 0.0 --]
I would have expected form the signal / numerical point of view for the
integer result -> [-- 4 4 3 1 0 0 --] which is symmetric like the
original signal.
2) TS = [-- 1 1 1 0 0 0 --]
as Integer: cmov_average(TS,3) -> [-- 1 1 0 0 0 0 --]
as float: cmov_average(TS,3) -> [-- 1.0 1.0 0.667 0.333 0.0 0.0 --]
My expectation would have been -> [-- 1 1 1 0 0 0 --]
In this case the central moving average is simply shifting the step to
the left by one timestamp.
The reason of this behaviour is the floor rounding done by default if
using integer division. If the round() method where used the result
where as I would have expected.
Is there a possibility to change this default behaviour knowing that the
functions cmov_average() and others are implemented in C.
Best Regards
Georges Schutz
--- Here the used code ---
import numpy as np
import scikits.timeseries as ts
from scikits.timeseries.lib.moving_funcs import cmov_average
ISeries = ts.time_series(np.array([3]*4+[0]*4), #Change 3 to 1 for ex. 2
start_date=ts.Date(freq='D',
string='2010-01-01'),
dtype=int)
FSeries = ts.time_series(ISeries, dtype=float)
print cmov_average(ISeries, 3)
print cmov_average(FSeries, 3)
More information about the SciPy-User
mailing list