Ejemplo n.º 1
0
    def test_zeros_independent_of_ar(self):
        q = 5
        rng = default_rng(5)
        b = rng.normal(size=q)
        arma1 = Arma(rng.normal(size=3), b)
        arma2 = Arma(rng.normal(size=5), b)

        zeros1 = arma1.calculate_zeros()
        zeros2 = arma2.calculate_zeros()

        np.testing.assert_allclose(zeros1, zeros2)
Ejemplo n.º 2
0
    def test_ma1(self):
        b = [0.6]
        ma1 = Arma([], b)
        zeros = ma1.calculate_zeros()

        self.assertEqual(len(zeros), 1)
        self.assertAlmostEqual(zeros[0], -b[0])
Ejemplo n.º 3
0
    def test_number_of_zeros_matches_ma_order(self):
        q = 5
        rng = default_rng(3)
        ma = Arma([], rng.normal(size=q))
        zeros = ma.calculate_zeros()

        self.assertEqual(len(zeros), q)
Ejemplo n.º 4
0
    def test_ma2(self):
        b = [-0.5, -0.3]
        ma2 = Arma([], b)
        zeros = ma2.calculate_zeros()

        self.assertEqual(len(zeros), 2)

        zero_prod = np.prod(zeros)
        zero_sum = np.sum(zeros)

        np.testing.assert_allclose(zero_sum, -b[0], atol=1e-8)
        np.testing.assert_allclose(zero_prod, b[1], atol=1e-8)
Ejemplo n.º 5
0
    def test_product_of_monomials_based_on_zeros_recovers_ma_coeffs(self):
        p = 4
        q = 4
        rng = default_rng(2)
        arma = Arma(rng.normal(size=p), rng.normal(size=q))

        zeros = arma.calculate_zeros()
        coeffs = np.polynomial.polynomial.polyfromroots(zeros)

        # 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.b)