Skip to content

Commit a3dd746

Browse files
🎨 Replace Pymc3 plots w/arviz plots and sigma param change
1 parent 041e54f commit a3dd746

15 files changed

+199
-278
lines changed

examples/case_studies/LKJ.ipynb

+1-1
Original file line numberDiff line numberDiff line change
@@ -716,7 +716,7 @@
716716
"metadata": {
717717
"anaconda-cloud": {},
718718
"kernelspec": {
719-
"display_name": "pymc3-dev",
719+
"display_name": "Python (PyMC3 Dev)",
720720
"language": "python",
721721
"name": "pymc3-dev"
722722
},

examples/case_studies/blackbox_external_likelihood.ipynb

+5-5
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@
320320
" trace = pm.sample(ndraws, tune=nburn, discard_tuned_samples=True)\n",
321321
"\n",
322322
"# plot the traces\n",
323-
"_ = pm.traceplot(trace, lines={\"m\": mtrue, \"c\": ctrue})\n",
323+
"_ = az.plot_trace(trace, lines={\"m\": mtrue, \"c\": ctrue})\n",
324324
"\n",
325325
"# put the chains in an array (for later!)\n",
326326
"samples_pymc3 = np.vstack((trace[\"m\"], trace[\"c\"])).T"
@@ -616,7 +616,7 @@
616616
" trace = pm.sample(ndraws, tune=nburn, discard_tuned_samples=True)\n",
617617
"\n",
618618
"# plot the traces\n",
619-
"_ = pm.traceplot(trace, lines={\"m\": mtrue, \"c\": ctrue})\n",
619+
"_ = az.plot_trace(trace, lines={\"m\": mtrue, \"c\": ctrue})\n",
620620
"\n",
621621
"# put the chains in an array (for later!)\n",
622622
"samples_pymc3_2 = np.vstack((trace[\"m\"], trace[\"c\"])).T"
@@ -644,12 +644,12 @@
644644
" theta = tt.as_tensor_variable([m, c])\n",
645645
"\n",
646646
" # use a Normal distribution\n",
647-
" pm.Normal(\"likelihood\", mu=(m * x + c), sd=sigma, observed=data)\n",
647+
" pm.Normal(\"likelihood\", mu=(m * x + c), sigma=sigma, observed=data)\n",
648648
"\n",
649649
" trace = pm.sample(ndraws, tune=nburn, discard_tuned_samples=True)\n",
650650
"\n",
651651
"# plot the traces\n",
652-
"_ = pm.traceplot(trace, lines={\"m\": mtrue, \"c\": ctrue})\n",
652+
"_ = az.plot_trace(trace, lines={\"m\": mtrue, \"c\": ctrue})\n",
653653
"\n",
654654
"# put the chains in an array (for later!)\n",
655655
"samples_pymc3_3 = np.vstack((trace[\"m\"], trace[\"c\"])).T"
@@ -832,7 +832,7 @@
832832
"name": "python",
833833
"nbconvert_exporter": "python",
834834
"pygments_lexer": "ipython3",
835-
"version": "3.8.2"
835+
"version": "3.8.5"
836836
}
837837
},
838838
"nbformat": 4,

examples/case_studies/conditional-autoregressive-model.ipynb

+5-5
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@
122122
"\n",
123123
"The classical `WinBUGS` implementation (more information [here](http://glau.ca/?p=340)):\n",
124124
"\n",
125-
"```\n",
125+
"```python\n",
126126
"model\n",
127127
"{\n",
128128
" for (i in 1 : regions) {\n",
@@ -2717,7 +2717,7 @@
27172717
}
27182718
],
27192719
"source": [
2720-
"summary2 = pm.summary(infdata2)\n",
2720+
"summary2 = az.summary(infdata2)\n",
27212721
"summary2[summary2[\"r_hat\"] > 1.05]"
27222722
]
27232723
},
@@ -3004,7 +3004,7 @@
30043004
"Note that in the node $\\phi \\sim \\mathcal{N}(0, [D_\\tau (I - \\alpha B)]^{-1})$, we are computing the log-likelihood for a multivariate Gaussian distribution, which might not scale well in high-dimensions. We can take advantage of the fact that the covariance matrix here $[D_\\tau (I - \\alpha B)]^{-1}$ is **sparse**, and there are faster ways to compute its log-likelihood. \n",
30053005
"\n",
30063006
"For example, a more efficient sparse representation of the CAR in `Stan`:\n",
3007-
"```\n",
3007+
"```python\n",
30083008
"functions {\n",
30093009
" /**\n",
30103010
" * Return the log probability of a proper conditional autoregressive (CAR) prior \n",
@@ -3040,7 +3040,7 @@
30403040
" - tau * (phit_D * phi - alpha * (phit_W * phi)));\n",
30413041
" }\n",
30423042
"}\n",
3043-
"```\n",
3043+
"```python\n",
30443044
"with the data transformed in the model:\n",
30453045
"```\n",
30463046
"transformed data {\n",
@@ -3500,7 +3500,7 @@
35003500
"name": "python",
35013501
"nbconvert_exporter": "python",
35023502
"pygments_lexer": "ipython3",
3503-
"version": "3.8.3"
3503+
"version": "3.8.5"
35043504
}
35053505
},
35063506
"nbformat": 4,

