Skip to content

Replacing PyMC3 plots w/ Arviz plots & sigma Param change #16

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
256 changes: 105 additions & 151 deletions examples/case_studies/BEST.ipynb

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion examples/case_studies/LKJ.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@
"outputs": [],
"source": [
"az.style.use(\"arviz-darkgrid\")\n",
"\n",
"warnings.simplefilter(action=\"ignore\", category=FutureWarning)\n",
"\n",
"RANDOM_SEED = 8924\n",
"np.random.seed(3264602) # from random.org"
]
Expand Down Expand Up @@ -716,7 +718,7 @@
"metadata": {
"anaconda-cloud": {},
"kernelspec": {
"display_name": "pymc3-dev",
"display_name": "Python (PyMC3 Dev)",
"language": "python",
"name": "pymc3-dev"
},
Expand Down
10 changes: 5 additions & 5 deletions examples/case_studies/blackbox_external_likelihood.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@
" trace = pm.sample(ndraws, tune=nburn, discard_tuned_samples=True)\n",
"\n",
"# plot the traces\n",
"_ = pm.traceplot(trace, lines={\"m\": mtrue, \"c\": ctrue})\n",
"_ = az.plot_trace(trace, lines={\"m\": mtrue, \"c\": ctrue})\n",
"\n",
"# put the chains in an array (for later!)\n",
"samples_pymc3 = np.vstack((trace[\"m\"], trace[\"c\"])).T"
Expand Down Expand Up @@ -616,7 +616,7 @@
" trace = pm.sample(ndraws, tune=nburn, discard_tuned_samples=True)\n",
"\n",
"# plot the traces\n",
"_ = pm.traceplot(trace, lines={\"m\": mtrue, \"c\": ctrue})\n",
"_ = az.plot_trace(trace, lines={\"m\": mtrue, \"c\": ctrue})\n",
"\n",
"# put the chains in an array (for later!)\n",
"samples_pymc3_2 = np.vstack((trace[\"m\"], trace[\"c\"])).T"
Expand Down Expand Up @@ -644,12 +644,12 @@
" theta = tt.as_tensor_variable([m, c])\n",
"\n",
" # use a Normal distribution\n",
" pm.Normal(\"likelihood\", mu=(m * x + c), sd=sigma, observed=data)\n",
" pm.Normal(\"likelihood\", mu=(m * x + c), sigma=sigma, observed=data)\n",
"\n",
" trace = pm.sample(ndraws, tune=nburn, discard_tuned_samples=True)\n",
"\n",
"# plot the traces\n",
"_ = pm.traceplot(trace, lines={\"m\": mtrue, \"c\": ctrue})\n",
"_ = az.plot_trace(trace, lines={\"m\": mtrue, \"c\": ctrue})\n",
"\n",
"# put the chains in an array (for later!)\n",
"samples_pymc3_3 = np.vstack((trace[\"m\"], trace[\"c\"])).T"
Expand Down Expand Up @@ -832,7 +832,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.2"
"version": "3.8.5"
}
},
"nbformat": 4,
Expand Down
10 changes: 5 additions & 5 deletions examples/case_studies/conditional-autoregressive-model.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@
"\n",
"The classical `WinBUGS` implementation (more information [here](http://glau.ca/?p=340)):\n",
"\n",
"```\n",
"```python\n",
"model\n",
"{\n",
" for (i in 1 : regions) {\n",
Expand Down Expand Up @@ -2717,7 +2717,7 @@
}
],
"source": [
"summary2 = pm.summary(infdata2)\n",
"summary2 = az.summary(infdata2)\n",
"summary2[summary2[\"r_hat\"] > 1.05]"
]
},
Expand Down Expand Up @@ -3004,7 +3004,7 @@
"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",
"\n",
"For example, a more efficient sparse representation of the CAR in `Stan`:\n",
"```\n",
"```python\n",
"functions {\n",
" /**\n",
" * Return the log probability of a proper conditional autoregressive (CAR) prior \n",
Expand Down Expand Up @@ -3040,7 +3040,7 @@
" - tau * (phit_D * phi - alpha * (phit_W * phi)));\n",
" }\n",
"}\n",
"```\n",
"```python\n",
"with the data transformed in the model:\n",
"```\n",
"transformed data {\n",
Expand Down Expand Up @@ -3500,7 +3500,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.3"
"version": "3.8.5"
}
},
"nbformat": 4,
Expand Down
4 changes: 2 additions & 2 deletions examples/case_studies/disaster_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

