Skip to content

Commit bba5916

Browse files
authored
Merge branch 'master' into smc_ml
2 parents 05dddb1 + d4f850a commit bba5916

39 files changed

+668
-285
lines changed

README.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ Learn Bayesian statistics with a book together with PyMC3:
5151

5252
- `Probabilistic Programming and Bayesian Methods for Hackers <https://github.com/CamDavidsonPilon/Probabilistic-Programming-and-Bayesian-Methods-for-Hackers>`__: Fantastic book with many applied code examples.
5353
- `PyMC3 port of the book "Doing Bayesian Data Analysis" by John Kruschke <https://github.com/aloctavodia/Doing_bayesian_data_analysis>`__ as well as the `second edition <https://github.com/JWarmenhoven/DBDA-python>`__: Principled introduction to Bayesian data analysis.
54-
- `PyMC3 port of the book "Statistical Rethinking A Bayesian Course with Examples in R and Stan" by Richard McElreath <https://github.com/aloctavodia/Statistical-Rethinking-with-Python-and-PyMC3>`__
55-
- `PyMC3 port of the book "Bayesian Cognitive Modeling" by Michael Lee and EJ Wagenmakers <https://github.com/junpenglao/Bayesian-Cognitive-Modeling-in-Pymc3>`__: Focused on using Bayesian statistics in cognitive modeling.
54+
- `PyMC3 port of the book "Statistical Rethinking A Bayesian Course with Examples in R and Stan" by Richard McElreath <https://github.com/pymc-devs/resources/tree/master/Rethinking>`__
55+
- `PyMC3 port of the book "Bayesian Cognitive Modeling" by Michael Lee and EJ Wagenmakers <https://github.com/pymc-devs/resources/tree/master/BCM>`__: Focused on using Bayesian statistics in cognitive modeling.
5656
- `Bayesian Analysis with Python by Osvaldo Martin <https://www.packtpub.com/big-data-and-business-intelligence/bayesian-analysis-python>`__ (and `errata <https://github.com/aloctavodia/BAP>`__): Great introductory book.
5757

5858
PyMC3 talks

