Utilities.py 文件源码

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

项目:BayesVP 作者: cameronliang 项目源码 文件源码
def estimate_bayes_factor(traces, logp, r=0.05):
    """
    Esitmate Odds ratios in a random subsample of the chains in MCMC
    AstroML (see Eqn 5.127, pg 237)
    """

    ndim, nsteps = traces.shape # [ndim,number of steps in chain]

    # compute volume of a n-dimensional (ndim) sphere of radius r
    Vr = np.pi ** (0.5 * ndim) / gamma(0.5 * ndim + 1) * (r ** ndim)

    # use neighbor count within r as a density estimator
    bt = BallTree(traces.T)
    count = bt.query_radius(traces.T, r=r, count_only=True)

    # BF = N*p/rho
    bf = logp + np.log(nsteps) + np.log(Vr) - np.log(count) #log10(bf)

    p25, p50, p75 = np.percentile(bf, [25, 50, 75])
    return p50, 0.7413 * (p75 - p25)

########################################################################
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号