我正在使用EMCEE。我在下面写了从那里出现问题的部分。我遇到了这个错误
ValueError: lnprob returned NaN.
这个错误会中断计算,我不知道如何克服。所以,我应该做一些事情来传递这个错误,以便继续剩下的计算。
我想到的唯一事情是在lnprob
函数中添加一行,例如:
if not np.isfinite(lp):
return -np.inf
if np.isnan(lp):
return -np.inf
但这是不正确的
代码是:
def log_prior(H0, od0, c, b, Orc, M):
if 0.4 < od0 < 0.9 and 50 < H0 < 90 and 0 < c < 3 and 0 < b < 1 and -0.3 < M < 0.2 and 0 < Orc < 0.1:
return 0.0
return -np.inf
def lnlike(H0, od0, c, b, Orc, M):
lg = -chi2(H0, od0, c, b, Orc, M)/2.
return lg
def lnprob(H0, od0, c, b, Orc, M):
lp = log_prior(H0, od0, c, b, Orc, M)
if not np.isfinite(lp):
return -np.inf
return lp + lnlike(H0, od0, c, b, Orc, M)
def func(theta):
H0, od0, c, b, Orc, M = theta
return -2. * lnprob(H0, od0, c, b, Orc, M)
我感谢您的帮助。