ActiveInference.jl represents a significant advancement in computational modeling for cognitive neuroscience and computational psychiatry, providing a robust Julia implementation of active inference models based on Partially Observable Markov Decision Processes (POMDPs) [1][2][3]. Developed by the ComputationalPsychiatry research group, this package bridges the gap between theoretical active inference frameworks and practical empirical data analysis, offering researchers a high-performance platform for simulating intelligent behavior and fitting complex cognitive models to experimental data [1][3].
Active inference is a normative theory of brain function rooted in the free energy principle, which posits that biological agents minimize variational free energy to maintain their existence and adapt to environmental changes [2][4][3]. The framework treats perception and action as unified processes under a single imperative: minimizing surprise or uncertainty about sensory observations [4][5][3].
The core mathematical foundation rests on two key quantities [5][3]:
Variational Free Energy (VFE): Quantifies how well an agent's internal generative model explains incoming sensory observations, serving as an upper bound on surprise [5][3]. The VFE decomposes into accuracy (how well the model predicts observations) and complexity (how much beliefs must change to maintain accuracy) [3].
Expected Free Energy (EFE): Represents the free energy expected under different action policies, naturally balancing exploratory behavior (information gain) and exploitative behavior (goal achievement) [5][3]. This balance emerges automatically from the mathematics rather than requiring explicit engineering as in reinforcement learning [6].
ActiveInference.jl implements active inference using discrete state-space POMDPs, which represent environments as sets of hidden states that generate observable outcomes [1][3]. The generative model consists of five key matrices [3]:
- A matrix (observation model): Encodes how environmental states generate observations
- B matrix (transition model): Describes state-to-state transitions contingent on actions
- C vector (preference prior): Specifies prior preferences over observations
- D vector (state prior): Initial beliefs about environmental states
- E vector (habit prior): Prior preferences over action policies
ActiveInference.jl draws significant inspiration from the Python pymdp library while leveraging Julia's unique advantages for scientific computing [1][3]. The package implements Coordinate Ascent Variational Inference (CAVI) using fixed-point iteration to approximate posterior beliefs about environmental states [3].
The central AIF object structure contains all generative model components, dynamic belief states, and inference settings [3]. Key algorithmic components include:
State Inference: Uses variational message passing to update beliefs about hidden states given observations, employing a mean-field approximation that factorizes across time steps and state factors [3].
Policy Inference: Evaluates expected free energy for each possible action sequence, with policy selection governed by a softmax transformation of negative expected free energies [3].
Parameter Learning: Updates Dirichlet concentration parameters for model matrices based on observed outcomes, enabling adaptive learning of environmental structure [3].
A distinguishing feature of ActiveInference.jl is its seamless integration with Julia's computational ecosystem [2][3]. The package leverages Turing.jl, Julia's powerful probabilistic programming framework, enabling sophisticated Bayesian parameter estimation using both sampling-based (MCMC) and variational methods [3][7][8].
This integration addresses the "two-language problem" common in computational modeling, where high-level languages require external compilers for performance or auto-differentiability [3]. Julia's native auto-differentiation and just-in-time (JIT) compilation provide near-C performance while maintaining Python-like ease of use [9][10][11].
Julia's performance advantages are particularly relevant for active inference modeling, which involves computationally intensive belief updating and policy evaluation [9][10]. The language's JIT compilation creates specialized code for specific data types, achieving performance comparable to compiled languages while retaining dynamic flexibility [11].
Benchmark studies demonstrate Julia's exceptional performance in scientific computing contexts, often achieving 5-10x speed improvements over Python for machine learning tasks and performance comparable to C++ and Fortran for numerical computations [10].
ActiveInference.jl provides intuitive functions for constructing and simulating POMDP-based active inference agents [1][3]. The core workflow involves:
Initialization: The init_aif() function creates AIF objects with specified generative model matrices and hyperparameters [3]. Helper functions like create_matrix_templates() generate appropriately dimensioned matrices for different environment configurations [1][3].
Simulation Loop: The package implements a standard perception-action cycle through functions like infer_states!(), infer_policies!(), update_parameters!(), and sample_action!() [3]. This modular design allows researchers to examine intermediate belief states and customize inference procedures.
Multi-Modal Environments: The package supports multi-factorial state spaces and multi-modal observations, enabling modeling of complex environments with multiple interacting factors [1][3].
A crucial innovation of ActiveInference.jl is its capability for fitting models to empirical behavioral data [2][3]. Through integration with ActionModels.jl, researchers can perform sophisticated Bayesian parameter estimation and model comparison [3][12].
Bayesian Inference: The package supports both MCMC sampling and variational inference methods for parameter estimation, leveraging Turing.jl's advanced inference algorithms [3][7].
Model Comparison: Researchers can compare different active inference models or contrast them with other cognitive models like reinforcement learning or Hierarchical Gaussian Filtering within the same framework [3][13].
Hierarchical Modeling: The integration supports hierarchical Bayesian models that can capture individual differences and group-level effects in computational psychiatry applications [3][12].
ActiveInference.jl is particularly valuable for computational psychiatry research, where researchers seek to understand psychiatric conditions through computational models of aberrant cognition [14][15][16]. The package enables researchers to model how differences in prior beliefs, learning rates, or uncertainty processing might underlie various psychiatric symptoms [3].
The package is part of the Translational Algorithms for Psychiatry-Advancing Science (TAPAS) ecosystem, positioning it within a broader framework of computational psychiatry tools [3][16].
The package facilitates research into fundamental cognitive processes like perception, learning, and decision-making [3]. Researchers can model how agents navigate uncertain environments, balance exploration and exploitation, and adapt to changing contingencies [17][18].
The T-maze example implemented in the package demonstrates how active inference agents can solve navigation problems while learning about reward probabilities and state transitions [17][3].
ActiveInference.jl enables theoretical investigations into the properties of active inference agents, such as their behavior under different parameter settings or environmental conditions [3]. The package's simulation capabilities support systematic exploration of parameter spaces and sensitivity analyses.
ActiveInference.jl complements several other Julia packages in the computational psychiatry ecosystem [3][12]:
ActionModels.jl: Provides a general framework for cognitive and behavioral modeling with integration to Turing.jl for Bayesian inference [12][19].
HierarchicalGaussianFiltering.jl: Implements the Hierarchical Gaussian Filter, another prominent computational psychiatry model [3][13].
POMDPs.jl: Offers a general framework for POMDP problems with extensive solver libraries [20][21].
ActiveInference.jl builds upon and extends capabilities available in other active inference implementations [3]:
SPM/DEM (MATLAB): The original implementation with comprehensive functionality but limited to MATLAB ecosystem [3].
pymdp (Python): A flexible Python implementation that inspired ActiveInference.jl's design but lacks integrated parameter estimation capabilities [22][3].
RxInfer.jl: A factor graph-based approach to active inference with high computational efficiency but more specialized focus [23][24].
The package has seen rapid development, with version 0.1.2 released in January 2025 and ongoing improvements to documentation and functionality [1]. The recent publication in Entropy (January 2025) provides comprehensive documentation of the package's theoretical foundations and practical applications [2][3].
Recent research demonstrates the package's utility for modeling collective behavior and multi-agent systems, extending active inference principles to group-level phenomena [25]. This represents an important expansion of active inference beyond individual agents to social and collective dynamics.
The developers have outlined several areas for future enhancement [3]:
Extended Generative Models: Implementation of continuous-time active inference and more sophisticated generative model architectures beyond discrete POMDPs.
Performance Optimization: Continued optimization of inference algorithms and integration with Julia's evolving high-performance computing capabilities.
Educational Resources: Development of comprehensive tutorials and educational materials to broaden adoption in cognitive science and computational psychiatry communities.
Performance: Julia's JIT compilation provides significant performance advantages over interpreted languages while maintaining ease of use [9][10][11].
Integration: Seamless integration with advanced Bayesian inference tools through Turing.jl ecosystem [3][7].
Flexibility: Support for complex, multi-factorial models with customizable inference procedures [3].
Open Source: Full transparency and extensibility through open-source development [1].
Learning Curve: Requires familiarity with both active inference theory and Julia programming [3].
Model Scope: Currently limited to discrete POMDP implementations, though extensions are planned [3].
Documentation: While comprehensive, the documentation assumes significant background knowledge in computational modeling [1][3].
Julia execution shares the usual risks of running generated simulation code: use trusted GNN inputs, keep dependencies updated, and avoid embedding secrets in model files or logs you redistribute.
ActiveInference.jl represents a significant contribution to computational cognitive science, providing researchers with a powerful, performant, and theoretically grounded tool for active inference modeling [1][2][3]. By combining Julia's computational advantages with sophisticated Bayesian inference capabilities, the package enables new possibilities for empirical research in computational psychiatry and cognitive neuroscience [3].
The package's integration with the broader Julia ecosystem for cognitive modeling positions it as a cornerstone tool for researchers seeking to understand the computational principles underlying intelligent behavior and psychiatric dysfunction [3][12]. As the field of computational psychiatry continues to evolve, ActiveInference.jl provides essential infrastructure for translating theoretical insights into empirical discoveries and clinical applications.
[1] https://github.com/ComputationalPsychiatry/ActiveInference.jl [2] https://www.mdpi.com/1099-4300/27/1/62 [3] https://github.com/ComputationalPsychiatry/ActionModels.jl [4] https://pmc.ncbi.nlm.nih.gov/articles/PMC8956124/ [5] https://nms.kcl.ac.uk/osvaldo.simeone/freeenergymin.pdf [6] https://direct.mit.edu/books/oa-monograph/chapter-pdf/2246582/c004100_9780262369978.pdf [7] https://research.aalto.fi/fi/datasets/turinglangturingjl-v0240 [8] https://www.sciencedirect.com/science/article/pii/S0925231.3.020903 [9] https://discourse.julialang.org/t/blog-post-rust-vs-julia-in-scientific-computing/101711 [10] https://github.com/JuliaPOMDP/POMDPs.jl [11] https://pymdp-rtd.readthedocs.io/en/latest/notebooks/pymdp_fundamentals.html [12] http://proceedings.mlr.press/v72/donselaar18a/donselaar18a.pdf [13] https://github.com/TuringLang [14] https://www.reddit.com/r/reinforcementlearning/comments/1fbu536/any_successful_story_of_active_inference_free/ [15] https://www.nature.com/articles/s41467-023-40141-z [16] https://blogs.illinois.edu/view/6204/2112694587 [17] https://siit.co/blog/mastering-julia-a-comprehensive-guide-to-modern-scientific-computing/8890 [18] https://roboti.us/lab/papers/TheodorouADPRL13.pdf [19] https://github.com/ComputationalPsychiatry/RegressionDynamicCausalModeling.jl [20] https://pretalx.com/juliacon2024/talk/Z8MJK8/ [21] https://www.sciencedirect.com/science/article/pii/S0022249621000973 [22] https://pmc.ncbi.nlm.nih.gov/articles/PMC5167251/ [23] https://direct.mit.edu/books/oa-monograph/chapter-pdf/2246581/c003400_9780262369978.pdf [24] https://www.preprints.org/manuscript/202411.1880/v1 [25] https://www.youtube.com/watch?v=XxA93mlv9Mc [26] https://github.com/ilabcode/ActiveInference.jl [27] https://pubmed.ncbi.nlm.nih.gov/39851682/ [28] https://www.youtube.com/watch?v=MRTULbP1ZKs [29] https://juliapackages.com/p/activeinference [30] https://www.ewi-psy.fu-berlin.de/en/psychologie/einrichtungen/ccnb/seminar/2022_05_09_Ryan-Smith.html [31] https://discovery.ucl.ac.uk/id/eprint/10143770/1/1-s2.0-S0022249621000973-main.pdf [32] https://medicine.yale.edu/psychiatry/education/programs-and-initiatives/map/support/ryan/ [33] https://direct.mit.edu/neco/article/36/5/963/119791/An-Overview-of-the-Free-Energy-Principle-and [34] https://arxiv.org/pdf/2207.06415.pdf [35] https://scholar.harvard.edu/files/schwartz/files/8-freeenergy.pdf [36] https://publish.obsidian.md/active-inference/knowledge_base/mathematics/variational_free_energy [37] https://paperswithcode.com/paper/pymdp-a-python-library-for-active-inference [38] https://enccs.github.io/julia-for-hpc/ [39] https://julialang.org [40] https://juliahighperformance.com [41] https://siit.co/blog/julia-programming-a-high-performance-language-for-scientific-computing-and-data-science/9010 [42] https://discovery.ucl.ac.uk/id/eprint/10048538/1/s00422-018-0753-2.pdf [43] https://juliapackages.com/p/pomdps [44] https://www.frontiersin.org/journals/robotics-and-ai/articles/10.3389/frobt.2019.00020/full [45] https://pmc.ncbi.nlm.nih.gov/articles/PMC6060791/ [46] https://www.frontiersin.org/journals/computational-neuroscience/articles/10.3389/fncom.2020.574372/full [47] https://www.biorxiv.org/content/10.1101/2024.08.18.608439v1.full-text [48] https://github.com/ReactiveBayes/RxInfer.jl [49] https://pdfs.semanticscholar.org/4eb5/2dd3d55ace27c5d868d7a3f5e9f7546525e4.pdf [50] https://www.mdpi.com/1099-4300/27/2/143 [51] https://discourse.julialang.org/t/gui-developer-for-computational-psychiatry-with-the-julia-lab/59813 [52] https://github.com/ComputationalPsychiatry/HierarchicalGaussianFiltering.jl [53] https://github.com/DominiqueMakowski/CognitiveModels [54] https://julialang.org/blog/2020/08/invalidations/ [55] https://pubmed.ncbi.nlm.nih.gov/33400903/