python - 具有高斯先验的主持人给出 NaN
问题描述
我一直在使用 emcee 对我的参数进行采样,起初我之前的都是统一的
def logprior_BAO(theta):
A, B, C, D, epsilon, rd = theta
if A > 0 and B > 0 and C > 0 and D > 0 and epsilon > -5 and 146.96<=rd<=147.58:
return 0.0
return -np.inf
它工作得很好。然后,我在高斯之前更改 rd,
def logprior_BAO(theta):
A, B, C, D, epsilon, rd = theta
#flat priors
if not A > 0 and B > 0 and C > 0 and D > 0 and epsilon > -5:
return -np.inf
#gaussian prior rd
mu = 147.27
sigma = 0.31
return np.log(1.0/(np.sqrt(2*np.pi)*sigma))-0.5*(rd-mu)**2/sigma**2
程序给了我这个错误
ValueError Traceback (most recent call last)
<ipython-input-9-b9ee20e97036> in <module>
3 move = emcee.moves.StretchMove(a=a_parameter)
4 sampler = emcee.EnsembleSampler(nwalker, ndims, logposterior,args=argslist, moves=move)
----> 5 sampler.run_mcmc(initial, nsteps, progress=True)
~\anaconda3\lib\site-packages\emcee\ensemble.py in run_mcmc(self, initial_state, nsteps, **kwargs)
382
383 results = None
--> 384 for results in self.sample(initial_state, iterations=nsteps, **kwargs):
385 pass
386
~\anaconda3\lib\site-packages\emcee\ensemble.py in sample(self, initial_state, log_prob0, rstate0, blobs0, iterations, tune, skip_initial_state_check, thin_by, thin, store, progress)
283 state.blobs = blobs0
284 if state.log_prob is None:
--> 285 state.log_prob, state.blobs = self.compute_log_prob(state.coords)
286 if np.shape(state.log_prob) != (self.nwalkers,):
287 raise ValueError("incompatible input dimensions")
~\anaconda3\lib\site-packages\emcee\ensemble.py in compute_log_prob(self, coords)
454 # Check for log_prob returning NaN.
455 if np.any(np.isnan(log_prob)):
--> 456 raise ValueError("Probability function returned NaN")
457
458 return log_prob, blob
ValueError: Probability function returned NaN
谁能告诉我为什么会这样,以及如何解决?我会感谢你的回答,谢谢
解决方案
推荐阅读
- google-api - gmail API Users.messages:列表没有收到回复
- javascript - 当我在节点 js 中将 x 设置为请求时,“x”的 getData 不起作用
- google-apps-script - Google Script getRange(函数返回 A1Notation)
- django - 如何在 uwsgi 后面获取 django 日志?
- r - 优雅地结合连续和因子栅格
- mysql - 如何在 MySQL 中将行数据转置为列
- ag-grid - 如何在 ag-grid 上显示数据之前对其进行格式化
- python - Tensorflow 图结果在恢复后出现随机
- javascript -
在页面刷新之前无法重复获得焦点 - c# - c# decode base64 - Base-64 字符数组或字符串的长度无效