densities.py 文件源码

python
阅读 30 收藏 0 点赞 0 评论 0

项目:GPflow 作者: GPflow 项目源码 文件源码
def multivariate_normal(x, mu, L):
    """
    L is the Cholesky decomposition of the covariance.

    x and mu are either vectors (ndim=1) or matrices. In the matrix case, we
    assume independence over the *columns*: the number of rows must match the
    size of L.
    """
    d = x - mu
    alpha = tf.matrix_triangular_solve(L, d, lower=True)
    num_col = 1 if tf.rank(x) == 1 else tf.shape(x)[1]
    num_col = tf.cast(num_col, settings.float_type)
    num_dims = tf.cast(tf.shape(x)[0], settings.float_type)
    ret = - 0.5 * num_dims * num_col * np.log(2 * np.pi)
    ret += - num_col * tf.reduce_sum(tf.log(tf.matrix_diag_part(L)))
    ret += - 0.5 * tf.reduce_sum(tf.square(alpha))
    return ret
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号