Esempio n. 1
0
 def _create_case(self, p=2, T=300):
     n = 4
     X = np.random.normal(size=(T, n))
     X[1:] = X[:-1] + 0.5 * np.random.normal(size=(T - 1, n))
     X[2:, 0] = X[:-2, -1] + 0.5 * np.random.normal(size=T - 2)
     X[1:, 1] = X[:-1, 3] + 0.5 * np.random.normal(size=T - 1)
     R = compute_covariance(X, p_max=p)
     return R, X
Esempio n. 2
0
    def test_cost_gradient001(self):
        p = 4
        T = 1000
        n = 2
        X = np.random.normal(size=(T, n))
        X[1:] = X[:-1] + 0.5 * np.random.normal(size=(T - 1, n))
        R = compute_covariance(X, p_max=p)

        A, _, _ = whittle_lev_durb(R)
        B_hat = A_to_B(A)
        g = cost_gradient(B_hat, R)
        np.testing.assert_almost_equal(g, np.zeros_like(g))
        return
Esempio n. 3
0
    def test_cost_function001(self):
        n = 2
        p = 2
        T = 200

        for _ in range(10):
            X = np.random.normal(size=(T, n))
            X[1:] = X[:-1] + 0.5 * np.random.normal(size=(T - 1, n))
            R = compute_covariance(X, p_max=p)
            A, _, _ = whittle_lev_durb(R)
            B = A_to_B(A)

            cost0 = cost_function(B, R)
            cost = cost_function(B, R, lmbda=0.5)
            self.assertAlmostEqual(cost, cost0 + 0.5 * np.sum(np.abs(B)))
        return
Esempio n. 4
0
    def test_cost_function000(self):
        n = 2
        p = 2
        T = 200

        for _ in range(10):
            X = np.random.normal(size=(T, n))
            X[1:] = X[:-1] + 0.5 * np.random.normal(size=(T - 1, n))
            R = compute_covariance(X, p_max=p)
            A, _, _ = whittle_lev_durb(R)
            B = A_to_B(A)

            cost_opt = cost_function(B, R)
            cost_larger = cost_function(B + 1e-3 * np.random.normal(size=B.shape), R)
            self.assertGreater(cost_larger, cost_opt)
        return
Esempio n. 5
0
    def _create_big_case(self, p=5, T=500):
        n = 30
        X = np.random.normal(size=(T, n))
        X[1:] = X[:-1] + 0.5 * np.random.normal(size=(T - 1, n))
        X[2:, 0] = X[:-2, -1] + 0.5 * np.random.normal(size=T - 2)
        X[1:, 1] = X[:-1, 3] + 0.5 * np.random.normal(size=T - 1)

        L = np.random.normal(size=(n, n))

        L[2, :] = 0
        L[12, :] = 0
        L[9, :] = 0

        X[2:] = X[:-2] @ L

        R = compute_covariance(X, p_max=p)
        return R, X
Esempio n. 6
0
 def _create_case(self, p=1, T=300):
     n = 2
     X = np.random.normal(size=(T, n))
     X[1:] = X[:-1] + 0.5 * np.random.normal(size=(T - 1, n))
     R = compute_covariance(X, p_max=p)
     return R, X