RELEASE-NOTES.md

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
- Renamed `sample_ppc()` and `sample_ppc_w()` to `sample_posterior_predictive()` and `sample_posterior_predictive_w()`, respectively.
77
- Refactor SMC and properly compute marginal likelihood (#3124)
88

9+
910
## PyMC 3.5 (July 21 2018)
1011

1112
### New features

build_and_deploy_docs.sh

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
#!/bin/sh
22

3+
latesttag=$(git describe --tags `git rev-list --tags --max-count=1`)
4+
echo checking out ${latesttag}
5+
git checkout ${latesttag}
36
pushd docs/source
47
make html
58
ghp-import -c docs.pymc.io -n -p _build/html/

docs/source/advanced_theano.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ variable for our observations::
6060
# fit the model
6161
trace = pm.sample()
6262

63-
# Switch out the observations and use `sample_ppc` to predict
63+
# Switch out the observations and use `sample_posterior_predictive` to predict
6464
x_shared.set_value([-1, 0, 1.])
65-
post_pred = pm.sample_ppc(trace, samples=500)
65+
post_pred = pm.sample_posterior_predictive(trace, samples=500)
6666

6767
However, due to the way we handle shapes at the moment, it is
6868
not possible to change the shape of a shared variable if that would

docs/source/examples.rst

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Howto
1818
notebooks/PyMC3_tips_and_heuristic.ipynb
1919
notebooks/LKJ.ipynb
2020
notebooks/live_sample_plots.ipynb
21+
notebooks/sampling_compound_step.ipynb
2122

2223
Applied
2324
=======

docs/source/intro.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Introduction
88
Purpose
99
=======
1010

11-
PyMC3 is a probabilistic programming module for Python that allows users to fit Bayesian models using a variety of numerical methods, most notably Markov chain Monte Carlo (MCMC) and variational inference (VI). Its flexibility and extensibility make it applicable to a large suite of problems. Along with core model specification and fitting functionality, PyMC3 includes functionality for summarizing output and for model diagnostics.
11+
PyMC3 is a probabilistic programming package for Python that allows users to fit Bayesian models using a variety of numerical methods, most notably Markov chain Monte Carlo (MCMC) and variational inference (VI). Its flexibility and extensibility make it applicable to a large suite of problems. Along with core model specification and fitting functionality, PyMC3 includes functionality for summarizing output and for model diagnostics.
1212

1313

1414

docs/source/notebooks/Bayes_factor.ipynb

+2-2
Original file line numberDiff line numberDiff line change
@@ -437,8 +437,8 @@
437437
],
438438
"source": [
439439
"_, ax = plt.subplots()\n",
440-
"ppc_0 = pm.sample_ppc(traces[0], 1000, models[0], size=(len(y), 20))\n",
441-
"ppc_1 = pm.sample_ppc(traces[1], 1000, models[1], size=(len(y), 20))\n",
440+
"ppc_0 = pm.sample_posterior_predictive(traces[0], 1000, models[0], size=(len(y), 20))\n",
441+
"ppc_1 = pm.sample_posterior_predictive(traces[1], 1000, models[1], size=(len(y), 20))\n",
442442
"for m_0, m_1 in zip(ppc_0['yl'].T, ppc_1['yl'].T):\n",
443443
" pm.kdeplot(np.mean(m_0, 0), ax=ax, color='C0', label='model 0')\n",
444444
" pm.kdeplot(np.mean(m_1, 0), ax=ax, color='C1', label='model 1')\n",

docs/source/notebooks/Euler-Maruyama and SDEs.ipynb renamed to docs/source/notebooks/Euler-Maruyama_and_SDEs.ipynb

+2-2
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@
431431
],
432432
"source": [
433433
"# generate trace from posterior\n",
434-
"ppc_trace = pm.sample_ppc(trace, model=model)\n",
434+
"ppc_trace = pm.sample_posterior_predictive(trace, model=model)\n",
435435
"\n",
436436
"# plot with data\n",
437437
"figure(figsize=(10, 3))\n",
@@ -799,7 +799,7 @@
799799
],
800800
"source": [
801801
"# generate trace from posterior\n",
802-
"ppc_trace = pm.sample_ppc(trace, model=model)\n",
802+
"ppc_trace = pm.sample_posterior_predictive(trace, model=model)\n",
803803
"\n",
804804
"# plot with data\n",
805805
"figure(figsize=(10, 3))\n",

docs/source/notebooks/GLM-robust-with-outlier-detection.ipynb

+112-196
Large diffs are not rendered by default.

docs/source/notebooks/GP-Latent.ipynb

+3-3
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@
301301
"\n",
302302
"### Using `.conditional`\n",
303303
"\n",
304-
"Next, we extend the model by adding the conditional distribution so we can predict at new $x$ locations. Lets see how the extrapolation looks out to higher $x$. To do this, we extend our `model` with the `conditional` distribution of the GP. Then, we can sample from it using the `trace` and the `sample_ppc` function. This is similar to how Stan uses its `generated quantities {...}` blocks. We could have included `gp.conditional` in the model *before* we did the NUTS sampling, but it is more efficient to separate these steps."
304+
"Next, we extend the model by adding the conditional distribution so we can predict at new $x$ locations. Lets see how the extrapolation looks out to higher $x$. To do this, we extend our `model` with the `conditional` distribution of the GP. Then, we can sample from it using the `trace` and the `sample_posterior_predictive` function. This is similar to how Stan uses its `generated quantities {...}` blocks. We could have included `gp.conditional` in the model *before* we did the NUTS sampling, but it is more efficient to separate these steps."
305305
]
306306
},
307307
{
@@ -334,7 +334,7 @@
334334
"\n",
335335
"# Sample from the GP conditional distribution\n",
336336
"with model:\n",
337-
" pred_samples = pm.sample_ppc(trace, vars=[f_pred], samples=1000)"
337+
" pred_samples = pm.sample_posterior_predictive(trace, vars=[f_pred], samples=1000)"
338338
]
339339
},
340340
{
@@ -543,7 +543,7 @@
543543
" f_pred = gp.conditional(\"f_pred\", X_new)\n",
544544
"\n",
545545
"with model:\n",
546-
" pred_samples = pm.sample_ppc(trace, vars=[f_pred], samples=1000)"
546+
" pred_samples = pm.sample_posterior_predictive(trace, vars=[f_pred], samples=1000)"
547547
]
548548
},
549549
{

docs/source/notebooks/GP-Marginal.ipynb

+2-2
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@
349349
"\n",
350350
"# To use the MAP values, you can just replace the trace with a length-1 list with `mp`\n",
351351
"with model:\n",
352-
" pred_samples = pm.sample_ppc([mp], vars=[f_pred], samples=2000)"
352+
" pred_samples = pm.sample_posterior_predictive([mp], vars=[f_pred], samples=2000)"
353353
]
354354
},
355355
{
@@ -420,7 +420,7 @@
420420
"source": [
421421
"with model:\n",
422422
" y_pred = gp.conditional(\"y_pred\", X_new, pred_noise=True)\n",
423-
" y_samples = pm.sample_ppc([mp], vars=[y_pred], samples=2000)"
423+
" y_samples = pm.sample_posterior_predictive([mp], vars=[y_pred], samples=2000)"
424424
]
425425
},
426426
{

docs/source/notebooks/GP-SparseApprox.ipynb

+1-1
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@
179179
"\n",
180180
"# To use the MAP values, you can just replace the trace with a length-1 list with `mp`\n",
181181
"with model:\n",
182-
" pred_samples = pm.sample_ppc(trace, vars=[f_pred], samples=1000)"
182+
" pred_samples = pm.sample_posterior_predictive(trace, vars=[f_pred], samples=1000)"
183183
]
184184
},
185185
{

docs/source/notebooks/GP-TProcess.ipynb

+1-1
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@
252252
"\n",
253253
"# Sample from the GP conditional distribution\n",
254254
"with model:\n",
255-
" pred_samples = pm.sample_ppc(tr, vars=[f_pred], samples=1000)"
255+
" pred_samples = pm.sample_posterior_predictive(tr, vars=[f_pred], samples=1000)"
256256
]
257257
},
258258
{

docs/source/notebooks/api_quickstart.ipynb

+4-4
Original file line numberDiff line numberDiff line change
@@ -1551,7 +1551,7 @@
15511551
"source": [
15521552
"## 4. Posterior Predictive Sampling\n",
15531553
"\n",
1554-
"The `sample_ppc()` function performs prediction on hold-out data and posterior predictive checks."
1554+
"The `sample_posterior_predictive()` function performs prediction on hold-out data and posterior predictive checks."
15551555
]
15561556
},
15571557
{
@@ -1596,14 +1596,14 @@
15961596
],
15971597
"source": [
15981598
"with model:\n",
1599-
" post_pred = pm.sample_ppc(trace, samples=500, size=len(data))"
1599+
" post_pred = pm.sample_posterior_predictive(trace, samples=500, size=len(data))"
16001600
]
16011601
},
16021602
{
16031603
"cell_type": "markdown",
16041604
"metadata": {},
16051605
"source": [
1606-
"`sample_ppc()` returns a dict with a key for every observed node:"
1606+
"`sample_posterior_predictive()` returns a dict with a key for every observed node:"
16071607
]
16081608
},
16091609
{
@@ -1718,7 +1718,7 @@
17181718
"y_shared.set_value([0, 0, 0]) # dummy values\n",
17191719
"\n",
17201720
"with model:\n",
1721-
" post_pred = pm.sample_ppc(trace, samples=500)"
1721+
" post_pred = pm.sample_posterior_predictive(trace, samples=500)"
17221722
]
17231723
},
17241724
{

docs/source/notebooks/bayes_param_survival_pymc3.ipynb

+2-2
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,7 @@
647647
],
648648
"source": [
649649
"with weibull_model:\n",
650-
" pp_weibull_trace = pm.sample_ppc(\n",
650+
" pp_weibull_trace = pm.sample_posterior_predictive(\n",
651651
" weibull_trace, samples=1500, vars=[y_obs]\n",
652652
" )"
653653
]
@@ -892,7 +892,7 @@
892892
"cens_.set_value(cens_pp)\n",
893893
"\n",
894894
"with log_logistic_model:\n",
895-
" pp_log_logistic_trace = pm.sample_ppc(\n",
895+
" pp_log_logistic_trace = pm.sample_posterior_predictive(\n",
896896
" log_logistic_trace, samples=1500, vars=[y_obs]\n",
897897
" )"
898898
]

