def test_indicators(self, dimensions, indicator):
        """
        Test if indicator matrix is built correctly.
        """
        dct = {
            'intercept':
            [indicator[j] == dimensions[j] for j in range(len(dimensions))]
        }

        y = np.random.randn(np.prod(dimensions))
        model = LME(dimensions, 0, y, {}, dct, {}, False, {})
        Z = rutils.kronecker(indicator, dimensions, 0)
        x = np.random.randn(np.prod(indicator))

        assert (np.linalg.norm(model.X(x) - Z.dot(x)) < 1e-10) and \
            (np.linalg.norm(model.XT(y) - np.transpose(Z).dot(y)) < 1e-10)
 def test_repeat_covariate(self, dimensions, cov_dim):
     N = np.prod(dimensions)
     X = np.ones((N, 2))  # 1st column is intercept
     cov = np.random.randn(np.prod(cov_dim))
     cov_dim_bool = [
         cov_dim[i] == dimensions[i] for i in range(len(dimensions))
     ]
     Z = rutils.kronecker(cov_dim, dimensions, 0)
     X[:, 1] = Z.dot(cov)
     beta_true = [1., -0.6]  # beta_0 for intercept
     Y = X.dot(beta_true)
     model = LME(dimensions, 0, Y, {'cov1': (cov, cov_dim_bool)}, {},
                 {'cov1': [-float('inf'), float('inf')]}, True, {})
     beta = np.random.randn(2)
     assert np.linalg.norm(model.X(beta) - X.dot(beta)) < 1e-10
     y = np.random.randn(N)
     assert np.linalg.norm(model.XT(y) - np.transpose(X).dot(y)) < 1e-10
     model._buildX()
     assert np.linalg.norm(model.Xm - X) < 1e-10