def test_poles_independent_of_ma(self): p = 5 rng = default_rng(5) a = rng.normal(size=p) arma1 = Arma(a, rng.normal(size=3)) arma2 = Arma(a, rng.normal(size=5)) poles1 = arma1.calculate_poles() poles2 = arma2.calculate_poles() np.testing.assert_allclose(poles1, poles2)
def test_ar1(self): a = [0.7] ar1 = Arma(a, []) poles = ar1.calculate_poles() self.assertEqual(len(poles), 1) self.assertAlmostEqual(poles[0], a[0])
def test_number_of_poles_matches_ar_order(self): p = 6 rng = default_rng(4) ar = Arma(rng.normal(size=p), []) poles = ar.calculate_poles() self.assertEqual(len(poles), p)
def test_ar2(self): a = [0.5, -0.7] ar2 = Arma(a, []) poles = ar2.calculate_poles() self.assertEqual(len(poles), 2) pole_prod = np.prod(poles) pole_sum = np.sum(poles) np.testing.assert_allclose(pole_sum, a[0], atol=1e-8) np.testing.assert_allclose(pole_prod, -a[1], atol=1e-8)
def test_product_of_monomials_based_on_poles_recovers_ar_coeffs(self): p = 5 q = 3 rng = default_rng(2) arma = Arma(rng.normal(size=p), rng.normal(size=q)) poles = arma.calculate_poles() coeffs = np.polynomial.polynomial.polyfromroots(poles) # make sure the coefficients are real, up to tolerance self.assertLess(np.max(np.abs(np.imag(coeffs))), 1e-6) # ensure that the coefficients are ordered in the proper way coeffs = np.flip(coeffs.real) np.testing.assert_allclose(coeffs[1:], -arma.a)