2015-09-25 206 views
0

我正在寻找一个基于Python的Kolmogorov-Zurbenko过滤器,它接收一个时间序列输入,并根据窗口大小和迭代次数对其进行过滤,但没有发现任何似乎可行的东西。有没有人比我有更好的运气?Python/Scipy Kolmogorov-Zurbenko过滤器?

谢谢!

回答

1

我刚刚查看了相同的问题。实际KZ过滤器是大熊猫很容易:

import pandas as pd 
def kz(series, window, iterations): 
    """KZ filter implementation 
    series is a pandas series 
    window is the filter window m in the units of the data (m = 2q+1) 
    iterations is the number of times the moving average is evaluated 
    """ 
    z = series.copy() 
    for i in range(iterations): 
     z = pd.rolling_mean(z, window=window, min_periods=1, center=True) 
    return z 

什么不能轻易实现的,据我所知是Kologorov Zurbenko过滤器(KZA)的自适应版本。这至少需要一个rolling_mean方法,该方法允许在中心的左侧和右侧指定不同的窗口长度。在https://cran.r-project.org/web/packages/kza/index.html的C代码看起来相当简单直接,但它需要循环,因此如果直接在Python中实现,会很慢。