def test_predict():
    endog = np.ones(10)
    with pytest.warns(FutureWarning):
        markov_autoregression.MarkovAutoregression(endog, k_regimes=2, order=1, trend='nc')
    mod = markov_autoregression.MarkovAutoregression(endog, k_regimes=2, order=1, trend='n')
    assert_equal(mod.nobs, 9)
    assert_equal(mod.endog, np.ones(9))
    params = np.r_[(0.5, 0.5, 1.0, 0.1, 0.5)]
    mod_resid = mod._resid(params)
    resids = np.zeros((2, 2, mod.nobs))
    resids[0, :, :] = (np.ones(9) - (0.1 * np.ones(9)))
    assert_allclose(mod_resid[0, :, :], resids[0, :, :])
    resids[1, :, :] = (np.ones(9) - (0.5 * np.ones(9)))
    assert_allclose(mod_resid[1, :, :], resids[1, :, :])
    endog = np.arange(10)
    mod = markov_autoregression.MarkovAutoregression(endog, k_regimes=2, order=1)
    assert_equal(mod.nobs, 9)
    assert_equal(mod.endog, np.arange(1, 10))
    params = np.r_[(0.5, 0.5, 2.0, 3.0, 1.0, 0.1, 0.5)]
    mod_resid = mod._resid(params)
    resids = np.zeros((2, 2, mod.nobs))
    resids[0, 0, :] = ((np.arange(1, 10) - 2.0) - (0.1 * (np.arange(9) - 2.0)))
    assert_allclose(mod_resid[0, 0, :], resids[0, 0, :])
    resids[0, 1, :] = ((np.arange(1, 10) - 2.0) - (0.1 * (np.arange(9) - 3.0)))
    assert_allclose(mod_resid[0, 1, :], resids[0, 1, :])
    resids[1, 0, :] = ((np.arange(1, 10) - 3.0) - (0.5 * (np.arange(9) - 2.0)))
    assert_allclose(mod_resid[1, 0, :], resids[1, 0, :])
    resids[1, 1, :] = ((np.arange(1, 10) - 3.0) - (0.5 * (np.arange(9) - 3.0)))
    assert_allclose(mod_resid[1, 1, :], resids[1, 1, :])
    endog = np.arange(10)
    mod = markov_autoregression.MarkovAutoregression(endog, k_regimes=3, order=2)
    assert_equal(mod.nobs, 8)
    assert_equal(mod.endog, np.arange(2, 10))
    params = np.r_[(([0.3] * 6), 2.0, 3.0, 4, 1.0, 0.1, 0.5, 0.8, (- 0.05), (- 0.25), (- 0.4))]
    mod_resid = mod._resid(params)
    resids = np.zeros((3, 3, 3, mod.nobs))
    resids[0, 0, 0, :] = (((np.arange(2, 10) - 2.0) - (0.1 * (np.arange(1, 9) - 2.0))) - ((- 0.05) * (np.arange(8) - 2.0)))
    assert_allclose(mod_resid[0, 0, 0, :], resids[0, 0, 0, :])
    resids[1, 0, 0, :] = (((np.arange(2, 10) - 3.0) - (0.5 * (np.arange(1, 9) - 2.0))) - ((- 0.25) * (np.arange(8) - 2.0)))
    assert_allclose(mod_resid[1, 0, 0, :], resids[1, 0, 0, :])
    resids[0, 2, 1, :] = (((np.arange(2, 10) - 2.0) - (0.1 * (np.arange(1, 9) - 4.0))) - ((- 0.05) * (np.arange(8) - 3.0)))
    assert_allclose(mod_resid[0, 2, 1, :], resids[0, 2, 1, :])
    endog = np.arange(10)
    exog = np.r_[(0.4, 5, 0.2, 1.2, (- 0.3), 2.5, 0.2, (- 0.7), 2.0, (- 1.1))]
    mod = markov_autoregression.MarkovAutoregression(endog, k_regimes=2, order=1, exog=exog)
    assert_equal(mod.nobs, 9)
    assert_equal(mod.endog, np.arange(1, 10))
    params = np.r_[(0.5, 0.5, 2.0, 3.0, 1.5, 1.0, 0.1, 0.5)]
    mod_resid = mod._resid(params)
    resids = np.zeros((2, 2, mod.nobs))
    resids[0, 0, :] = (((np.arange(1, 10) - 2.0) - (1.5 * exog[1:])) - (0.1 * ((np.arange(9) - 2.0) - (1.5 * exog[:(- 1)]))))
    assert_allclose(mod_resid[0, 0, :], resids[0, 0, :])
    resids[0, 1, :] = (((np.arange(1, 10) - 2.0) - (1.5 * exog[1:])) - (0.1 * ((np.arange(9) - 3.0) - (1.5 * exog[:(- 1)]))))
    assert_allclose(mod_resid[0, 1, :], resids[0, 1, :])
    resids[1, 0, :] = (((np.arange(1, 10) - 3.0) - (1.5 * exog[1:])) - (0.5 * ((np.arange(9) - 2.0) - (1.5 * exog[:(- 1)]))))
    assert_allclose(mod_resid[1, 0, :], resids[1, 0, :])
    resids[1, 1, :] = (((np.arange(1, 10) - 3.0) - (1.5 * exog[1:])) - (0.5 * ((np.arange(9) - 3.0) - (1.5 * exog[:(- 1)]))))
    assert_allclose(mod_resid[1, 1, :], resids[1, 1, :])
