x_analytical_values.py 文件源码

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

项目:adversarial-variational-bayes 作者: gdikov 项目源码 文件源码
def analytical_value_i_shannon(distr, par):
    """ Analytical value of mutual information for the given distribution.

    Parameters
    ----------    
    distr : str
            Name of the distribution.
    par : dictionary
          Parameters of the distribution. If distr = 'normal': par["ds"], 
          par["cov"] are the vector of component dimensions and the (joint) 
          covariance matrix. 

    Returns
    -------
    i : float
        Analytical value of the Shannon mutual information.

    """

    if distr == 'normal':
        c, ds = par["cov"], par["ds"]
        # 0,d_1,d_1+d_2,...,d_1+...+d_{M-1}; starting indices of the
        # subspaces:
        cum_ds = cumsum(hstack((0, ds[:-1])))
        i = 1
        for m in range(len(ds)):
            idx = range(cum_ds[m], cum_ds[m] + ds[m])
            i *= det(c[ix_(idx, idx)])

        i = log(i / det(c)) / 2     
    else:
        raise Exception('Distribution=?')

    return i
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号