"""


import arviz as az
import theano.tensor as tt

from numpy import arange, array
Expand Down Expand Up @@ -152,4 +152,4 @@
start = {"early_mean": 2.0, "late_mean": 3.0}

tr = pm.sample(1000, tune=500, start=start)
pm.traceplot(tr)
pm.plot_trace(tr)
4 changes: 2 additions & 2 deletions examples/case_studies/disaster_model_theano_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Note that gradient based samplers will not work.
"""


import arviz as az
import theano.tensor as tt

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

tr = pm.sample(1000, tune=500, start=start, step=[step1, step2], cores=2)
pm.traceplot(tr)
az.plot_trace(tr)
179 changes: 46 additions & 133 deletions examples/case_studies/factor_analysis.ipynb

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion examples/case_studies/garch_example.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import numpy as np
import theano.tensor as tt

from pymc3 import Model, Normal, Uniform, sample, summary
from arviz import summary
from pymc3 import Model, Normal, Uniform, sample

"""
Example from Stan - slightly altered
Expand Down
3 changes: 2 additions & 1 deletion examples/case_studies/gelman_schools.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import numpy as np

from pymc3 import HalfCauchy, Model, Normal, loo, sample
from arviz import loo
from pymc3 import HalfCauchy, Model, Normal, sample

"""Original Stan model

Expand Down
38 changes: 22 additions & 16 deletions examples/case_studies/hierarchical_partial_pooling.ipynb

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions examples/case_studies/lightspeed_example.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import numpy as np

import arviz as az
import pymc3 as pm

