diagnostics.py 文件源码

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

项目:zhusuan 作者: thu-ml 项目源码 文件源码
def effective_sample_size(samples, burn_in=100):
    """
    Compute the effective sample size of a chain of vector samples, using the
    algorithm in Stan. Users should flatten their samples as vectors if not so.

    :param samples: A 2-D numpy array of shape ``(M, D)``, where ``M`` is the
        number of samples, and ``D`` is the number of dimensions of each
        sample.
    :param burn_in: The number of discarded samples.

    :return: A 1-D numpy array. The effective sample size.
    """
    current_ess = np.inf
    esses = []
    for d in range(samples.shape[1]):
        ess = effective_sample_size_1d(np.squeeze(samples[burn_in:, d]))
        assert ess >= 0
        if ess > 0:
            current_ess = min(current_ess, ess)

        esses.append(ess)
    return current_ess
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号