pythonpymcmcmcmultinomialdirichlet

KeyError while printing trace in PyMC


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 ?

enter image description here)


Solution

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