在PyMC中打印跟踪时出现KeyError [英] KeyError while printing trace in PyMC

查看:121
本文介绍了在PyMC中打印跟踪时出现KeyError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我读到默认情况下,随机变量有一些名称.我在下面编写代码的相关部分.

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')[:]

最后一行引发错误 KeyError:'parameters_0'.有人可以解释为什么会这样.

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

但是,如果我使用Matplot.plot(m),则会得到绘图(在下面将其附加).我的印象是键是parameter_0,parameters_1,parameters_2.

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 ?

)

推荐答案

您没有名为parameters_0的节点.您只有lamparametersrv_0rv_1

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

这篇关于在PyMC中打印跟踪时出现KeyError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