Untitled

mail@pastecode.io avatar
unknown
plain_text
2 months ago
861 B
2
Indexable
Never
def modified_kz_filter(original_series, p, k):
    
    # length of the window of KZ filter (m=2k+1)
    m = 2 * k + 1
    
    
    # Performing p iterations
    for iter in range(p):
        filtered_series = [0] * len(original_series)
        # k-1 for the head part
        for i in range(k):
            filtered_series[i] = np.sum(original_series[:2*i ]) / (2 * i + 1)

        # k to length(X)-k-1 for the middle part
        for i in range(k, len(original_series) - k):
            filtered_series[i] = np.sum(original_series[i - k:i + k + 1]) / m

        # length(X)-k to length(X)-1 for the tail part
        for i in range(len(original_series) - k , len(original_series)):
            filtered_series[i] = np.sum(original_series[i - (len(original_series) - i):len(original_series)]) / (2 * (len(original_series) - i) + 1)

    return filtered_series
Leave a Comment