austerity.py 文件源码

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

项目:kernel_goodness_of_fit 作者: karlnapf 项目源码 文件源码
def austerity(log_lik,log_density_prior, X,epsilon,batch_size=30,chain_size=10000, thinning=1, theta_t=np.random.randn()):
    A = [theta_t]
    N = X.shape[0]
    dimension=1
    if hasattr(theta_t, "__len__"):
        dimension = len(theta_t)

    global_evals = 0
    for i in range(chain_size*thinning-1):
        # if i % 1000 ==0:
        #     print( 100.0*i/(chain_size*thinning), ' %')
        theta_prime = np.random.randn(dimension)+theta_t

        u = np.random.rand()
        mu_0 = np.log(u)+log_density_prior(theta_t) -log_density_prior(theta_prime)
        mu_0 = mu_0/N

        accept,evals = approximate_MH_accept(mu_0, log_lik, X, batch_size, epsilon, theta_prime, theta_t, N)
        global_evals += evals
        if accept:
           theta_t = theta_prime

        A.append(theta_t)

    return np.array(A[::thinning]),global_evals
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号