Entropy 2025, 27, 62 12 of 33
 
# Create AIF object
aif = init_aif (
A:: Vector { Array {T, N}}, # A- matrices
B:: Vector { Array {T, N}}; # B- matrices
C:: Vector { Array { Real }}, # C- matrices ( optional )
D:: Vector { Vector { Real }}, # D- matrices ( optional )
E:: Vector {T}, # E- vector ( optional )
pA:: Union { Vector { Array {T, N}}, Nothing }, # Dirichlet priors for A- matrices ( optional )
pB:: Union { Vector { Array {T, N}}, Nothing }, # Dirichlet priors for B- matrices ( optional )
pD:: Union { Vector { Array { Real }}, Nothing }, # Dirichlet priors for D- vectors ( optional )
parameters :: Dict { String , Real }, # Dictionary containing other parameters ( optional )
settings :: Dict { String , Any } # Dictionary containing settings ( optional )
)
 
A and B are the only mandatory arguments to the init_aif function—the other arguments
are keyword arguments that default to uniform priors. A, B, C, D and E and their corre-
sponding Dirichlet priors, in the cases of A, B and D, should be formatted as standard
array objects. All but E can have multiple modalities/factors (see Section 4), so they should
be formatted as vectors of arrays with one array per modality/factor. These arrays can be
hand-specified by the user, or be generated with some of the helper functions supplied by
ActiveInference. Here, we create an AIF agent equipped with a generative model with
six environmental states, five possible observations and two possible actions. Here, we use
helper functions to create matrices and vectors with the correct dimensions; in Section 4, we
create them manually. First, we define the number of states, observations, controls and the
length of policies:
 
# Information about number of states , observations , actions and policy length
states = [6] # Six states , single factor
observations = [5] # Five observations , single modality
controls = [2] # Two actions , single factor
policy_length = 1 # Length of policies
# Generate uniform templates for matrices and vectors of the generative model
A, B, C, D, E = create_matrix_templates ( states , observations , controls , policy_length )
 
The A object generated here is a one-dimensional vector containing a uniform 5 × 6 matrix
(six states and five observations). The B object is a one-dimensional vector containing
a uniform 6 × 6 × 2 array (six states and two actions). The C, D and E objects are one-
dimensional vectors, each containing uniform vectors with their corresponding sizes. We
can now modify these to supply the agent with more informative priors over observations,
initial states and policies. Here, we performed this using the onehot function:
 
# We make C take the following form : [0 , 0, 0, 0, 1]
C[1] = onehot (5,5) # Initialize the single element of the C object with a one - hot vector
# D will be: [1 , 0, 0, 0, 0, 0]
D[1] = onehot (1,6) # Initialize the single element of the D object with a one - hot vector
# To make the agent prefer policy 2
E = onehot (2,2) # Initialize as a one - hot encoded vector : [0 ,1]
 
We now create the Dirichlet priors for A, B and D. When we use parameter learning, these
are used to define A, B and D defined above, and are updated at every time step. One
way to construct Dirichlet priors is to simply multiply the matrices below with a scaling
factor; a higher scaling leads to more precise priors that require stronger evidence to update.
Here, we use a scaling parameter of 2. In the current version, parameter learning is only
implemented for the A, B and D: