text: (cid:7) 
  aif_agent = init_aif ( 
  A, B, C = C, D = D, E = E, pA = pA , settings = settings , parameters = parameters 
  
  ) 
  (cid:6)  (cid:5) 
  
  4.2. Simulating Behaviour 
  
  Since the environment and agent were set up, we could proceed to simulate the 
  behaviour of the agent in the environment. We created a for loop, where the agent received 
  an observation, made inferences about the environment, updated**A**, inferred policies 
  and sampled actions: 
  (cid:7)  (cid:4) 
  
  # Run 1000 time steps 
  T = 1000 
  
  # Sample initial observation 
  obs = reset_TMaze !( Env ) 
  
  # For loop over every time step 
  **for**t = 1:T 
  
  # Infer states based on the current observation 
  infer_states !( aif_agent , obs ) 
  
  # Infer policies and calculate expected free energy 
  infer_policies !( aif_agent ) 
  
  # Updating A. This is the learning part , 
  # that includes the counting of the pA Dirichlet . 
  update_parameters !( aif_agent ) 
  
  # Sample an action based on the inferred policies 
  chosen_action = sample_action !( aif_agent ) 