Exemple #1
0
    def test_residuals(self):
        np.random.seed(31415)
        x, var0 = self.generate_data()

        var = VAR(2)
        var.fit(x)

        self.assertEqual(x.shape, var.residuals.shape)
        self.assertTrue(np.allclose(var.rescov, np.eye(var.rescov.shape[0]), 0.005, 0.005))
Exemple #2
0
    def test_fit(self):
        np.random.seed(12345)
        x, var0 = self.generate_data()
        y = x.copy()

        var = VAR(2)
        var.fit(x)

        # make sure the input remains unchanged
        self.assertTrue(np.all(x == y))

        self.assertTrue(np.all(np.abs(var0.coef - var.coef) < 0.005))
Exemple #3
0
    def func(self):
        x, var0 = self.generate_data()
        y = x.copy()

        var = VAR(10, o)
        var.fit(x)

        # make sure the input remains unchanged
        self.assertTrue(np.all(x == y))

        b0 = np.zeros((2, 20))
        b0[:, 0:2] = var0.coef[:, 0:2]
        b0[:, 10:12] = var0.coef[:, 2:4]

        # that limit is rather generous, but we don't want tests to fail due to random variation
        self.assertTrue(np.all(np.abs(b0 - var.coef) < 0.02))
Exemple #4
0
 def generate_data(self):
     var = VAR(2)
     var.coef = np.array([[0.2, 0.1, 0.4, -0.1], [0.3, -0.2, 0.1, 0]])
     l = (1000, 100)
     x = var.simulate(l)
     return x, var