x_analytical_values.py 文件源码

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

项目:adversarial-variational-bayes 作者: gdikov 项目源码 文件源码
def analytical_value_k_expected(distr1, distr2, sigma, par1, par2):
    """ Analytical value of expected kernel for the given distributions.

    Parameters
    ----------    
    distr1, distr2 : str
                     Names of the distributions.
    sigma: float, >0
           Std parameter of the expected kernel.
    par1, par2 : dictionary-s
                 Parameters of the distributions. If distr1 = distr2 = 
                 'normal': par1["mean"], par1["cov"] and par2["mean"], 
                 par2["cov"] are the means and the covariance matrices.

    Returns
    -------
    k : float
        Analytical value of the expected kernel.

    References
    ----------
    Krikamol Muandet, Kenji Fukumizu, Francesco Dinuzzo, and Bernhard 
    Scholkopf. Learning from distributions via support measure machines.
    In Advances in Neural Information Processing Systems (NIPS), pages
    10-18, 2011.

    """

    if distr1 == 'normal' and distr2 == 'normal':

        # covariance matrices, expectations:
        c1, m1 = par1['cov'], par1['mean']
        c2, m2 = par2['cov'], par2['mean']
        dim = len(m1)

        gam = 1 / sigma**2
        diffm = m1 - m2 
        exp_arg = dot(dot(diffm, inv(c1 + c2 + eye(dim) / gam)), diffm)
        k = exp(-exp_arg / 2) / \
            sqrt(absolute(det(gam * c1 + gam * c2 + eye(dim))))
    else:
        raise Exception('Distribution=?')

    return k
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号