Entropy 2025, 27, 62 15 of 33
 
# Give single observation to the agent
observation = [1]
action = single_in put! ( agent , observation )
# Give multiple observations to the agent and simulate actions
observations = [1, 2, 1, 2, 3]
actions = give_inputs !( agent , observations )
 
Additionally, a set of convenience functions can extract and set parameters and (histories
of) beliefs. We briefly show how to extract the current or histories of past states:
 
# Get all current belief states
states = get_states ( agent )
# Get a specific state , like the expected free energies only
efe = get_states ( agent , " expected_free_energies ")
# Get history for all states
history = get_history ( agent )
# Get history of expected free energies only
history_efe = get_history ( agent , " expected_free_energies ")
 
And how to change the parameters of a created agent:
 
# Set individual parameter , alpha to 1.0
set_parameters !( agent , " alpha ", 1 .0 )
# Set multiple parameters by passing a dictionary
new_parameters = Dict (
" alpha " => 1 .0 , # Set alpha to 1.0
" lr_pA " => 0 .5 # Set learning rate of A to 0.5
)
set_parameters !( agent , new_parameters ) # Set new parameters to agent
 
3.3. Model Fitting withActionModels
In addition to simulating the behaviour and belief updating of agents, ActionModels
also makes it possible to fit models to data and perform parameter estimation. This is
used in general to form better models and theories of mental processes, as well as to
find mechanistic differences (usually prior beliefs in AIF) between, for example, clinical
populations or investigating how computational constructs, like Bayesian beliefs, relate
to, for example, neuronal dynamics. This is performed in fields like cognitive modelling
and mathematical psychology [ 34], as well as computational psychiatry [ 14,53]. In the
following, we briefly describe the high-level functions needed to fit AIF models to empirical
data with ActionModels.
We have our agent object defined as above. We then need to specify priors for the
parameters we want to estimate. Here, we estimate the α parameter, and use a gamma
distribution as prior:
 
# Load package for specifying distributions
using Distributions
# Initialize priors
priors = Dict (" alpha " => Gamma (4,4))
 
We can now use the create_model function to instantiate a probabilistic model object with
data. This takes the agent object, the priors, and a set of observations and actions as
the arguments: