The Compositional Structure of Bayesian Inference

Authors Dylan Braithwaite, Jules Hedges, Toby St Clere Smithe

Thumbnail PDF


  • Filesize: 0.74 MB
  • 15 pages

Document Identifiers

Author Details

Dylan Braithwaite
  • Department of Computer and Information Sciences, University of Strathclyde, Glasgow, UK
Jules Hedges
  • Department of Computer and Information Sciences, University of Strathclyde, Glasgow, UK
Toby St Clere Smithe
  • Topos Institute, Berkeley, CA, USA
  • Department of Experimental Psychology, University of Oxford, UK

Cite AsGet BibTex

Dylan Braithwaite, Jules Hedges, and Toby St Clere Smithe. The Compositional Structure of Bayesian Inference. In 48th International Symposium on Mathematical Foundations of Computer Science (MFCS 2023). Leibniz International Proceedings in Informatics (LIPIcs), Volume 272, pp. 24:1-24:15, Schloss Dagstuhl – Leibniz-Zentrum für Informatik (2023)


Bayes' rule tells us how to invert a causal process in order to update our beliefs in light of new evidence. If the process is believed to have a complex compositional structure, we may observe that the inversion of the whole can be computed piecewise in terms of the component processes. We study the structure of this compositional rule, noting that it relates to the lens pattern in functional programming. Working in a suitably general axiomatic presentation of a category of Markov kernels, we see how we can think of Bayesian inversion as a particular instance of a state-dependent morphism in a fibred category. We discuss the compositional nature of this, formulated as a functor on the underlying category and explore how this can used for a more type-driven approach to statistical inference.

Subject Classification

ACM Subject Classification
  • Theory of computation → Categorical semantics
  • Mathematics of computing → Probabilistic representations
  • Mathematics of computing → Bayesian computation
  • monoidal categories
  • probabilistic programming
  • Bayesian inference


  • Access Statistics
  • Total Accesses (updated on a weekly basis)
    PDF Downloads


  1. Andre M. Bastos, W. Martin Usrey, Rick A. Adams, George R. Mangun, Pascal Fries, and Karl J. Friston. Canonical microcircuits for predictive coding. Neuron, 2012. URL:
  2. Francis Borceux. Handbook of Categorical Algebra 2. Categories and Structures. Cambridge University Press, 1994. URL:
  3. Dylan Braithwaite and Jules Hedges. Dependent Bayesian Lenses: Categories of Bidirectional Markov Kernels with Canonical Bayesian Inversion, 2022. URL:
  4. Matteo Capucci, Bruno Gavranović, Jules Hedges, and Eigil Fjeldgren Rischel. Towards Foundations of Categorical Cybernetics. ACT21, 2022. URL:
  5. Kenta Cho and Bart Jacobs. Disintegration and Bayesian inversion via string diagrams. MSCS, 2019. URL:
  6. Geoffrey S. H. Cruttwell, Bruno Gavranović, Neil Ghani, Paul Wilson, and Fabio Zanasi. Categorical foundations of gradient-based learning. ESOP22, 2022. URL:
  7. J. Nathan Foster, Michael B. Greenwald, Jonathan T. Moore, Benjamin C. Pierce, and Alan Schmitt. Combinators for bidirectional tree transformations: A linguistic approach to the view-update problem. TOPLAS, 2007. URL:
  8. Tobias Fritz. A synthetic approach to Markov kernels, conditional independence and theorems on sufficient statistics. Advances in Mathematics, 2020. URL:
  9. Neil Ghani, Jules Hedges, Viktor Winschel, and Philipp Zahn. Compositional game theory. LICS18, 2018. URL:
  10. Michèlle Giry. A categorical approach to probability theory. Categorical aspects of Topology and Analysis, 1982. URL:
  11. Jules Hedges and Riu Rodríguez Sakamoto. Value Iteration Is Optic Composition. ACT22, 2023. Forthcoming. Google Scholar
  12. Bart Jacobs. Categorical Logic and Type Theory. Elsevier Science, 1999. Google Scholar
  13. Beren Millidge, Tommaso Salvatori, Yuhang Song, Rafal Bogacz, and Thomas Lukasiewicz. Predictive coding: Towards a future of deep learning beyond backpropagation? IJCAI22, 2022. URL:
  14. Joe Moeller and Christina Vasilakopoulou. Monoidal Grothendieck construction, 2020. Google Scholar
  15. Robert Rosenbaum. On the relationship between predictive coding and backpropagation. PLoS ONE, 2022. URL:
  16. Toby St. Clere Smithe. Bayesian updates compose optically, 2020. URL:
  17. Toby St. Clere Smithe. Compositional Active Inference I: Bayesian Lenses. Statistical Games, 2022. URL:
  18. Toby St Clere Smithe. Mathematical Foundations for a Compositional Account of the Bayesian Brain. PhD thesis, University of Oxford, 2023. URL:
  19. David I. Spivak. Generalized Lens Categories via functors 𝒞^ op → Cat, 2019. URL:
  20. Jan-Willem van de Meent, Brooks Paige, Hongseok Yang, and Frank Wood. An Introduction to Probabilistic Programming, 2021. URL:
  21. H. Wu and F. Noé. Maximum a posteriori estimation for markov chains based on gaussian markov random fields. ICCS10, 2010. URL:
Questions / Remarks / Feedback

Feedback for Dagstuhl Publishing

Thanks for your feedback!

Feedback submitted

Could not send message

Please try again later or send an E-mail