ActiveInference.jl

Stable Dev Build Status Coverage License: MIT

Julia Package for Active Inference.

ActiveInference.jl is a new Julia package designed to implement active inference within discrete state-spaces using Partially Observable Markov Decision Processes (POMDP's). With ActiveInference.jl you can define a generative model for active inference and run agent-based simulations. Additionally, we provide a functionality for fitting experimental data 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 arrays of type Array{Any}, 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)

# Generate random Generative Model 
A_matrix, B_matrix = generate_random_GM(states, observations, controls);

# Here, the A_matrix is a one element Vector{Any} where the element is a 25x25 Matrix
size(A_matrix[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)

# Generate random Generative Model 
A_matrix, B_matrix = generate_random_GM(states, observations, controls);

# Each modality is stored as a separate element.
size(A_matrix[1]) # Array{Float64, 3} with these dimensions: (25, 25, 2)
size(A_matrix[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_matrix,
               B_matrix;
               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)