Entropy 2025, 27, 62 13 of 33
 
scaling_parameter = 2 .0
pA = deepcopy (A) * scaling_parameter # Create pA as a scaled copy of A
pB = deepcopy (B) * scaling_parameter # Create pB as a scaled copy of B
pD = deepcopy (D) * scaling_parameter # Create pD as a scaled copy of D
 
Finally, we define the hyper-parameters and other settings in two dictionaries. Here, we
display the most common parameters and settings, and set them to their default values,
which are used if they are not set by the user:
 
parameters = Dict (
" alpha " => 16 .0 , # Action precision alpha
" gamma " => 16 .0 , # Policy precision gamma
" lr_pA " => 1 .0 , # Learning rate of A
" fr_pA " => 1 .0 , # Forgetting rate of A
" lr_pB " => 1 .0 , # Learning rate of B
" fr_pB " => 1 .0 , # Forgetting rate of B
" lr_pD " => 1 .0 , # Learning rate of D
" fr_pD " => 1 .0 # Forgetting rate of D
)
settings = Dict (
# Length of policies to consider
" policy_len " => 1,
# Whether to use state information gain for action selection
" use_states_info_gain " => true ,
# Whether to use parameter information gain for action selection
" use_param_info_gain " => false ,
# Whether to use pragmatic gain for action selection
" use_utility " => true ,
)
 
We can now input the above arguments intoinit_aif and create an AIF object. This allows
us to present it with observations and let it choose actions. The following displays a few
functions in the order they are usually used, first inferring environmental states, then
updating matrices and then selecting a new action. First, we make inferences about the
environment with infer_states!, which returns the updated posterior belief q(s) about
environmental states given an observation. The observation is presented as a vector with
an entry for each observation modality:
 
observation = [1] # Define an observation for each observation modality
qs = infer_states !( aif , observation ) # Produce a posterior belief about states
 
We can now also update the Dirichlet beliefs about the various parameters with the
update_parameters! function. A is updated based on the last observation and the posterior
belief about the state that generated it. B is updated based on the posteriors about the
previous state transition given the previous action. D is updated based on the posterior
over states at the first time step.
 
# Update parameters based on provided priors , pA , pB , and pD.
update_parameters !( aif )
 
The infer_policies! function then calculates the expected free energy for each possible
policy (the number of policies varies depending on the amount of possible actions per
time step and the length of policies considered), as well as the corresponding posterior
probability over these policies. This calculation depends on the settings specified in the