docs/source/notebooks/bayesian_neural_network_advi.ipynb

+2-2
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@
347347
"source": [
348348
"Now that we trained our model, lets predict on the hold-out set using a posterior predictive check (PPC). \n",
349349
"\n",
350-
"1. We can use [`sample_ppc()`](../api/inference.rst) to generate new data (in this case class predictions) from the posterior (sampled from the variational estimation).\n",
350+
"1. We can use [`sample_posterior_predictive()`](../api/inference.rst) to generate new data (in this case class predictions) from the posterior (sampled from the variational estimation).\n",
351351
"2. It is better to get the node directly and build theano graph using our approximation (`approx.sample_node`) , we get a lot of speed up"
352352
]
353353
},
@@ -400,7 +400,7 @@
400400
" ann_input.set_value(X_test)\n",
401401
" ann_output.set_value(Y_test)\n",
402402
" with neural_network:\n",
403-
" ppc = pm.sample_ppc(trace, samples=500, progressbar=False)\n",
403+
" ppc = pm.sample_posterior_predictive(trace, samples=500, progressbar=False)\n",
404404
"\n",
405405
" # Use probability of > 0.5 to assume prediction of class 1\n",
406406
" pred = ppc['out'].mean(axis=0) > 0.5\n",

docs/source/notebooks/bayesian_neural_network_with_sgfs.ipynb

