コード例 #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_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)
コード例 #3
0
 def test_pandas2d(self):
     start = datetime(1951, 3, 31)
     end = datetime(1958, 12, 31)
     x = concat((self.data[0], self.data[0]), axis=1)
     res = convolution_filter(x, [[.75, .75], [.25, .25]])
     assert_(res.index[0] == start)
     assert_(res.index[-1] == end)
コード例 #4
0
 def test_pandas2d(self):
     start = datetime(1951, 3, 31)
     end = datetime(1958, 12, 31)
     x = concat((self.data[0], self.data[0]), axis=1)
     res = convolution_filter(x, [[.75, .75], [.25, .25]])
     assert_(res.index[0] == start)
     assert_(res.index[-1] == end)
コード例 #5
0
    def test_convolution(self):
        x = self.data.values.squeeze()
        res = convolution_filter(x, [.75, .25])
        expected = self.expected.conv2
        np.testing.assert_almost_equal(res, expected)

        res = convolution_filter(x, [.75, .25], nsides=1)
        expected = self.expected.conv1
        np.testing.assert_almost_equal(res, expected)

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

        res = convolution_filter(x, [.75, .25], nsides=1)
        expected = self.expected.conv1_na
        np.testing.assert_almost_equal(res, expected)
コード例 #6
0
    def test_convolution(self):
        x = self.data.values.squeeze()
        res = convolution_filter(x, [.75, .25])
        expected = self.expected.conv2
        np.testing.assert_almost_equal(res, expected)

        res = convolution_filter(x, [.75, .25], nsides=1)
        expected = self.expected.conv1
        np.testing.assert_almost_equal(res, expected)

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

        res = convolution_filter(x, [.75, .25], nsides=1)
        expected = self.expected.conv1_na
        np.testing.assert_almost_equal(res, expected)
コード例 #7
0
    def test_convolution2d(self):
        x = self.data.values
        res = convolution_filter(x, [[.75], [.25]])
        expected = self.expected.conv2
        np.testing.assert_almost_equal(res, expected[:, None])
        res = convolution_filter(np.c_[x, x], [[.75, .75], [.25, .25]])
        np.testing.assert_almost_equal(res, np.c_[expected, expected])

        res = convolution_filter(x, [[.75], [.25]], nsides=1)
        expected = self.expected.conv1
        np.testing.assert_almost_equal(res, expected[:, None])

        x = self.datana.values
        res = convolution_filter(x, [[.75], [.25]])
        expected = self.expected.conv2_na
        np.testing.assert_almost_equal(res, expected[:, None])

        res = convolution_filter(x, [[.75], [.25]], nsides=1)
        expected = self.expected.conv1_na
        np.testing.assert_almost_equal(res, expected[:, None])
コード例 #8
0
    def test_convolution2d(self):
        x = self.data.values
        res = convolution_filter(x, [[.75], [.25]])
        expected = self.expected.conv2
        np.testing.assert_almost_equal(res, expected[:, None])
        res = convolution_filter(np.c_[x, x], [[.75, .75], [.25, .25]])
        np.testing.assert_almost_equal(res, np.c_[expected, expected])

        res = convolution_filter(x, [[.75], [.25]], nsides=1)
        expected = self.expected.conv1
        np.testing.assert_almost_equal(res, expected[:, None])

        x = self.datana.values
        res = convolution_filter(x, [[.75], [.25]])
        expected = self.expected.conv2_na
        np.testing.assert_almost_equal(res, expected[:, None])

        res = convolution_filter(x, [[.75], [.25]], nsides=1)
        expected = self.expected.conv1_na
        np.testing.assert_almost_equal(res, expected[:, None])
コード例 #9
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)
コード例 #10
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)