Reihaneh Kouhi
Reihaneh Kouhi

Reputation: 559

How does the convolution filter work in StatsModels seasonal.seasonal_decompose?

I am using seasonal.seasonal_decompose, for 1D array time series with length N. I am searching for seasonality with time period 2l.

Now my question is how does convolution filter work in this code? Does it make a matrix with of 2l*(N/2l) dimension and then work with that network? Which type of convolution filter does it use? CNN?

I want to know the story of the mathematics behind the convolution filter used in this code.

Upvotes: 1

Views: 955

Answers (1)

Konstantin Z
Konstantin Z

Reputation: 190

It uses scipy convolve filter. here is the seasonal_decompose source code extract:

def seasonal_decompose(x, model="additive", filt=None, period=None, two_sided=True,)
...
    if filt is None:
    if period % 2 == 0:  # split weights at ends
        filt = np.array([0.5] + [1] * (period - 1) + [0.5]) / period
    else:
        filt = np.repeat(1.0 / period, period)

    nsides = int(two_sided) + 1
    trend = convolution_filter(x, filt, nsides)
...
from scipy import signal
def convolution_filter(x, filt, nsides=2):
    ...
    result = signal.convolve(x, filt, mode='valid')
    ...
    return PandasWrapper.wrap(result)

where convolution filter is basically a wrapper of scipy.signal.convolve function. As I understood from scipy.signal.convolve source code it uses either direct convolve of fft convolve transform. To learn more about convolution, proceed to this wiki article

Short summary from wiki:

Convolution is defined as the integral of the product of the two functions after one is reversed and shifted

and here the second function (filt) is constant by default.

Upvotes: 1

Related Questions