Bug (?): NaN SMC weights and IndexOutOfBoundsError in theano

I’m running a toy hierarchical model and am using the SMC sampler (code and outputs attached), and it appears that at least one of the weights goes to 0 or an NaN value. From the traceback:

File “/usr/local/anaconda2/lib/python2.7/site-packages/pymc3/step_methods/smc.py”, line 272, in calc_beta
ESS = int(1 / np.sum(weights ** 2))
ValueError: cannot convert float NaN to integer

I’ve tried changing the seed and increasing the number of chains; but this results (sometimes) in an alternative error: an out-of-bounds from Theano.

This is on OSX 10.12.6 – python and library versions are in the outloaded stdout logs (appended to the code as only two links are allowed)
foo.oob.withOutput.py (23.0 KB)
foo.nan.withOutput.py (19.2 KB)

cc @aloctavodia - could you have a look?

Sure, I will check it tomorrow.

1 Like

@chartl, thanks for reporting this problem, I can confirm this is a bug. The main problem is that SMC is not working properly with discrete priors. I will try to fix this in the next few days.

BTW, when using SMC, the sampler arguments tune and chainsare ignored. The number of chains is the same as the number of draws. You can pass the argument tune to the step method SMC like pm.SMC(tune=False), by default this is True. I will also improve the documentation to make this more clear. In the meantime you can try using PyMC 3.5 which has the older version of SMC.

I think I fixed the problem (I have a pending PR). I also rewrite your model in a more vectorized way (see attached). Please check I did not mess up your model. Samples looks at least reasonable, you may want to increase the number of samples. I am using step=pm.SMC(tune=False) since tuning is not working very well right now (I will try to fix it ASAP)
chartl.py (12.0 KB)

Update: The PR has been accepted. You could try the fix by installing PyMC3 from master pip install git+https://github.com/pymc-devs/pymc3

1 Like