+2-2
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@
308308
"ann_output.set_value(Y_test)\n",
309309
"\n",
310310
"# Creater posterior predictive samples\n",
311-
"ppc = pm.sample_ppc(trace, model=neural_network, samples=500, random_seed=0)\n",
311+
"ppc = pm.sample_posterior_predictive(trace, model=neural_network, samples=500, random_seed=0)\n",
312312
"\n",
313313
"# Use probability of > 0.5 to assume prediction of class 1\n",
314314
"pred = ppc['out'].mean(axis=0) > 0.5"
@@ -395,7 +395,7 @@
395395
"ann_output.set_value(dummy_out)\n",
396396
"\n",
397397
"# Creater posterior predictive samples\n",
398-
"ppc = pm.sample_ppc(trace, model=neural_network, samples=500, random_seed=0)"
398+
"ppc = pm.sample_posterior_predictive(trace, model=neural_network, samples=500, random_seed=0)"
399399
]
400400
},
401401
{

docs/source/notebooks/constant_stochastic_gradient.ipynb

+3-3
Original file line numberDiff line numberDiff line change
@@ -524,15 +524,15 @@
524524
"samples = 1000\n",
525525
"\n",
526526
"# Creater posterior predictive samples\n",
527-
"sgfs_ppc = pm.sample_ppc(sgfs_trace, model=model, samples=samples, random_seed=0)\n",
527+
"sgfs_ppc = pm.sample_posterior_predictive(sgfs_trace, model=model, samples=samples, random_seed=0)\n",
528528
"sgfs_pred = sgfs_ppc['y_obs'].mean(axis=0)\n",
529529
"\n",
530530
"# Creater posterior predictive samples\n",
531-
"csg_ppc = pm.sample_ppc(csg_trace, model=model, samples=samples, random_seed=0)\n",
531+
"csg_ppc = pm.sample_posterior_predictive(csg_trace, model=model, samples=samples, random_seed=0)\n",
532532
"csg_pred = csg_ppc['y_obs'].mean(axis=0)\n",
533533
"\n",
534534
"# Nuts predictive samples\n",
535-
"nuts_ppc = pm.sample_ppc(nuts_trace, model=model, samples=samples, random_seed=0)\n",
535+
"nuts_ppc = pm.sample_posterior_predictive(nuts_trace, model=model, samples=samples, random_seed=0)\n",
536536
"nuts_pred = nuts_ppc['y_obs'].mean(axis=0)\n",
537537
"\n",
538538
"sgfs_diff = sgfs_pred-test_Y\n",

docs/source/notebooks/dependent_density_regression.ipynb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1191,7 +1191,7 @@
11911191
"x_lidar.set_value(lidar_pp_x[:, np.newaxis])\n",
11921192
"\n",
11931193
"with model:\n",
1194-
" pp_trace = pm.sample_ppc(trace, PP_SAMPLES, random_seed=SEED)"
1194+
" pp_trace = pm.sample_posterior_predictive(trace, PP_SAMPLES, random_seed=SEED)"
11951195
]
11961196
},
11971197
{

docs/source/notebooks/marginalized_gaussian_mixture_model.ipynb

+1-1
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@
281281
],
282282
"source": [
283283
"with model:\n",
284-
" ppc_trace = pm.sample_ppc(trace, 5000, random_seed=SEED)"
284+
" ppc_trace = pm.sample_posterior_predictive(trace, 5000, random_seed=SEED)"
285285
]
286286
},
287287
{

docs/source/notebooks/model_averaging.ipynb

+3-3
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@
423423
"\n",
424424
"We can also see that we get a column with the relative `weight` for each model (according to the first equation at the beginning of this notebook). This weights can be _vaguely_ interpreted as the probability that each model will make the correct predictions on future data. Of course this interpretation is conditional on the models used to compute the weights, if we add or remove models the weights will change. And also is dependent on the assumptions behind WAIC (or any other Information Criterion used). So try to do not overinterpret these `weights`. \n",
425425
"\n",
426-
"Now we are going to use copmuted `weights` to generate predictions based not on a single model but on the weighted set of models. This is one way to perform model averaging. Using PyMC3 we can call the `sample_ppc_w` function as follows:"
426+
"Now we are going to use copmuted `weights` to generate predictions based not on a single model but on the weighted set of models. This is one way to perform model averaging. Using PyMC3 we can call the `sample_posterior_predictive_w` function as follows:"
427427
]
428428
},
429429
{
@@ -434,7 +434,7 @@
434434
},
435435
"outputs": [],
436436
"source": [
437-
"ppc_w = pm.sample_ppc_w(traces, 1000, models,\n",
437+
"ppc_w = pm.sample_posterior_predictive_w(traces, 1000, models,\n",
438438
" weights=comp.weight.sort_index(ascending=True),\n",
439439
" progressbar=False)"
440440
]
@@ -456,7 +456,7 @@
456456
},
457457
"outputs": [],
458458
"source": [
459-
"ppc_2 = pm.sample_ppc(trace_2, 1000, model_2,\n",
459+
"ppc_2 = pm.sample_posterior_predictive(trace_2, 1000, model_2,\n",
460460
" progressbar=False)"
461461
]
462462
},

