Introduction

Author

Šimon Kucharský

Published

May 6, 2025

This project accompanies the “Bayesian Cognitive Modeling: A Practical Course” book by Lee & Wagenmakers (2013). It is not a substitute for the original book. You will need it to understand the examples, as well as read the theoretical parts to understand the machinery of Bayesian statistics. This project only implements the examples using BayesFlow in Python, but does not provide much theoretical understanding of the examples.

What is BayesFlow?

BayesFlow (https://bayesflow.org/) is a Python library allowing Amortized Bayesian Inference (ABI) using deep learning generative networks. As such, it is on the crossroads between Bayesian statistics and Machine learning.

Who is this project for?

This project is mainly helpful as an additional study material to those who want to expand their skills regarding Bayesian statistics beyond R and MCMC sampling.

Prerequisites

You will need a computer with Python installed, and some programming/Python knowledge. It is not necessary to be a wizard in Python, but you should be able to understand basic concepts and data structures.

Familiarity with Bayesian statistics is recommended. If you are a complete novice in Bayesian statistics, this project if probably not for you. That said, you can get started by reading Lee & Wagenmakers (2013) from cover to cover, and then you will be ready for the materials in this book. Other introductory books into Bayesian statistics suitable to get started include:

Familiarity with machine learning and generative neural networks is recommended but not necessary. You should be able to understand the examples without deeply understanding how the generative neural networks work.

A note on notation

The examples in the original book are accompanied by Bayesian Graphical models beautifully typeset using TikZ (Tantau, 2013). In this book, we only provide the symbolic representation of the model in terms of sampling statements such as

\[\begin{equation} \begin{aligned} \mu & \sim \text{Normal}(0, 1) \\ x & \sim \text{Normal}(\mu, 1). \end{aligned} \end{equation}\]

We will use the parametrization of probability distributions as implemented by the Python code, so that the notation in this book is consistent with the code shown in the examples. This means that we will diverge from the notation in the book, which uses the conventions for parametrizations of JAGS (Plummer et al., 2003).

Limitations

Currently it is not easy to estimate many models using BayesFlow. For example, while multilevel and mixture models are feasible with ABI (Habermann et al., 2024; Kucharský & Bürkner, 2025), the current version of BayesFlow does not provide convenient interface to estimate such models. This project provides solutions to examples which can be handled with BayesFlow without writing significant amounts of custom code. We may update this project once the interface of BayesFlow expands to cover the kinds of models that are currently left out of this project.

References

Gelman, A., Carlin, J. B., Stern, H. S., & Rubin, D. B. (1995). Bayesian Data Analysis (3rd ed.). Chapman; Hall/CRC.
Habermann, D., Schmitt, M., Kühmichel, L., Bulling, A., Radev, S. T., & Bürkner, P.-C. (2024). Amortized bayesian multilevel models. arXiv Preprint arXiv:2408.13230.
Kruschke, J. K. (2014). Doing bayesian data analysis: A tutorial with R, JAGS, and Stan.
Kucharský, Š., & Bürkner, P. C. (2025). Amortized bayesian mixture models. arXiv Preprint arXiv:2501.10229.
Lambert, B. (2018). A student’s guide to Bayesian statistics. SAGE Publications Ltd.
Lee, M. D., & Wagenmakers, E.-J. (2013). Bayesian Cognitive Modeling: A Practical Course. Cambridge University Press.
McElreath, R. (2018). Statistical rethinking: A Bayesian course with examples in R and Stan. Chapman; Hall/CRC.
Plummer, M. et al. (2003). JAGS: A program for analysis of Bayesian graphical models using Gibbs sampling. Proceedings of the 3rd International Workshop on Distributed Statistical Computing, 124, 1–10.
Tantau, T. (2013). The TikZ and PGF packages: Manual for version 3.0.0. http://sourceforge.net/projects/pgf/

Reuse