KeyError while printing trace in PyMC

独自空忆成欢 提交于 2019-12-12 01:39:16

问题


I had read that by default some names are assigned to Stochastic vaiables. I am writing the relevant portion of my code below.

lam = pm.Uniform('lam', lower=0.0, upper=5, doc='lam')
parameters = pm.Dirichlet('parameters',[1,1,1,1], doc='parameters')
rv = [ pm.Multinomial("rv"+str(i), count[i], prob_distribution[i], value = data[i], observed = True) for i in xrange(0, len(count)) ]

m = pm.MCMC([lam, parameters, rv])
m.sample(10)
print m.trace('lam')[:]
print m.trace('parameters_0')[:]

The last line raises an error KeyError: 'parameters_0' Can someone explain why it is so.

But if I use Matplot.plot(m), I get the plots (which I have attached below). I get the impression that the keys are parameters_0, parameters_1, parameters_2.

Is there some way by which I can know all keys whose trace is present ?

)

回答1:


You don't have a node called parameters_0. You only have lam, parameters, rv_0, rv_1, etc.



来源:https://stackoverflow.com/questions/24092306/keyerror-while-printing-trace-in-pymc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!