为什么find_MAP会在这个模型上抛出错误?

时间:2015-07-30 17:21:05

标签: pymc pymc3

我在pymc3中尝试了一个简单的模型,但是当我尝试使用find_MAP方法时,它会抛出以下错误。:

ValueError: Optimization error: max, logp or dlogp at max have non-finite values. Some values may be outside of distribution support. max: {'theta_stickbreaking': array([  1.90465421e-09,   0.00000000e+00])} logp: array(-inf) dlogp: array([ -1.14279242e-09,   0.00000000e+00])Check that 1) you don't have hierarchical parameters, these will lead to points with infinite density. 2) your distribution logp's are properly specified. Specific issues:

非常相似的代码使用Beta和Binomial分布而不是Dirichlet和Multinomial分布,但以下代码失败:

from pymc3 import Model
from pymc3 import Metropolis 
from pymc3 import Multinomial, Dirichlet
from pymc3 import sample, find_MAP
from pymc3 import traceplot
from scipy import optimize
import numpy as np

y_obs = [200, 400, 500]
k = 3
a= np.array([1, 1, 1])

with Model() as multinomial_inference:
    n = 1000
    theta = Dirichlet('theta', a, shape=k)
    y = Multinomial('y', n, theta, observed=y_obs)

with multinomial_inference:
    start = find_MAP()
    step = Metropolis([theta])
    trace = sample(10000, step, start)

如何调整模型推理设置以使其不会爆炸?

1 个答案:

答案 0 :(得分:2)

我认为问题在于您选择的y_obsn值。 y的观测值总和应与n相加。