Skip to content

Commit 1ba9d31

Browse files
authored
fix diagnosing biased inference until variational api quickstart (#4080)
1 parent 9b1f3e5 commit 1ba9d31

10 files changed

+41
-27
lines changed

docs/source/notebooks/Diagnosing_biased_Inference_with_Divergences.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@
2121
}
2222
],
2323
"source": [
24+
"from collections import defaultdict\n",
25+
"\n",
2426
"import arviz as az\n",
2527
"import matplotlib.pyplot as plt\n",
2628
"import numpy as np\n",
2729
"import pandas as pd\n",
2830
"import pymc3 as pm\n",
2931
"\n",
30-
"from collections import defaultdict\n",
31-
"\n",
3232
"print('Runing on PyMC3 v{}'.format(pm.__version__))"
3333
]
3434
},

docs/source/notebooks/GP-Marginal.ipynb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,12 +137,12 @@
137137
},
138138
"outputs": [],
139139
"source": [
140-
"import pymc3 as pm\n",
140+
"import matplotlib.pyplot as plt\n",
141141
"import numpy as np\n",
142-
"import scipy as sp\n",
143142
"import pandas as pd\n",
143+
"import pymc3 as pm\n",
144+
"import scipy as sp\n",
144145
"\n",
145-
"import matplotlib.pyplot as plt\n",
146146
"%matplotlib inline"
147147
]
148148
},
@@ -481,6 +481,7 @@
481481
"\n",
482482
"# plot the samples from the gp posterior with samples and shading\n",
483483
"from pymc3.gp.util import plot_gp_dist\n",
484+
"\n",
484485
"plot_gp_dist(ax, pred_samples[\"f_pred\"], X_new);\n",
485486
"\n",
486487
"# plot the data and the true latent function\n",

docs/source/notebooks/GP-smoothing.ipynb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,10 @@
162162
"outputs": [],
163163
"source": [
164164
"import pymc3 as pm\n",
165-
"from theano import shared\n",
165+
"\n",
166166
"from pymc3.distributions.timeseries import GaussianRandomWalk\n",
167-
"from scipy import optimize"
167+
"from scipy import optimize\n",
168+
"from theano import shared"
168169
]
169170
},
170171
{

docs/source/notebooks/MvGaussianRandomWalk_demo.ipynb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@
1313
"metadata": {},
1414
"outputs": [],
1515
"source": [
16-
"import numpy as np\n",
1716
"import matplotlib.pyplot as plt\n",
18-
"from scipy.linalg import cholesky\n",
19-
"\n",
17+
"import numpy as np\n",
2018
"import pymc3 as pm\n",
2119
"import theano\n",
2220
"\n",
21+
"from scipy.linalg import cholesky\n",
22+
"\n",
2323
"np.random.seed(42)\n",
2424
"%matplotlib inline"
2525
]

docs/source/notebooks/bayesian_neural_network_advi.ipynb

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@
7676
}
7777
],
7878
"source": [
79+
"from warnings import filterwarnings\n",
80+
"\n",
7981
"import matplotlib.pyplot as plt\n",
8082
"import numpy as np\n",
8183
"import pymc3 as pm\n",
@@ -85,10 +87,9 @@
8587
"import theano.tensor as T\n",
8688
"\n",
8789
"from sklearn import datasets\n",
88-
"from sklearn.preprocessing import scale\n",
89-
"from sklearn.model_selection import train_test_split\n",
9090
"from sklearn.datasets import make_moons\n",
91-
"from warnings import filterwarnings\n",
91+
"from sklearn.model_selection import train_test_split\n",
92+
"from sklearn.preprocessing import scale\n",
9293
"\n",
9394
"print('Running on PyMC3 v{}'.format(pm.__version__))"
9495
]
@@ -252,7 +253,8 @@
252253
},
253254
"outputs": [],
254255
"source": [
255-
"from pymc3.theanof import set_tt_rng, MRG_RandomStreams\n",
256+
"from pymc3.theanof import MRG_RandomStreams, set_tt_rng\n",
257+
"\n",
256258
"set_tt_rng(MRG_RandomStreams(42))"
257259
]
258260
},

