Beispiel #1
0
    def test_one_step_predictions(self):
        ma_model = PureARMA(theta=[-0.9], sigma_sq=1)
        ma_data = [-2.58, 1.62, -0.96, 2.62, -1.36]
        ma = ARMA(ma_data, subtract_mean=False)

        self.assertEqual(ma.get_one_step_predictor(0, ma_model), 0)
        self.assertAlmostEqual(ma.get_one_step_predictor(1, ma_model, method="innovations_algo"), 1.28, 2)
        self.assertAlmostEqual(ma.get_one_step_predictor(2, ma_model, method="innovations_algo"), -0.22, 2)
        self.assertAlmostEqual(ma.get_one_step_predictor(3, ma_model, method="innovations_algo"), 0.55, 2)
        self.assertAlmostEqual(ma.get_one_step_predictor(4, ma_model, method="innovations_algo"), -1.63, 2)
        self.assertAlmostEqual(ma.get_one_step_predictor(5, ma_model, method="innovations_algo"), -0.22, 2)

        arma_data = [-1.1, 0.514, 0.116, -0.845, 0.872, -0.467, -0.977, -1.699, -1.228, -1.093]
        arma_model = PureARMA(phi=[0.2], theta=[0.4], sigma_sq=1)
        arma = ARMA(arma_data, subtract_mean=False)

        self.assertEqual(arma.get_one_step_predictor(0, arma_model, method="innovations_algo"), 0)
        self.assertAlmostEqual(arma.get_one_step_predictor(1, arma_model, method="innovations_algo"), -0.534, 1)
        self.assertAlmostEqual(arma.get_one_step_predictor(2, arma_model, method="innovations_algo"), 0.5068, 1)
        self.assertAlmostEqual(arma.get_one_step_predictor(3, arma_model, method="innovations_algo"), -0.1321, 1)
        self.assertAlmostEqual(arma.get_one_step_predictor(4, arma_model, method="innovations_algo"), -0.4539, 1)
        self.assertAlmostEqual(arma.get_one_step_predictor(5, arma_model, method="innovations_algo"), 0.7046, 1)

        data = [1, 2, 3, 4, 5]
        empty_model = PureARMA()
        empty = ARMA(data)
        empty.model = empty_model

        for k in range(6):
            self.assertEqual(empty.get_one_step_predictor(k, method="innovations_algo"), 0)
Beispiel #2
0
    def test_FPE(self):
        short_data = np.zeros(10)
        long_data = np.ones(100000)
        low_var_model = PureARMA(phi=[0.3, 0.2], sigma_sq=0.1)
        high_var_model = PureARMA(phi=[0.1, 0.4, -0.4], sigma_sq=5)
        noise_model = PureARMA(sigma_sq=2)
        short_ts = ARMA(short_data)
        long_ts = ARMA(long_data)
        short_ts.model = low_var_model
        long_ts.model = low_var_model

        self.assertAlmostEqual(short_ts.get_fpe(), 0.1 * 12 / 8)
        self.assertAlmostEqual(short_ts.get_fpe(model=high_var_model), 5 * 13 / 7)
        self.assertAlmostEqual(short_ts.get_fpe(model=noise_model), 2)

        self.assertAlmostEqual(long_ts.get_fpe(), 0.1 * 100002 / 99998)
        self.assertAlmostEqual(long_ts.get_fpe(model=high_var_model), 5 * 100003 / 99997)
        self.assertAlmostEqual(long_ts.get_fpe(model=noise_model), 2)