ActiveInference.jl

Julia Package for Active Inference
Author ilabcode
Popularity
5 Stars
Updated Last
4 Months Ago
Started In
December 2023

ActiveInference.jl

Stable Dev Build Status Coverage License: MIT Aqua QA

Julia Package for Active Inference.

ActiveInference.jl is a new Julia package for the computational modeling of active inference. We provide the necessary infrastructure for defining active inference models, currently implemented as partially observable Markov decision processes. After defining the generative model, you can simulate actions using agent-based simulations. We also provide the functionality to fit experimental data to active inference models for parameter recovery.

Maze Animation

  • Example visualization of an agent navigating a maze, inspired by the one described in Bruineberg et al., 2018. Left: A synthetic agent wants to reach the end of the maze environment while avoiding dark-colored locations. Right: The agent's noisy prior expectations about the state of the environment parameterized by Dirichlet distributions are updated dynamically as it moves through the maze.

Installation

Install ActiveInference.jl using the Julia package manager:

using Pkg
Pkg.add("ActiveInference")

using ActiveInference

Getting Started

Understanding Vector Data Types in ActiveInference.jl

The generative model is defined using vectors of arrays, where each element can itself be a multi-dimensional array or matrix. For example:

  • If there is only one modality

# Initialize States, Observations, and Controls
states = [25]
observations = [25]
controls = [2] # Two controls (e.g. left and right)
policy_length = 2

# Generate random Generative Model 
A, B = create_matrix_templates(states, observations, controls, policy_length);

# Here, the A_matrix is a one element Vector{Matrix{Float64}} where the element is a 25x25 Matrix
size(A[1]) 

  • If there are more modalities

# Initialize States, Observations, and Controls
states = [25,2] 
observations = [25,2]
controls = [2,1] # Only the first factor is controllable (e.g. left and right)
policy_length = 2

# Generate random Generative Model 
A, B = create_matrix_templates(states, observations, controls, policy_length);

# Each modality is stored as a separate element.
size(A[1]) # Array{Float64, 3} with these dimensions: (25, 25, 2)
size(A[2]) # Array{Float64, 3} with these dimensions: (2, 25, 2)

More detailed description of Julia arrays can be found in the official Julia Documentation

Basic Usage

# Define some settings as a dictionary.
settings = Dict( "policy_len" => 3)

# Define some parameters as a dictionary.
parameters = Dict("alpha" => 16.0 )

# Initialize the AIF-type agent.
aif = init_aif(A,
               B;
               settings = settings,
               parameters = parameters);

Agent Output

# Give observation to the agent and run state inference.
observation = [3,1]
infer_states!(aif, observation)

# Infer policies 
infer_policies!(aif)

# Sample action
sample_action!(aif)

Used By Packages

No packages found.