I ran the first example notebook - Sampler Statistics and found the following two interdependent glitches(maybe)
The usage of
%matplotlib inline
at
Line 7
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sb
import pandas as pd
import pymc3 as pm
%matplotlib inline
model = pm.Model()
with model:
mu1 = pm.Normal("mu1", mu=0, sd=1, shape=10)
with model:
step = pm.NUTS()
trace = pm.sample(2000, tune=1000, init=None, step=step, njobs=2)
trace.stat_names
plt.plot(trace['step_size_bar'])
plt.show()
sizes1, sizes2 = trace.get_sampler_stats('depth', combine=False)
is supported only if IPython is installed.
Instead, we can use plt.show() after every figure we need to print.
%matplotlib inline
model = pm.Model()
with model:
mu1 = pm.Normal("mu1", mu=0, sd=1, shape=10)
with model:
step = pm.NUTS()
trace = pm.sample(2000, tune=1000, init=None, step=step, njobs=2)
trace.stat_names
plt.plot(trace['step_size_bar'])
plt.show()
sizes1, sizes2 = trace.get_sampler_stats('depth', combine=False)
fig, (ax1, ax2) = plt.subplots(2, 1, sharex=True, sharey=True)
ax1.plot(sizes1)
ax2.plot(sizes2)
plt.show()
plt.show()
accept = trace.get_sampler_stats('mean_tree_accept', burn=1000)
sb.distplot(accept, kde=False)
plt.show()
accept.mean()
This does compromise on the quality of a few graphs.
We can add to the docs that IPython is required.
What should be done?
Thanks
They are meant to run as jupyter notebooks, as in general in a .py
file you are not supposed to have %matplotlib inline
.
Do you have jupyter notebook installed? You should open a jupyter kernel and run the notebooks from the browser.
Okay, Thanks!
I’ll complete the installation and then run it.