def test_predict():
    endog = np.ones(10)
    with pytest.warns(FutureWarning):
        markov_autoregression.MarkovAutoregression(endog, k_regimes=2, order=1, trend='nc')
    mod = markov_autoregression.MarkovAutoregression(endog, k_regimes=2, order=1, trend='n')
    assert_equal(mod.nobs, 9)
    assert_equal(mod.endog, np.ones(9))
    params = np.r_[(0.5, 0.5, 1.0, 0.1, 0.5)]
    mod_resid = mod._resid(params)
    resids = np.zeros((2, 2, mod.nobs))
    resids[0, :, :] = (np.ones(9) - (0.1 * np.ones(9)))
    assert_allclose(mod_resid[0, :, :], resids[0, :, :])
    resids[1, :, :] = (np.ones(9) - (0.5 * np.ones(9)))
    assert_allclose(mod_resid[1, :, :], resids[1, :, :])
    endog = np.arange(10)
    mod = markov_autoregression.MarkovAutoregression(endog, k_regimes=2, order=1)
    assert_equal(mod.nobs, 9)
    assert_equal(mod.endog, np.arange(1, 10))
    params = np.r_[(0.5, 0.5, 2.0, 3.0, 1.0, 0.1, 0.5)]
    mod_resid = mod._resid(params)
    resids = np.zeros((2, 2, mod.nobs))
    resids[0, 0, :] = ((np.arange(1, 10) - 2.0) - (0.1 * (np.arange(9) - 2.0)))
    assert_allclose(mod_resid[0, 0, :], resids[0, 0, :])
    resids[0, 1, :] = ((np.arange(1, 10) - 2.0) - (0.1 * (np.arange(9) - 3.0)))
    assert_allclose(mod_resid[0, 1, :], resids[0, 1, :])
    resids[1, 0, :] = ((np.arange(1, 10) - 3.0) - (0.5 * (np.arange(9) - 2.0)))
    assert_allclose(mod_resid[1, 0, :], resids[1, 0, :])
    resids[1, 1, :] = ((np.arange(1, 10) - 3.0) - (0.5 * (np.arange(9) - 3.0)))
    assert_allclose(mod_resid[1, 1, :], resids[1, 1, :])
    endog = np.arange(10)
    mod = markov_autoregression.MarkovAutoregression(endog, k_regimes=3, order=2)
    assert_equal(mod.nobs, 8)
    assert_equal(mod.endog, np.arange(2, 10))
    params = np.r_[(([0.3] * 6), 2.0, 3.0, 4, 1.0, 0.1, 0.5, 0.8, (- 0.05), (- 0.25), (- 0.4))]
    mod_resid = mod._resid(params)
    resids = np.zeros((3, 3, 3, mod.nobs))
    resids[0, 0, 0, :] = (((np.arange(2, 10) - 2.0) - (0.1 * (np.arange(1, 9) - 2.0))) - ((- 0.05) * (np.arange(8) - 2.0)))
    assert_allclose(mod_resid[0, 0, 0, :], resids[0, 0, 0, :])
    resids[1, 0, 0, :] = (((np.arange(2, 10) - 3.0) - (0.5 * (np.arange(1, 9) - 2.0))) - ((- 0.25) * (np.arange(8) - 2.0)))
    assert_allclose(mod_resid[1, 0, 0, :], resids[1, 0, 0, :])
    resids[0, 2, 1, :] = (((np.arange(2, 10) - 2.0) - (0.1 * (np.arange(1, 9) - 4.0))) - ((- 0.05) * (np.arange(8) - 3.0)))
    assert_allclose(mod_resid[0, 2, 1, :], resids[0, 2, 1, :])
    endog = np.arange(10)
    exog = np.r_[(0.4, 5, 0.2, 1.2, (- 0.3), 2.5, 0.2, (- 0.7), 2.0, (- 1.1))]
    mod = markov_autoregression.MarkovAutoregression(endog, k_regimes=2, order=1, exog=exog)
    assert_equal(mod.nobs, 9)
    assert_equal(mod.endog, np.arange(1, 10))
    params = np.r_[(0.5, 0.5, 2.0, 3.0, 1.5, 1.0, 0.1, 0.5)]
    mod_resid = mod._resid(params)
    resids = np.zeros((2, 2, mod.nobs))
    resids[0, 0, :] = (((np.arange(1, 10) - 2.0) - (1.5 * exog[1:])) - (0.1 * ((np.arange(9) - 2.0) - (1.5 * exog[:(- 1)]))))
    assert_allclose(mod_resid[0, 0, :], resids[0, 0, :])
    resids[0, 1, :] = (((np.arange(1, 10) - 2.0) - (1.5 * exog[1:])) - (0.1 * ((np.arange(9) - 3.0) - (1.5 * exog[:(- 1)]))))
    assert_allclose(mod_resid[0, 1, :], resids[0, 1, :])
    resids[1, 0, :] = (((np.arange(1, 10) - 3.0) - (1.5 * exog[1:])) - (0.5 * ((np.arange(9) - 2.0) - (1.5 * exog[:(- 1)]))))
    assert_allclose(mod_resid[1, 0, :], resids[1, 0, :])
    resids[1, 1, :] = (((np.arange(1, 10) - 3.0) - (1.5 * exog[1:])) - (0.5 * ((np.arange(9) - 3.0) - (1.5 * exog[:(- 1)]))))
    assert_allclose(mod_resid[1, 1, :], resids[1, 1, :])