docs/source/notebooks/multilevel_modeling.ipynb

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"\n",
3535
"Radon is a radioactive gas that enters homes through contact points with the ground. It is a carcinogen that is the primary cause of lung cancer in non-smokers. Radon levels vary greatly from household to household.\n",
3636
"\n",
37-
"![radon](http://www.fix-your-radon.com/images/how_radon_enters.jpg)\n",
37+
"![radon](https://www.cgenarchive.org/uploads/2/5/2/6/25269392/7758459_orig.jpg)\n",
3838
"\n",
3939
"The EPA did a study of radon levels in 80,000 houses. Two important predictors:\n",
4040
"\n",

docs/source/notebooks/posterior_predictive.ipynb

+3-3
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@
123123
}
124124
],
125125
"source": [
126-
"ppc = pm.sample_ppc(trace, samples=500, model=model)"
126+
"ppc = pm.sample_posterior_predictive(trace, samples=500, model=model)"
127127
]
128128
},
129129
{
@@ -313,7 +313,7 @@
313313
],
314314
"source": [
315315
"# Simply running PPC will use the updated values and do prediction\n",
316-
"ppc = pm.sample_ppc(trace, model=model, samples=100)"
316+
"ppc = pm.sample_posterior_predictive(trace, model=model, samples=100)"
317317
]
318318
},
319319
{
@@ -322,7 +322,7 @@
322322
"source": [
323323
"### Mean predicted values plus error bars to give sense of uncertainty in prediction\n",
324324
"\n",
325-
"Note that these are uncertainty caused by MCMC estimation, and not from the underlying model. If we had taken more samples in `sample_ppc`, the error bars would get smaller quite quickly."
325+
"Note that these are uncertainty caused by MCMC estimation, and not from the underlying model. If we had taken more samples in `sample_posterior_predictive`, the error bars would get smaller quite quickly."
326326
]
327327
},
328328
{

docs/source/notebooks/rugby_analytics.ipynb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1212,7 +1212,7 @@
12121212
],
12131213
"source": [
12141214
"with model:\n",
1215-
" pp_trace = pm.sample_ppc(trace)"
1215+
" pp_trace = pm.sample_posterior_predictive(trace)"
12161216
]
12171217
},
12181218
{

0 commit comments

Comments
 (0)