Пример #1
0
 def _get_sigma_ls(self):
     """Initialize covariance matrix of var distribution over unary potentials.
 """
     cov = self.cov
     inputs_dists = self.inputs_dists
     K_mm = cov.kron_cov(inputs_dists)
     return t3f.get_variable('sigma_ls', initializer=kron.cholesky(K_mm))
Пример #2
0
 def _get_sigma_l(self):
   """Initializes latent inputs covariance Sigma_l.
   """
   shapes = self.inputs.npoints
   cov = self.cov
   inputs_dists = self.inputs_dists
   K_mm = cov.kron_cov(inputs_dists)    
   return t3f.get_variable('sigma_l', initializer=kron.cholesky(K_mm))
Пример #3
0
    def testCholesky(self):
        # Tests the cholesky function
        np.random.seed(8)

        # generating two symmetric positive-definite tt-cores
        L_1 = np.tril(np.random.normal(scale=2., size=(2, 2)))
        L_2 = np.tril(np.random.normal(scale=2., size=(3, 3)))
        K_1 = L_1.dot(L_1.T)
        K_2 = L_2.dot(L_2.T)
        K = np.kron(K_1, K_2)
        initializer = TensorTrain(
            [K_1[None, :, :, None], K_2[None, :, :, None]], tt_ranks=7 * [1])
        kron_mat = variables.get_variable('kron_mat', initializer=initializer)
        init_op = tf.global_variables_initializer()
        with self.test_session() as sess:
            sess.run(init_op)
            desired = np.linalg.cholesky(K)
            actual = ops.full(kr.cholesky(kron_mat)).eval()
            self.assertAllClose(desired, actual)
Пример #4
0
    def testCholesky(self):
        # Tests the cholesky function
        np.random.seed(8)

        # generating two symmetric positive-definite tt-cores
        L_1 = np.tril(np.random.normal(scale=2., size=(2, 2)))
        L_1 = L_1.astype(self.dtype.as_numpy_dtype)
        L_2 = np.tril(np.random.normal(scale=2., size=(3, 3)))
        L_2 = L_2.astype(self.dtype.as_numpy_dtype)
        K_1 = L_1.dot(L_1.T)
        K_2 = L_2.dot(L_2.T)
        K = np.kron(K_1, K_2)
        initializer = TensorTrain(
            [K_1[None, :, :, None], K_2[None, :, :, None]], tt_ranks=7 * [1])
        kron_mat = variables.get_variable('kron_mat', initializer=initializer)
        init_op = tf.compat.v1.global_variables_initializer()
        self.evaluate(init_op)
        desired = np.linalg.cholesky(K)
        actual = self.evaluate(ops.full(kr.cholesky(kron_mat)))
        self.assertAllClose(desired, actual, atol=1e-5, rtol=1e-5)
Пример #5
0
    def testCholesky(self):
        # Tests the cholesky function
        np.random.seed(8)

        # generating two symmetric positive-definite tt-cores
        L_1 = np.tril(np.random.normal(scale=2., size=(4, 2, 2)))
        L_2 = np.tril(np.random.normal(scale=2., size=(4, 3, 3)))
        K_1 = np.einsum('ijk,ilk->ijl', L_1, L_1)
        K_2 = np.einsum('ijk,ilk->ijl', L_2, L_2)
        initializer = TensorTrainBatch(
            [K_1[:, None, :, :, None], K_2[:, None, :, :, None]],
            tt_ranks=7 * [1])
        kron_mat_batch = variables.get_variable('kron_mat_batch',
                                                initializer=initializer)
        init_op = tf.global_variables_initializer()
        with self.test_session() as sess:
            sess.run(init_op)
            desired = np.linalg.cholesky(ops.full(kron_mat_batch).eval())
            actual = ops.full(kr.cholesky(kron_mat_batch)).eval()
            self.assertAllClose(desired, actual)
Пример #6
0
 def _get_sigma_ls(self):
     cov = self.cov
     inputs_dists = self.inputs_dists
     K_mm = cov.kron_cov(inputs_dists)    
     return t3f.get_variable('sigma_ls', initializer=kron.cholesky(K_mm))