def test_stable(self): var = VAR(1) # Stable AR model -- rule of thumb: sum(coefs) < 1 var.coef = np.asarray([[0.5, 0.3]]) self.assertTrue(var.is_stable()) # Unstable AR model -- rule of thumb: sum(coefs) > 1 var.coef = np.asarray([[0.5, 0.7]]) self.assertFalse(var.is_stable())
def generate_data(self, cc=((1, 0), (0, 1))): 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, lambda: np.random.randn(2).dot(cc)) self.assertEqual(x.shape, (l[1], 2, l[0])) return x, var
def test_simulate(self): noisefunc = lambda: [1, 1] # use deterministic function instead of noise num_samples = 100 b = np.array([[0.2, 0.1, 0.4, -0.1], [0.3, -0.2, 0.1, 0]]) var = VAR(2) var.coef = b np.random.seed(42) x = var.simulate(num_samples, noisefunc) # make sure we got expected values within reasonable accuracy for n in range(10, num_samples): self.assertTrue(np.all( np.abs(x[n, :] - 1 - np.dot(b[:, 0::2], x[n - 1, :]) - np.dot(b[:, 1::2], x[n - 2, :])) < 1e-10))
def test_simulate(self): noisefunc = lambda: [1, 1 ] # use deterministic function instead of noise num_samples = 100 b = np.array([[0.2, 0.1, 0.4, -0.1], [0.3, -0.2, 0.1, 0]]) var = VAR(2) var.coef = b np.random.seed(42) x = var.simulate(num_samples, noisefunc) # make sure we got expected values within reasonable accuracy for n in range(10, num_samples): self.assertTrue( np.all( np.abs(x[n, :] - 1 - np.dot(b[:, 0::2], x[n - 1, :]) - np.dot(b[:, 1::2], x[n - 2, :])) < 1e-10))
def generate_data(self, cc=((1, 0), (0, 1))): 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, lambda: np.random.randn(2).dot(cc)) return x, var