Пример #1
0
    def test_odd_length_filter(self):
        start = datetime(1951, 3, 31)
        end = datetime(1958, 12, 31)
        x = self.data[0]
        res = convolution_filter(x, [.75, .5, .3, .2, .1])
        expected = self.expected.conv2_odd
        np.testing.assert_almost_equal(res.values.squeeze(), expected)
        np.testing.assert_(res.index[0] == start)
        np.testing.assert_(res.index[-1] == end)

        res = convolution_filter(x, [.75, .5, .3, .2, .1], nsides=1)
        expected = self.expected.conv1_odd
        np.testing.assert_almost_equal(res.values.squeeze(), expected)
        np.testing.assert_(res.index[0] == start)
        np.testing.assert_(res.index[-1] == end)
        # with no NAs

        # not a stable filter
        res = recursive_filter(x, [.75, .5, .3, .2, .1], init=[150, 100,
                                                               125, 135,
                                                               145])
        expected = self.expected.recurse_odd
        # only have 12 characters in R and this blows up and gets big
        np.testing.assert_almost_equal(res.values.squeeze(), expected, 4)
        np.testing.assert_(res.index[0] == start)
        np.testing.assert_(res.index[-1] == end)
Пример #2
0
    def test_pandas(self):
        start = datetime(1951, 3, 31)
        end = datetime(1958, 12, 31)
        x = self.data[0]
        res = convolution_filter(x, [.75, .25])
        assert_(res.index[0] == start)
        assert_(res.index[-1] == end)

        res = convolution_filter(x, [.75, .25], nsides=1)
        assert_(res.index[0] == start)
        # with no nan-padding q1 if not
        assert_(res.index[-1] == end)

        res = recursive_filter(x, [.75, .25])
        assert_(res.index[0] == start)
        assert_(res.index[-1] == end)

        x = self.datana
        res = recursive_filter(x, [.75, .25])
        assert_(res.index[0] == start)
        assert_(res.index[-1] == end)
Пример #3
0
    def test_recursive(self):
        x = self.data.values.squeeze()
        res = recursive_filter(x, [.75, .25])
        expected = self.expected.recurse
        np.testing.assert_almost_equal(res, expected)

        res = recursive_filter(x, [.75, .25], init=[150, 100])
        expected = self.expected.recurse_init
        np.testing.assert_almost_equal(res, expected)

        x = self.datana.values.squeeze()
        res = recursive_filter(x, [.75, .25])
        expected = self.expected.recurse_na
        np.testing.assert_almost_equal(res, expected)

        res = recursive_filter(x, [.75, .25], init=[150, 100])
        expected = self.expected.recurse_init_na
        np.testing.assert_almost_equal(res, expected)

        assert_raises(ValueError, recursive_filter, x,
                      [.75, .25, .5], [150, 100])
Пример #4
0
def recursive_filter_function(signal):
    signal = shift_array(signal)
    filter_length = len(filter_freq)
    signal = recursive_filter(signal, filter_freq)[300:]
    return signal
Пример #5
0
def rec_fil(x):
    xtmp = x.iloc[1:301].append(x.iloc[1:])
    ftmp = recursive_filter(xtmp, taps)[300:]
    return ftmp
Пример #6
0
def adstock(x, rate, y):
    y['adstock'] = sm.recursive_filter(x,rate)
    return y