examples/case_studies/disaster_model.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
99
"""
1010

11-
11+
import arviz as az
1212
import theano.tensor as tt
1313

1414
from numpy import arange, array
@@ -152,4 +152,4 @@
152152
start = {"early_mean": 2.0, "late_mean": 3.0}
153153

154154
tr = pm.sample(1000, tune=500, start=start)
155-
pm.traceplot(tr)
155+
pm.plot_trace(tr)

examples/case_studies/disaster_model_theano_op.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
Note that gradient based samplers will not work.
55
"""
66

7-
7+
import arviz as az
88
import theano.tensor as tt
99

1010
from numpy import arange, array, empty
@@ -166,4 +166,4 @@ def rate_(switchpoint, early_mean, late_mean):
166166
start = {"early_mean": 2.0, "late_mean": 3.0}
167167

168168
tr = pm.sample(1000, tune=500, start=start, step=[step1, step2], cores=2)
169-
pm.traceplot(tr)
169+
az.plot_trace(tr)

examples/case_studies/factor_analysis.ipynb

+44-133
Large diffs are not rendered by default.

examples/case_studies/garch_example.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import numpy as np
22
import theano.tensor as tt
33

4-
from pymc3 import Model, Normal, Uniform, sample, summary
4+
from arviz import summary
5+
from pymc3 import Model, Normal, Uniform, sample
56

67
"""
78
Example from Stan - slightly altered

examples/case_studies/gelman_schools.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import numpy as np
22

3-
from pymc3 import HalfCauchy, Model, Normal, loo, sample
3+
from arviz import loo
4+
from pymc3 import HalfCauchy, Model, Normal, sample
45

56
"""Original Stan model
67

examples/case_studies/hierarchical_partial_pooling.ipynb

+22-16
Large diffs are not rendered by default.

examples/case_studies/log-gaussian-cox-process.ipynb

