当前位置: 首页>>代码示例>>Python>>正文


Python tensorflow.cholesky_solve方法代码示例

本文整理汇总了Python中tensorflow.cholesky_solve方法的典型用法代码示例。如果您正苦于以下问题:Python tensorflow.cholesky_solve方法的具体用法?Python tensorflow.cholesky_solve怎么用?Python tensorflow.cholesky_solve使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tensorflow的用法示例。


在下文中一共展示了tensorflow.cholesky_solve方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: build_backward_variance

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import cholesky_solve [as 别名]
def build_backward_variance(self, Yvar):
        """
        Additional method for scaling variance backward (used in :class:`.Normalizer`). Can process both the diagonal
        variances returned by predict_f, as well as full covariance matrices.

        :param Yvar: size N x N x P or size N x P
        :return: Yvar scaled, same rank and size as input
        """
        rank = tf.rank(Yvar)
        # Because TensorFlow evaluates both fn1 and fn2, the transpose can't be in the same line. If a full cov
        # matrix is provided fn1 turns it into a rank 4, then tries to transpose it as a rank 3.
        # Splitting it in two steps however works fine.
        Yvar = tf.cond(tf.equal(rank, 2), lambda: tf.matrix_diag(tf.transpose(Yvar)), lambda: Yvar)
        Yvar = tf.cond(tf.equal(rank, 2), lambda: tf.transpose(Yvar, perm=[1, 2, 0]), lambda: Yvar)

        N = tf.shape(Yvar)[0]
        D = tf.shape(Yvar)[2]
        L = tf.cholesky(tf.square(tf.transpose(self.A)))
        Yvar = tf.reshape(Yvar, [N * N, D])
        scaled_var = tf.reshape(tf.transpose(tf.cholesky_solve(L, tf.transpose(Yvar))), [N, N, D])
        return tf.cond(tf.equal(rank, 2), lambda: tf.reduce_sum(scaled_var, axis=1), lambda: scaled_var) 
开发者ID:GPflow,项目名称:GPflowOpt,代码行数:23,代码来源:transforms.py

示例2: build_backward

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import cholesky_solve [as 别名]
def build_backward(self, Y):
        """
        TensorFlow implementation of the inverse mapping
        """
        L = tf.cholesky(tf.transpose(self.A))
        XT = tf.cholesky_solve(L, tf.transpose(Y-self.b))
        return tf.transpose(XT) 
开发者ID:GPflow,项目名称:GPflowOpt,代码行数:9,代码来源:transforms.py

示例3: test_works_with_five_different_random_pos_def_matrices

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import cholesky_solve [as 别名]
def test_works_with_five_different_random_pos_def_matrices(self):
    with self.test_session():
      for n in range(1, 6):
        for np_type, atol in [(np.float32, 0.05), (np.float64, 1e-5)]:
          # Create 2 x n x n matrix
          array = np.array(
              [_random_pd_matrix(n, self.rng), _random_pd_matrix(n, self.rng)]
          ).astype(np_type)
          chol = tf.cholesky(array)
          for k in range(1, 3):
            rhs = self.rng.randn(2, n, k).astype(np_type)
            x = tf.cholesky_solve(chol, rhs)
            self.assertAllClose(
                rhs, tf.batch_matmul(array, x).eval(), atol=atol) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:16,代码来源:linalg_ops_test.py

示例4: KL

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import cholesky_solve [as 别名]
def KL(self):
        """
        The KL divergence from the variational distribution to the prior

        :return: KL divergence from N(q_mu, q_sqrt) to N(0, I), independently for each GP
        """
        # if self.white:
        #     return gauss_kl(self.q_mu, self.q_sqrt)
        # else:
        #     return gauss_kl(self.q_mu, self.q_sqrt, self.Ku)

        self.build_cholesky_if_needed()

        KL = -0.5 * self.num_outputs * self.num_inducing
        KL -= 0.5 * tf.reduce_sum(tf.log(tf.matrix_diag_part(self.q_sqrt) ** 2))

        if not self.white:
            KL += tf.reduce_sum(tf.log(tf.matrix_diag_part(self.Lu))) * self.num_outputs
            KL += 0.5 * tf.reduce_sum(tf.square(tf.matrix_triangular_solve(self.Lu_tiled, self.q_sqrt, lower=True)))
            Kinv_m = tf.cholesky_solve(self.Lu, self.q_mu)
            KL += 0.5 * tf.reduce_sum(self.q_mu * Kinv_m)
        else:
            KL += 0.5 * tf.reduce_sum(tf.square(self.q_sqrt))
            KL += 0.5 * tf.reduce_sum(self.q_mu**2)

        return KL 
开发者ID:ICL-SML,项目名称:Doubly-Stochastic-DGP,代码行数:28,代码来源:layers.py


注:本文中的tensorflow.cholesky_solve方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。