Probabilistic-Programming-and-Bayesian-Methods-for-Hackers
Probabilistic-Programming-and-Bayesian-Methods-for-Hackers copied to clipboard
Chapter2_pymc2 does not work with the latest numpy
When I run the notebook for Chapter 2 on pymc2, it fails with the error below. It looks like current implementation is not compatible with numpy boolean subtract.
python version: 3.6 numpy version: 1.14.5
model = pm.Model([p, true_answers, first_coin_flips,
second_coin_flips, observed_proportion, observations])
# To be explained in Chapter 3!
mcmc = pm.MCMC(model)
mcmc.sample(40000, 15000)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-36-aa3a84ff9334> in <module>()
4 # To be explained in Chapter 3!
5 mcmc = pm.MCMC(model)
----> 6 mcmc.sample(40000, 15000)
/usr/local/lib/python3.6/dist-packages/pymc/MCMC.py in sample(self, iter, burn, thin, tune_interval, tune_throughout, save_interval, burn_till_tuned, stop_tuning_after, verbose, progress_bar)
277
278 # Run sampler
--> 279 Sampler.sample(self, iter, length, verbose)
280
281 def _loop(self):
/usr/local/lib/python3.6/dist-packages/pymc/Model.py in sample(self, iter, length, verbose)
249 # Loop
250 self._current_iter = 0
--> 251 self._loop()
252 self._finalize()
253
/usr/local/lib/python3.6/dist-packages/pymc/MCMC.py in _loop(self)
313 print_('Step method %s stepping' % step_method._id)
314 # Step the step method
--> 315 step_method.step()
316
317 # Record sample to trace, if appropriate
/usr/local/lib/python3.6/dist-packages/pymc/StepMethods.py in step(self)
908 def step(self):
909 if ndim(self.stochastic.value):
--> 910 Metropolis.step(self)
911 else:
912
/usr/local/lib/python3.6/dist-packages/pymc/StepMethods.py in step(self)
499
500 # Sample a candidate value
--> 501 self.propose()
502
503 # Probability and likelihood for s's proposed value:
/usr/local/lib/python3.6/dist-packages/pymc/StepMethods.py in propose(self)
967 switch_locs = where(rand_array < p_jump)
968 if shape(new_value):
--> 969 new_value[switch_locs] = True - new_value[switch_locs]
970 else:
971 new_value = True - new_value
TypeError: numpy boolean subtract, the `-` operator, is deprecated, use the bitwise_xor, the `^` operator, or the logical_xor function instead.
I experienced the same issue.
A simple solution to get the code working is to downgrade numpy to version <= 1.13.3
Yea, I need to update the libs (all of them really) for the chapters
No other possible solution?