light_speed = np.array(
Expand Down Expand Up @@ -92,7 +92,7 @@ def run(n=5000):
with model_1:
trace = pm.sample(n)

pm.summary(trace)
az.summary(trace)


if __name__ == "__main__":
Expand Down
18 changes: 8 additions & 10 deletions examples/case_studies/log-gaussian-cox-process.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@
"outputs": [],
"source": [
"with pm.Model() as lgcp_model:\n",
" mu = pm.Normal(\"mu\", sd=3)\n",
" mu = pm.Normal(\"mu\", sigma=3)\n",
" rho = pm.Uniform(\"rho\", lower=25, upper=200)\n",
" cov_scale = pm.Exponential(\"cov_scale\", lam=1)\n",
"\n",
Expand Down Expand Up @@ -601,9 +601,7 @@
{
"cell_type": "code",
"execution_count": 14,
"metadata": {
"scrolled": false
},
"metadata": {},
"outputs": [
{
"data": {
Expand Down Expand Up @@ -773,7 +771,7 @@
"n_centroids = centroids.shape[0]\n",
"\n",
"with pm.Model() as mark_model:\n",
" mu = pm.Normal(\"mu\", sd=3)\n",
" mu = pm.Normal(\"mu\", sigma=3)\n",
" rho = pm.Uniform(\"rho\", lower=25, upper=200)\n",
"\n",
" cov_scale = pm.Exponential(\"scale\", lam=1)\n",
Expand Down Expand Up @@ -809,14 +807,14 @@
"outputs": [],
"source": [
"with mark_model:\n",
" alpha = pm.Normal(\"alpha\", sd=10.0)\n",
" beta = pm.Normal(\"beta\", sd=5)\n",
" alpha = pm.Normal(\"alpha\", sigma=10.0)\n",
" beta = pm.Normal(\"beta\", sigma=5)\n",
" eps_sd = pm.HalfCauchy(\"eps_sd\", beta=1.0)\n",
"\n",
" marks = pm.Normal(\n",
" \"marks\",\n",
" mu=alpha + beta * intensity[n_centroids::],\n",
" sd=eps_sd,\n",
" sigma=eps_sd,\n",
" shape=n,\n",
" observed=data[\"marks\"].values,\n",
" )"
Expand Down Expand Up @@ -1037,7 +1035,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.2"
"version": "3.8.5"
},
"toc": {
"base_numbering": 1,
Expand All @@ -1054,5 +1052,5 @@
}
},
"nbformat": 4,
"nbformat_minor": 2
"nbformat_minor": 4
}
11 changes: 3 additions & 8 deletions examples/case_studies/multilevel_modeling.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@
"from theano import tensor as tt\n",
"\n",
"print(f\"Running on PyMC3 v{pm.__version__}\")\n",
"\n",
"warnings.simplefilter(action=\"ignore\", category=FutureWarning)\n",
"\n",
"RANDOM_SEED = 8924\n",
"np.random.seed(286)"
]
Expand Down Expand Up @@ -8531,13 +8533,6 @@
"%load_ext watermark\n",
"%watermark -n -u -v -iv -w"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand All @@ -8557,7 +8552,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.9"
"version": "3.8.5"
}
},
"nbformat": 4,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1649,7 +1649,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.7"
"version": "3.8.5"
}
},
"nbformat": 4,
Expand Down
556 changes: 274 additions & 282 deletions examples/case_studies/putting_workflow.ipynb

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions examples/case_studies/rugby_analytics.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -1499,9 +1499,9 @@
"metadata": {
"anaconda-cloud": {},
"kernelspec": {
"display_name": "pymc-dev",
"display_name": "Python (PyMC3 Dev)",
"language": "python",
"name": "pymc-dev"
"name": "pymc3-dev"
},
"language_info": {
"codemirror_mode": {
Expand All @@ -1513,7 +1513,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.2"
"version": "3.8.5"
}
},
"nbformat": 4,
Expand Down
185 changes: 97 additions & 88 deletions examples/case_studies/stochastic_volatility.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion examples/diagnostics_and_criticism/Bayes_factor.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -694,7 +694,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.6"
"version": "3.8.5"
}
},
"nbformat": 4,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@
}
],
"source": [
"pm.summary(short_trace).round(2)"
"az.summary(short_trace).round(2)"
]
},
{
Expand Down Expand Up @@ -495,7 +495,7 @@
],
"source": [
"# plot the trace of log(tau)\n",
"pm.traceplot({\"log(tau)\": short_trace.get_values(varname=\"tau_log__\", combine=False)});"
"az.plot_trace({\"log(tau)\": short_trace.get_values(varname=\"tau_log__\", combine=False)});"
]
},
{
Expand Down Expand Up @@ -774,7 +774,7 @@
"# A small wrapper function for displaying the MCMC sampler diagnostics as above\n",
"def report_trace(trace):\n",
" # plot the trace of log(tau)\n",
" pm.traceplot({\"log(tau)\": trace.get_values(varname=\"tau_log__\", combine=False)})\n",
" az.plot_trace({\"log(tau)\": trace.get_values(varname=\"tau_log__\", combine=False)})\n",
"\n",
" # plot the estimate for the mean of log(τ) cumulating mean\n",
" logtau = np.log(trace[\"tau\"])\n",
Expand Down Expand Up @@ -1156,7 +1156,7 @@
}
],
"source": [
"pm.summary(longer_trace).round(2)"
"az.summary(longer_trace).round(2)"
]
},
{
Expand Down Expand Up @@ -2099,7 +2099,7 @@
}
],
"source": [
"pm.summary(fit_ncp80).round(2)"
"az.summary(fit_ncp80).round(2)"
]
},
{
Expand Down Expand Up @@ -2370,7 +2370,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.7"
"version": "3.8.5"
}
},
"nbformat": 4,
Expand Down
2 changes: 1 addition & 1 deletion examples/diagnostics_and_criticism/model_averaging.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -993,7 +993,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.6"
"version": "3.8.5"
}
},
"nbformat": 4,
Expand Down
2 changes: 1 addition & 1 deletion examples/diagnostics_and_criticism/model_comparison.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.6"
"version": "3.8.5"
}
},
"nbformat": 4,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -850,7 +850,7 @@
"metadata": {
"anaconda-cloud": {},
"kernelspec": {
"display_name": "pymc3-dev",
"display_name": "Python (PyMC3 Dev)",
"language": "python",
"name": "pymc3-dev"
},
Expand Down
2 changes: 1 addition & 1 deletion examples/diagnostics_and_criticism/sampler-stats.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.7"
"version": "3.8.5"
}
},
"nbformat": 4,
Expand Down
Loading