I am new to pymc and enjoy it, but have come across some very weird behavior. I want to use it to track movement; after the tutorials, I installed some stochastics and tried to use pymc.NormApprox() on it. fit() seems to work, but when I try to get the output, it gives me a KeyError . When I switch to using pymc.MCMC , it launches `sample () OK, but then destroys the namespace (Python even forgets how to exit ()).
System: Ubuntu 12.04, scipy numpy, etc. installed, pymc installed via easy_install; also tried from git.
Code to play: test.py ::
import pymc import numpy as np x = pymc.MvNormal('x',mu=np.zeros(4),tau=np.eye(4)) @pymc.deterministic() def y(x=x): out = np.zeros(2) out[0] = x[0]+x[2] out[1] = x[1]+x[3] return out ymeas = pymc.MvNormal('ymeas',mu=y,tau=np.eye(2)*100000,value=20*np.ones(2),observed=True)
Then in a shell running python or ipython ::
import test import pymc foo = pymc.NormApprox(test) foo.fit() foo.mu[foo.x] # Fails - gives KeyError foo._mu # I can see it OK if I break privacy rules foo = pymc.MCMC(test) foo.sample(10000) # runs OK foo # fails - namespace is nuked
What I expect to see: foo.mu[foo.x] should give me a normal approximation to the back; I should not receive a key error and should not go into foo._mu
instead I get:
>>> foo.mu[foo.x] Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/local/lib/python2.7/dist-packages/pymc-2.2-py2.7-linux-x86_64.egg/pymc/NormalApproximation.py", line 56, in __getitem__ tot_len += self.owner.stochastic_len[p] KeyError: 9.9999517411499177 >>> foo._mu array([ 9.99995174, 9.99997163, 10.0000485 , 10.00002837]) >>>
I also noticed that the docstring for foo.mu says N.mu(p1,p2) , but the online documentation says N.mu[N.p1,N.p2] .
Regarding namespace decay after MCMC, it even forgets how to exit ()
I can also confirm that I have the same problem on another machine (MacBook Pro) that launches another installation (Enthought Python).