Submitted:
24 November 2024
Posted:
26 November 2024
You are already at the latest version
Abstract
Keywords:
1. Introduction
2. Active Inference with POMDP’s
2.1. POMDPs in Active Inference

2.2. Perception in Active Inference
2.3. Action in Active Inference
2.4. Learning in Active Inference
3. Using ActiveInference.jl
3.1. Creating and using a POMDP












3.2. Simulation with ActionModels





3.3. Model Fitting with ActionModels







4. Usage Example
4.1. Setting up Environment and Agent



















4.2. Simulating Behaviour


4.3. Fitting the Model to Data










5. Discussion
Author Contributions
Funding
Institutional Review Board Statement
Informed Consent Statement
Data Availability Statement
Conflicts of Interest
Abbreviations
| AIF | Active Inference |
| FEP | Free Energy Principle |
| VFE | Variational free energy |
| EFE | Expected free energy |
| MCMC | Markov Chain Monte Carlo |
| POMDP | Partially-Observed Markov decision Process |
References
- Parr, T.; Pezzulo, G.; Friston, K.J. Active Inference: The Free Energy Principle in Mind, Brain, and Behavior; The MIT Press, 2022. [CrossRef]
- Friston, K.; FitzGerald, T.; Rigoli, F.; Schwartenbeck, P.; O’Doherty, J.; Pezzulo, G. Active inference and learning. Neuroscience & Biobehavioral Reviews 2016, 68, 862–879. [CrossRef]
- Friston, K.; FitzGerald, T.; Rigoli, F.; Schwartenbeck, P.; Pezzulo, G. Active inference: A process theory. Neural Computation 2017. [CrossRef]
- Friston, K.J.; Stephan, K.E. Free-energy and the brain. Synthese 2007, 159, 417–458. [CrossRef]
- Friston, K. The free-energy principle: a unified brain theory? Nature Reviews Neuroscience 2010, 11, 127–138. Number: 2 Publisher: Nature Publishing Group, . [CrossRef]
- Friston, K. The free-energy principle: a rough guide to the brain? Trends in Cognitive Sciences 2009, 13, 293–301. [CrossRef]
- Friston, K. A free energy principle for a particular physics, 2019. arXiv . [CrossRef]
- Friston, K.; Da Costa, L.; Sajid, N.; Heins, C.; Ueltzhöffer, K.; Pavliotis, G.A.; Parr, T. The free energy principle made simpler but not too simple. Physics Reports 2023, 1024, 1–29. [CrossRef]
- Friston, K.; Kiebel, S. Predictive coding under the free-energy principle. Philosophical Transactions of the Royal Society B: Biological Sciences 2009, 364, 1211–1221. Publisher: Royal Society, . [CrossRef]
- Karl, F. A Free Energy Principle for Biological Systems. Entropy (Basel, Switzerland) 2012, 14, 2100–2121. [CrossRef]
- Corcoran, A.W.; Pezzulo, G.; Hohwy, J. From allostatic agents to counterfactual cognisers: active inference, biological regulation, and the origins of cognition. Biology & Philosophy 2020, 35, 32. [CrossRef]
- Heins, C.; Millidge, B.; Da Costa, L.; Mann, R.P.; Friston, K.J.; Couzin, I.D. Collective behavior from surprise minimization. Proceedings of the National Academy of Sciences 2024, 121, e2320239121. Publisher: Proceedings of the National Academy of Sciences, . [CrossRef]
- Patzelt, E.H.; Hartley, C.A.; Gershman, S.J. Computational Phenotyping: Using Models to Understand Individual Differences in Personality, Development, and Mental Illness. Personality Neuroscience 2018, 1, e18. [CrossRef]
- Schwartenbeck, P.; Friston, K. Computational Phenotyping in Psychiatry: A Worked Example. eNeuro 2016, 3, ENEURO.0049–16.2016. [CrossRef]
- Albarracin, M.; Demekas, D.; Ramstead, M.J.D.; Heins, C. Epistemic Communities under Active Inference. Entropy 2022, 24, 476. Number: 4 Publisher: Multidisciplinary Digital Publishing Institute, . [CrossRef]
- Lanillos, P.; Meo, C.; Pezzato, C.; Meera, A.A.; Baioumy, M.; Ohata, W.; Tschantz, A.; Millidge, B.; Wisse, M.; Buckley, C.L.; Tani, J. Active Inference in Robotics and Artificial Agents: Survey and Challenges, 2021. arXiv:2112.01871 [cs], . [CrossRef]
- Friston, K.; Stephan, K.; Li, B.; Daunizeau, J. Generalised Filtering. Mathematical Problems in Engineering 2010, 2010, 1–34. [CrossRef]
- Waade, P.T.; Mikus, N.; Mathys, C. Inferring in Circles: Active Inference in Continuous State Space Using Hierarchical Gaussian Filtering of Sufficient Statistics. Machine Learning and Principles and Practice of Knowledge Discovery in Databases; Kamp, M.; Koprinska, I.; Bibal, A.; Bouadi, T.; Frénay, B.; Galárraga, L.; Oramas, J.; Adilova, L.; Krishnamurthy, Y.; Kang, B.; Largeron, C.; Lijffijt, J.; Viard, T.; Welke, P.; Ruocco, M.; Aune, E.; Gallicchio, C.; Schiele, G.; Pernkopf, F.; Blott, M.; Fröning, H.; Schindler, G.; Guidotti, R.; Monreale, A.; Rinzivillo, S.; Biecek, P.; Ntoutsi, E.; Pechenizkiy, M.; Rosenhahn, B.; Buckley, C.; Cialfi, D.; Lanillos, P.; Ramstead, M.; Verbelen, T.; Ferreira, P.M.; Andresini, G.; Malerba, D.; Medeiros, I.; Fournier-Viger, P.; Nawaz, M.S.; Ventura, S.; Sun, M.; Zhou, M.; Bitetta, V.; Bordino, I.; Ferretti, A.; Gullo, F.; Ponti, G.; Severini, L.; Ribeiro, R.; Gama, J.; Gavaldà, R.; Cooper, L.; Ghazaleh, N.; Richiardi, J.; Roqueiro, D.; Saldana Miranda, D.; Sechidis, K.; Graça, G., Eds.; Springer International Publishing: Cham, 2021; Communications in Computer and Information Science, pp. 810–818. [CrossRef]
- Weber, L.A.; Waade, P.T.; Legrand, N.; Møller, A.H.; Stephan, K.E.; Mathys, C. The generalized Hierarchical Gaussian Filter, 2023. arXiv:2305.10937 [cs, q-bio], . [CrossRef]
- Friston, K.J.; Trujillo-Barreto, N.; Daunizeau, J. DEM: A variational treatment of dynamic systems. NeuroImage 2008, 41, 849–885. [CrossRef]
- Inc, T.M. MATLAB version: 9.13.0 (R2022b), 2022.
- Penny, W.D.; Friston, K.J.; Ashburner, J.T.; Kiebel, S.J.; Nichols, T.E. Statistical Parametric Mapping: The Analysis of Functional Brain Images; Elsevier, 2011. Google-Books-ID: G_qdEsDlkp0C.
- Heins, C.; Millidge, B.; Demekas, D.; Klein, B.; Friston, K.; Couzin, I.D.; Tschantz, A. pymdp: A Python library for active inference in discrete state spaces. Journal of Open Source Software 2022, 7, 4098. [CrossRef]
- Rossum, G.v.; Drake, F.L. The Python language reference, release 3.0.1 [repr.] ed.; Number Pt. 2 in Python documentation manual / Guido van Rossum; Fred L. Drake [ed.], Python Software Foundation: Hampton, NH, 2010.
- Gregoretti, F.; Pezzulo, G.; Maisto, D. cpp-AIF: A multi-core C++ implementation of Active Inference for Partially Observable Markov Decision Processes. Neurocomputing 2024, 568, 127065. [CrossRef]
- Josuttis, N.M. The C++ Standard Library: A Tutorial and Reference; Addison-Wesley, 2012. Google-Books-ID: 9DEJKhasp7gC.
- Bagaev, D.; Podusenko, A.; Vries, B.d. RxInfer: A Julia package for reactive real-time Bayesian inference. Journal of Open Source Software 2023, 8, 5161. [CrossRef]
- Bezanson, J.; Karpinski, S.; Shah, V.; Edelman, A. Julia Language Documentation 2016.
- van de Laar, T.W.; de Vries, B. Simulating Active Inference Processes by Message Passing. Frontiers in Robotics and AI 2019, 6. Publisher: Frontiers, . [CrossRef]
- Vanderbroeck, M.; Baioumy, M.; Lans, D.v.d.; Rooij, R.d.; Werf, T.v.d. Active inference for Robot control: A Factor Graph Approach. Student Undergraduate Research E-journal! 2019, 5, 1–5. [CrossRef]
- van de Laar, T.; Şenöz; Özçelikkale, A.; Wymeersch, H. Chance-Constrained Active Inference. Neural Computation 2021, 33, 2710–2735. [CrossRef]
- Busemeyer, J.R.; Diederich, A. Cognitive Modeling; SAGE, 2010. Google-Books-ID: R7KDF35g5LQC.
- Smith, R.; Friston, K.J.; Whyte, C.J. A step-by-step tutorial on active inference and its application to empirical data. Journal of Mathematical Psychology 2022, 107, 102632. [CrossRef]
- Lee, M.D.; Wagenmakers, E.J. Bayesian Cognitive Modeling: A Practical Course, 1 ed.; Cambridge University Press, 2014. [CrossRef]
- Blei, D.M.; Kucukelbir, A.; McAuliffe, J.D. Variational Inference: A Review for Statisticians. Journal of the American Statistical Association 2017, 112, 859–877. arXiv:1601.00670 [cs, stat], . [CrossRef]
- Lattner, C.; Adve, V. LLVM: a compilation framework for lifelong program analysis & transformation. International Symposium on Code Generation and Optimization, 2004. CGO 2004., 2004, pp. 75–86. [CrossRef]
- R Core Team. R: A Language and Environment for Statistical Computing; R Foundation for Statistical Computing: Vienna, Austria, 2021.
- Carpenter, B.; Gelman, A.; Hoffman, M.D.; Lee, D.; Goodrich, B.; Betancourt, M.; Brubaker, M.; Guo, J.; Li, P.; Riddell, A. Stan: A Probabilistic Programming Language. Journal of Statistical Software 2017, 76, 1–32. [CrossRef]
- Ge, H.; Xu, K.; Ghahramani, Z. Turing: A Language for Flexible Probabilistic Inference. Proceedings of the Twenty-First International Conference on Artificial Intelligence and Statistics. PMLR, 2018, pp. 1682–1690. ISSN: 2640-3498.
- Hoffman, M.D.; Gelman, A. The No-U-Turn Sampler: Adaptively Setting Path Lengths in Hamiltonian Monte Carlo 2014.
- Mathys, C.; Weber, L. Hierarchical Gaussian Filtering of Sufficient Statistic Time Series for Active Inference. Active Inference; Verbelen, T.; Lanillos, P.; Buckley, C.L.; De Boom, C., Eds.; Springer International Publishing: Cham, 2020; Communications in Computer and Information Science, pp. 52–58. [CrossRef]
- Rescorla, R.A. A theory of Pavlovian conditioning: Variations in the effectiveness of reinforcement and non-reinforcement. Classical conditioning, Current research and theory 1972, 2, 64–69. Publisher: Appleton-Century-Crofts.
- Frässle, S.; Aponte, E.A.; Bollmann, S.; Brodersen, K.H.; Do, C.T.; Harrison, O.K.; Harrison, S.J.; Heinzle, J.; Iglesias, S.; Kasper, L.; Lomakina, E.I.; Mathys, C.; Müller-Schrader, M.; Pereira, I.; Petzschner, F.H.; Raman, S.; Schöbi, D.; Toussaint, B.; Weber, L.A.; Yao, Y.; Stephan, K.E. TAPAS: An Open-Source Software Package for Translational Neuromodeling and Computational Psychiatry. Frontiers in Psychiatry 2021, 12. Publisher: Frontiers, . [CrossRef]
- Smith, R.; Schwartenbeck, P.; Parr, T.; Friston, K.J. An Active Inference Approach to Modeling Structure Learning: Concept Learning as an Example Case. Frontiers in Computational Neuroscience 2020, 14. Publisher: Frontiers, . [CrossRef]
- Neacsu, V.; Mirza, M.B.; Adams, R.A.; Friston, K.J. Structure learning enhances concept formation in synthetic Active Inference agents. PLOS ONE 2022, 17. Publisher: PLOS, . [CrossRef]
- Xia, R.; Zhang, Y.; Liu, X.; Yang, B. A survey of sum–product networks structural learning. Neural Networks 2023, 164, 645–666. [CrossRef]
- Friston, K.J.; Da Costa, L.; Tschantz, A.; Kiefer, A.; Salvatori, T.; Neacsu, V.; Koudahl, M.; Heins, C.; Sajid, N.; Markovic, D.; Parr, T.; Verbelen, T.; Buckley, C.L. Supervised structure learning, 2023. arXiv:2311.10300 [cs], . [CrossRef]
- Serrano, S.A.; Santiago, E.; Martinez-Carranza, J.; Morales, E.F.; Sucar, L.E. Knowledge-Based Hierarchical POMDPs for Task Planning. Journal of Intelligent & Robotic Systems 2021, 101, 82. [CrossRef]
- Friston, K.J.; Rosch, R.; Parr, T.; Price, C.; Bowman, H. Deep temporal models and active inference. Neuroscience & Biobehavioral Reviews 2017, 77, 388–402. [CrossRef]
- Friston, K.; Mattout, J.; Trujillo-Barreto, N.; Ashburner, J.; Penny, W. Variational free energy and the Laplace approximation. NeuroImage 2007, 34, 220–234. [CrossRef]
- Friston, K.J. Variational filtering. NeuroImage 2008, 41, 747–766. [CrossRef]
- Tu, S. The Dirichlet-Multinomial and Dirichlet-Categorical models for Bayesian inference 2014.
- Smith, R.; Badcock, P.; Friston, K.J. Recent advances in the application of predictive coding and active inference models within clinical neuroscience. Psychiatry and Clinical Neurosciences 2021, 75, 3–13. _eprint: https://onlinelibrary.wiley.com/doi/pdf/10.1111/pcn.13138, . [CrossRef]
- Deacon, R.M.J.; Rawlins, J.N.P. T-maze alternation in the rodent. Nature Protocols 2006, 1, 7–12. Publisher: Nature Publishing Group, . [CrossRef]
- Lin, M.H.; Liran, O.; Bauer, N.; Baker, T.E. Power dynamics of theta oscillations during goal-directed navigation in freely moving humans: A mobile EEG-virtual reality T-maze study, 2021. Pages: 2021.10.05.463245 Section: New Results, . [CrossRef]
- Ghafari, M.; Falsafi, S.K.; Szodorai, E.; Kim, E.J.; Li, L.; Höger, H.; Berger, J.; Fuchs, K.; Sieghart, W.; Lubec, G. Formation of GABAA receptor complexes containing 1 and 5 subunits is paralleling a multiple T-maze learning task in mice. Brain Structure and Function 2017, 222, 549–561. [CrossRef]
- Sharma, S.; Rakoczy, S.; Brown-Borg, H. Assessment of spatial memory in mice. Life Sciences 2010, 87, 521–536. [CrossRef]
- Friston, K.; Da Costa, L.; Hafner, D.; Hesp, C.; Parr, T. Sophisticated Inference. arXiv:2006.04120 [cs, q-bio] 2020. arXiv: 2006.04120.
- Vehtari, A.; Simpson, D.; Gelman, A.; Yao, Y.; Gabry, J. Pareto Smoothed Importance Sampling, 2024. arXiv:1507.02646, . [CrossRef]
- Aponte, E.A.; Yao, Y.; Raman, S.; Frässle, S.; Heinzle, J.; Penny, W.D.; Stephan, K.E. An introduction to thermodynamic integration and application to dynamic causal models. Cognitive Neurodynamics 2021, 16, 1. [CrossRef]
- Daunizeau, J.; Ouden, H.E.M.d.; Pessiglione, M.; Kiebel, S.J.; Stephan, K.E.; Friston, K.J. Observing the Observer (I): Meta-Bayesian Models of Learning and Decision-Making. PLOS ONE 2010, 5, e15554. Publisher: Public Library of Science, . [CrossRef]
- Wilson, R.C.; Collins, A.G. Ten simple rules for the computational modeling of behavioral data. eLife 2019, 8, e49547. Publisher: eLife Sciences Publications, Ltd, . [CrossRef]
- Hess, A.J.; Iglesias, S.; Köchli, L.; Marino, S.; Müller-Schrader, M.; Rigoux, L.; Mathys, C.; Harrison, O.K.; Heinzle, J.; Frässle, S.; Stephan, K.E. Bayesian Workflow for Generative Modeling in Computational Psychiatry, 2024. Pages: 2024.02.19.581001 Section: New Results, . [CrossRef]
- TuringLang/ParetoSmooth.jl, 2024. original-date: 2021-06-04T22:08:47Z.
- Palmeri, T.J.; Love, B.C.; Turner, B.M. Model-based cognitive neuroscience. Journal of mathematical psychology 2017, 76, 59–64. [CrossRef]
- Kagan, B.J.; Kitchen, A.C.; Tran, N.T.; Habibollahi, F.; Khajehnejad, M.; Parker, B.J.; Bhat, A.; Rollo, B.; Razi, A.; Friston, K.J. In vitro neurons learn and exhibit sentience when embodied in a simulated game-world. Neuron 2022, 110, 3952–3969.e8. [CrossRef]
- Waade, P.T.; Olesen, C.L.; Laursen, J.E.; Nehrer, S.W.; Heins, C.; Friston, K.; Mathys, C. As One and Many: Relating Individual and Emergent Group-Level Generative Models in Active Inference, 2024. [CrossRef]







Disclaimer/Publisher’s Note: The statements, opinions and data contained in all publications are solely those of the individual author(s) and contributor(s) and not of MDPI and/or the editor(s). MDPI and/or the editor(s) disclaim responsibility for any injury to people or property resulting from any ideas, methods, instructions or products referred to in the content. |
© 2024 by the authors. Licensee MDPI, Basel, Switzerland. This article is an open access article distributed under the terms and conditions of the Creative Commons Attribution (CC BY) license (http://creativecommons.org/licenses/by/4.0/).