+8-10
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@
320320
"outputs": [],
321321
"source": [
322322
"with pm.Model() as lgcp_model:\n",
323-
" mu = pm.Normal(\"mu\", sd=3)\n",
323+
" mu = pm.Normal(\"mu\", sigma=3)\n",
324324
" rho = pm.Uniform(\"rho\", lower=25, upper=200)\n",
325325
" cov_scale = pm.Exponential(\"cov_scale\", lam=1)\n",
326326
"\n",
@@ -601,9 +601,7 @@
601601
{
602602
"cell_type": "code",
603603
"execution_count": 14,
604-
"metadata": {
605-
"scrolled": false
606-
},
604+
"metadata": {},
607605
"outputs": [
608606
{
609607
"data": {
@@ -773,7 +771,7 @@
773771
"n_centroids = centroids.shape[0]\n",
774772
"\n",
775773
"with pm.Model() as mark_model:\n",
776-
" mu = pm.Normal(\"mu\", sd=3)\n",
774+
" mu = pm.Normal(\"mu\", sigma=3)\n",
777775
" rho = pm.Uniform(\"rho\", lower=25, upper=200)\n",
778776
"\n",
779777
" cov_scale = pm.Exponential(\"scale\", lam=1)\n",
@@ -809,14 +807,14 @@
809807
"outputs": [],
810808
"source": [
811809
"with mark_model:\n",
812-
" alpha = pm.Normal(\"alpha\", sd=10.0)\n",
813-
" beta = pm.Normal(\"beta\", sd=5)\n",
810+
" alpha = pm.Normal(\"alpha\", sigma=10.0)\n",
811+
" beta = pm.Normal(\"beta\", sigma=5)\n",
814812
" eps_sd = pm.HalfCauchy(\"eps_sd\", beta=1.0)\n",
815813
"\n",
816814
" marks = pm.Normal(\n",
817815
" \"marks\",\n",
818816
" mu=alpha + beta * intensity[n_centroids::],\n",
819-
" sd=eps_sd,\n",
817+
" sigma=eps_sd,\n",
820818
" shape=n,\n",
821819
" observed=data[\"marks\"].values,\n",
822820
" )"
@@ -1037,7 +1035,7 @@
10371035
"name": "python",
10381036
"nbconvert_exporter": "python",
10391037
"pygments_lexer": "ipython3",
1040-
"version": "3.7.2"
1038+
"version": "3.8.5"
10411039
},
10421040
"toc": {
10431041
"base_numbering": 1,
@@ -1054,5 +1052,5 @@
10541052
}
10551053
},
10561054
"nbformat": 4,
1057-
"nbformat_minor": 2
1055+
"nbformat_minor": 4
10581056
}

examples/case_studies/multilevel_modeling.ipynb

+1-8
Original file line numberDiff line numberDiff line change
@@ -8531,13 +8531,6 @@
85318531
"%load_ext watermark\n",
85328532
"%watermark -n -u -v -iv -w"
85338533
]
8534-
},
8535-
{
8536-
"cell_type": "code",
8537-
"execution_count": null,
8538-
"metadata": {},
8539-
"outputs": [],
8540-
"source": []
85418534
}
85428535
],
85438536
"metadata": {
@@ -8557,7 +8550,7 @@
85578550
"name": "python",
85588551
"nbconvert_exporter": "python",
85598552
"pygments_lexer": "ipython3",
8560-
"version": "3.6.9"
8553+
"version": "3.8.5"
85618554
}
85628555
},
85638556
"nbformat": 4,

examples/case_studies/probabilistic_matrix_factorization.ipynb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1649,7 +1649,7 @@
16491649
"name": "python",
16501650
"nbconvert_exporter": "python",
16511651
"pygments_lexer": "ipython3",
1652-
"version": "3.7.7"
1652+
"version": "3.8.5"
16531653
}
16541654
},
16551655
"nbformat": 4,

examples/case_studies/putting_workflow.ipynb

+4-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
],
1616
"source": [
1717
"import io\n",
18+
"\n",
1819
"import arviz as az\n",
1920
"import matplotlib.pyplot as plt\n",
2021
"import numpy as np\n",
@@ -33,7 +34,8 @@
3334
"outputs": [],
3435
"source": [
3536
"import warnings\n",
36-
"warnings.filterwarnings('ignore')"
37+
"\n",
38+
"warnings.filterwarnings(\"ignore\")"
3739
]
3840
},
3941
{
@@ -1660,7 +1662,7 @@
16601662
" p_success = pm.Normal(\n",
16611663
" \"p_success\",\n",
16621664
" mu=p,\n",
1663-
" sd=tt.sqrt(((p * (1 - p)) / golf_data.tries) + dispersion ** 2),\n",
1665+
" sigma=tt.sqrt(((p * (1 - p)) / golf_data.tries) + dispersion ** 2),\n",
16641666
" observed=golf_data.successes / golf_data.tries,\n",
16651667
" )\n",
16661668
" return distance_angle_model\n",

examples/case_studies/rugby_analytics.ipynb

+3-3
Original file line numberDiff line numberDiff line change
@@ -1499,9 +1499,9 @@
14991499
"metadata": {
15001500
"anaconda-cloud": {},
15011501
"kernelspec": {
1502-
"display_name": "pymc-dev",
1502+
"display_name": "Python (PyMC3 Dev)",
15031503
"language": "python",
1504-
"name": "pymc-dev"
1504+
"name": "pymc3-dev"
15051505
},
15061506
"language_info": {
15071507
"codemirror_mode": {
@@ -1513,7 +1513,7 @@
15131513
"name": "python",
15141514
"nbconvert_exporter": "python",
15151515
"pygments_lexer": "ipython3",
1516-
"version": "3.8.2"
1516+
"version": "3.8.5"
15171517
}
15181518
},
15191519
"nbformat": 4,

examples/case_studies/stochastic_volatility.ipynb

+97-88
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)