Esempio n. 1
0
def test_corner():
    # fails because lag < 1
    with pytest.raises(ValueError):
        diff(x=x, lag=0)
    with pytest.raises(ValueError):
        diff_inv(x=x, lag=0)

    # fails because differences < 1
    with pytest.raises(ValueError):
        diff(x=x, differences=0)
    with pytest.raises(ValueError):
        diff_inv(x=x, differences=0)

    # Passing in xi with the incorrect shape to a 2-d array
    with pytest.raises(IndexError):
        diff_inv(x=np.array([[1, 1], [1, 1]]), xi=np.array([[1]]))
Esempio n. 2
0
def test_diff():
    # test vector for lag = (1, 2), diff = (1, 2)
    assert_array_equal(diff(x, lag=1, differences=1), np.ones(4))
    assert_array_equal(diff(x, lag=1, differences=2), np.zeros(3))
    assert_array_equal(diff(x, lag=2, differences=1), np.ones(3) * 2)
    assert_array_equal(diff(x, lag=2, differences=2), np.zeros(1))

    # test matrix for lag = (1, 2), diff = (1, 2)
    assert_array_equal(diff(m, lag=1, differences=1),
                       np.array([[-5, -5, -2], [7, -15, 12]]))
    assert_array_equal(diff(m, lag=1, differences=2),
                       np.array([[12, -10, 14]]))
    assert_array_equal(diff(m, lag=2, differences=1), np.array([[2, -20, 10]]))
    assert diff(m, lag=2, differences=2).shape[0] == 0
Esempio n. 3
0
def test_adf_ols():
    # Test the _ols function of the ADF test
    x = np.array([1, -1, 0, 2, -1, -2, 3])
    k = 2
    y = diff(x)
    assert_array_equal(y, [-2, 1, 2, -3, -1, 5])

    z = ADFTest._embed(y, k).T
    res = ADFTest._ols(x, y, z, k)

    # Assert on the params of the OLS. The comparisons are those obtained
    # from the R function.
    expected = np.array([1.0522, -3.1825, -0.1609, 1.4690])
    assert np.allclose(res.params, expected, rtol=0.001)

    # Now assert on the standard error
    stat = ADFTest._ols_std_error(res)
    assert np.allclose(stat, -100.2895)  # derived from R code
def test_corner():
    # fails because lag < 1
    with pytest.raises(ValueError):
        diff(x=x, lag=0)
Esempio n. 5
0
In this example, we demonstrate pyramid's array differencing, and how it's used
in conjunction with the ``d`` term to lag a time series.

.. raw:: html

   <br/>
"""
print(__doc__)

# Author: Taylor Smith <*****@*****.**>

from pmdarima.utils import array

# Build an array and show first order differencing results
x = array.c(10, 4, 2, 9, 34)
lag_1 = array.diff(x, lag=1, differences=1)

# The result will be the same as: x[1:] - x[:-1]
print(lag_1)  # [-6., -2., 7., 25.]

# Note that lag and differences are not the same! If we crank diff up by one,
# it performs the same differencing as above TWICE. Lag, therefore, controls
# the number of steps backward the ts looks when it differences, and the
# `differences` parameter controls how many times to repeat.
print(array.diff(x, lag=1, differences=2))  # [4., 9., 18.]

# Conversely, when we set lag to 2, the array looks two steps back for its
# differencing operation (only one).
print(array.diff(x, lag=2, differences=1))  # [-8., 5., 32.]

# The lag parameter is controlled by `m`, which is the seasonal periodicity of