Skip to content

Commit

Permalink
started MCMC chapter in BM4H
Browse files Browse the repository at this point in the history
  • Loading branch information
Emaasit committed Nov 13, 2017
1 parent 472fbf0 commit 10ace7b
Show file tree
Hide file tree
Showing 8 changed files with 3,752 additions and 14 deletions.
37 changes: 34 additions & 3 deletions .ipynb_checkpoints/01_quick_start-checkpoint.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,10 @@
" \n",
" # the likelihood of observations\n",
" # data can be passed in as ndarray or pandas df\n",
" obs = pm.Normal('obs', mu = mu, sd = sd, observed = y)"
" obs = pm.Normal('obs', mu = mu, sd = sd, observed = y)\n",
" \n",
" # simulate data from model\n",
" simulated_obs = pm.Normal(\"simulated_obs\", mu = mu, sd = sd, shape = mu.tag.test_value.shape)"
]
},
{
Expand Down Expand Up @@ -618,6 +621,17 @@
"posterior.get_values('mu', chains = 1).shape # get values of a single chain"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# extract the simulated data\n",
"simulated_data = posterior[\"simulated_obs\"]\n",
"simulated_data.shape"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -3435,7 +3449,10 @@
" mu = pm.Normal(\"mu\", mu = 0, sd = 1e6)\n",
" \n",
" ## specify the likelihood\n",
" obs = pm.Normal(\"obs\", mu = mu, sd = sigma, observed = y)"
" obs = pm.Normal(\"obs\", mu = mu, sd = sigma, observed = y)\n",
" \n",
" # simulate data from model\n",
" simulated_obs = pm.Normal(\"simulated_obs\", mu = mu, sd = sigma, shape = mu.tag.test_value.shape)"
]
},
{
Expand Down Expand Up @@ -3675,7 +3692,10 @@
" theta = pm.Deterministic(\"theta\", mu + tau*eta)\n",
" \n",
" ## specify the likelihood\n",
" obs = pm.Normal(\"obs\", mu = theta, sd = sigma, observed = y)"
" obs = pm.Normal(\"obs\", mu = theta, sd = sigma, observed = y)\n",
" \n",
" # simulate data from model\n",
" simulated_obs = pm.Normal(\"simulated_obs\", mu = theta, sd = sigma, shape = theta.tag.test_value.shape)"
]
},
{
Expand Down Expand Up @@ -4244,6 +4264,17 @@
"pm.summary(posterior_schools, varnames = [\"theta\", \"mu\", \"tau\"])"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# extract the simulated data\n",
"simulated_data = posterior[\"simulated_obs\"]\n",
"simulated_data.shape"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down
37 changes: 34 additions & 3 deletions 01_quick_start.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,10 @@
" \n",
" # the likelihood of observations\n",
" # data can be passed in as ndarray or pandas df\n",
" obs = pm.Normal('obs', mu = mu, sd = sd, observed = y)"
" obs = pm.Normal('obs', mu = mu, sd = sd, observed = y)\n",
" \n",
" # simulate data from model\n",
" simulated_obs = pm.Normal(\"simulated_obs\", mu = mu, sd = sd, shape = mu.tag.test_value.shape)"
]
},
{
Expand Down Expand Up @@ -618,6 +621,17 @@
"posterior.get_values('mu', chains = 1).shape # get values of a single chain"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# extract the simulated data\n",
"simulated_data = posterior[\"simulated_obs\"]\n",
"simulated_data.shape"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -3435,7 +3449,10 @@
" mu = pm.Normal(\"mu\", mu = 0, sd = 1e6)\n",
" \n",
" ## specify the likelihood\n",
" obs = pm.Normal(\"obs\", mu = mu, sd = sigma, observed = y)"
" obs = pm.Normal(\"obs\", mu = mu, sd = sigma, observed = y)\n",
" \n",
" # simulate data from model\n",
" simulated_obs = pm.Normal(\"simulated_obs\", mu = mu, sd = sigma, shape = mu.tag.test_value.shape)"
]
},
{
Expand Down Expand Up @@ -3675,7 +3692,10 @@
" theta = pm.Deterministic(\"theta\", mu + tau*eta)\n",
" \n",
" ## specify the likelihood\n",
" obs = pm.Normal(\"obs\", mu = theta, sd = sigma, observed = y)"
" obs = pm.Normal(\"obs\", mu = theta, sd = sigma, observed = y)\n",
" \n",
" # simulate data from model\n",
" simulated_obs = pm.Normal(\"simulated_obs\", mu = theta, sd = sigma, shape = theta.tag.test_value.shape)"
]
},
{
Expand Down Expand Up @@ -4244,6 +4264,17 @@
"pm.summary(posterior_schools, varnames = [\"theta\", \"mu\", \"tau\"])"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# extract the simulated data\n",
"simulated_data = posterior[\"simulated_obs\"]\n",
"simulated_data.shape"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down
1,807 changes: 1,803 additions & 4 deletions bm4h/.ipynb_checkpoints/ch02_more_pymc-checkpoint.ipynb

Large diffs are not rendered by default.

39 changes: 39 additions & 0 deletions bm4h/.ipynb_checkpoints/ch03_intro_mcmc-checkpoint.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Introduction to MCMC"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.3"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Binary file added bm4h/.ipynb_checkpoints/distplot-checkpoint.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 10ace7b

Please sign in to comment.