docs/source/notebooks/blackbox_external_likelihood.ipynb

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@
3636
"source": [
3737
"%load_ext Cython\n",
3838
"\n",
39+
"import os\n",
40+
"import platform\n",
41+
"\n",
3942
"import arviz as az\n",
4043
"import corner\n",
4144
"import cython\n",
@@ -44,8 +47,6 @@
4447
"import matplotlib\n",
4548
"import matplotlib.pyplot as plt\n",
4649
"import numpy as np\n",
47-
"import os\n",
48-
"import platform\n",
4950
"import pymc3 as pm\n",
5051
"import theano\n",
5152
"import theano.tensor as tt\n",
@@ -104,9 +105,11 @@
104105
"%%cython -I/usr/include -L/usr/lib/x86_64-linux-gnu -lgsl -lgslcblas -lm\n",
105106
"\n",
106107
"import cython\n",
108+
"\n",
107109
"cimport cython\n",
108110
"\n",
109111
"import numpy as np\n",
112+
"\n",
110113
"cimport numpy as np\n",
111114
"\n",
112115
"### STUFF FOR USING GSL (FEEL FREE TO IGNORE!) ###\n",
@@ -340,13 +343,16 @@
340343
"%%cython\n",
341344
"\n",
342345
"import cython\n",
346+
"\n",
343347
"cimport cython\n",
344348
"\n",
345349
"import numpy as np\n",
350+
"\n",
346351
"cimport numpy as np\n",
347352
"\n",
348353
"import warnings\n",
349354
"\n",
355+
"\n",
350356
"def gradients(vals, func, releps=1e-3, abseps=None, mineps=1e-9, reltol=1e-3,\n",
351357
" epsscale=0.5):\n",
352358
" \"\"\"\n",
@@ -661,6 +667,7 @@
661667
"outputs": [],
662668
"source": [
663669
"import warnings\n",
670+
"\n",
664671
"warnings.simplefilter(action='ignore', category=FutureWarning) # supress emcee autocorr FutureWarning\n",
665672
"\n",
666673
"matplotlib.rcParams['font.size'] = 18\n",

docs/source/notebooks/conditional-autoregressive-model.ipynb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,8 @@
1414
"import theano\n",
1515
"import theano.tensor as tt\n",
1616
"\n",
17-
"from pymc3.distributions import continuous\n",
18-
"from pymc3.distributions import distribution\n",
19-
"from theano import scan\n",
20-
"from theano import shared"
17+
"from pymc3.distributions import continuous, distribution\n",
18+
"from theano import scan, shared"
2119
]
2220
},
2321
{

docs/source/notebooks/gaussian-mixture-model-advi.ipynb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@
4040
"import seaborn as sns\n",
4141
"import theano.tensor as tt\n",
4242
"\n",
43-
"from pymc3 import Normal, Metropolis, sample, MvNormal, Dirichlet, DensityDist, find_MAP, NUTS, Slice\n",
43+
"from pymc3 import (NUTS, DensityDist, Dirichlet, Metropolis, MvNormal, Normal,\n",
44+
" Slice, find_MAP, sample)\n",
4445
"from pymc3.math import logsumexp\n",
4546
"from theano.tensor.nlinalg import det\n",
4647
"\n",
@@ -112,6 +113,7 @@
112113
"source": [
113114
"from pymc3.math import logsumexp\n",
114115
"\n",
116+
"\n",
115117
"# Log likelihood of normal distribution\n",
116118
"def logp_normal(mu, tau, value):\n",
117119
" # log probability of individual samples\n",

docs/source/notebooks/survival_analysis.ipynb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,13 @@
2828
"metadata": {},
2929
"outputs": [],
3030
"source": [
31-
"from matplotlib import pyplot as plt\n",
3231
"import numpy as np\n",
32+
"import pandas as pd\n",
3333
"import pymc3 as pm\n",
34-
"from pymc3.distributions.timeseries import GaussianRandomWalk\n",
3534
"import seaborn as sns\n",
36-
"import pandas as pd\n",
35+
"\n",
36+
"from matplotlib import pyplot as plt\n",
37+
"from pymc3.distributions.timeseries import GaussianRandomWalk\n",
3738
"from theano import tensor as T"
3839
]
3940
},

docs/source/notebooks/variational_api_quickstart.ipynb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@
2626
"source": [
2727
"%matplotlib inline\n",
2828
"import matplotlib.pyplot as plt\n",
29+
"import numpy as np\n",
2930
"import pymc3 as pm\n",
3031
"import theano\n",
31-
"import numpy as np\n",
3232
"\n",
3333
"np.random.seed(42)\n",
3434
"pm.set_tt_rng(42)"
@@ -853,6 +853,7 @@
853853
],
854854
"source": [
855855
"import seaborn as sns\n",
856+
"\n",
856857
"ax = sns.kdeplot(trace['x'], label='NUTS');\n",
857858
"sns.kdeplot(approx.sample(10000)['x'], label='ADVI');"
858859
]
@@ -1327,10 +1328,11 @@
13271328
}
13281329
],
13291330
"source": [
1331+
"import pandas as pd\n",
1332+
"import theano.tensor as tt\n",
1333+
"\n",
13301334
"from sklearn.datasets import load_iris\n",
13311335
"from sklearn.model_selection import train_test_split\n",
1332-
"import theano.tensor as tt\n",
1333-
"import pandas as pd\n",
13341336
"\n",
13351337
"X, y = load_iris(True)\n",
13361338
"X_train, X_test, y_train, y_test = train_test_split(X, y)"

0 commit comments

Comments
 (0)