class_docstr: The Agent class, the highest-level API that wraps together processes for action, perception, and learning under active inference.
  
  The basic usage is as follows:
  
  >>> my_agent = Agent(A = A, B = C, <more_params>)
  >>> observation = env.step(initial_action)
  >>> qs = my_agent.infer_states(observation)
  >>> q_pi, G = my_agent.infer_policies()
  >>> next_action = my_agent.sample_action()
  >>> next_observation = env.step(next_action)
  
  This represents one timestep of an active inference process. Wrapping this step in a loop with an ``Env()`` class that returns
  observations and takes actions as inputs, would entail a dynamic agent-environment interaction.
class_docstr_tok: ["The","Agent","class",",","the","highest-level","API","that","wraps","together","processes","for","action",",","perception",",","and","learning","under","active","inference",".","The","basic","usage","is","as","follows",":",">",">",">","my_agent","=","Agent","(","A","=","A",",","B","=","C",",","<","more_params",">",")",">",">",">","observation","=","env.step","(","initial_action",")",">",">",">","qs","=","my_agent.infer_states","(","observation",")",">",">",">","q_pi",",","G","=","my_agent.infer_policies","(",")",">",">",">","next_action","=","my_agent.sample_action","(",")",">",">",">","next_observation","=","env.step","(","next_action",")","This","represents","one","timestep","of","an","active","inference","process",".","Wrapping","this","step","in","a","loop","with","an","``","Env","(",")","``","class","that","returns","observations","and","takes","actions","as","inputs",",","would","entail","a","dynamic","agent-environment","interaction","."]
docstr: Perform policy inference by optimizing a posterior (categorical) distribution over policies.
  This distribution is computed as the softmax of ``G * gamma + lnE`` where ``G`` is the negative expected
  free energy of policies, ``gamma`` is a policy precision and ``lnE`` is the (log) prior probability of policies.
  This function returns the posterior over policies as well as the negative expected free energy of each policy.
  
  Returns
  ----------
  q_pi: 1D ``numpy.ndarray``
      Posterior beliefs over policies, i.e. a vector containing one posterior probability per policy.
  G: 1D ``numpy.ndarray``
      Negative expected free energies of each policy, i.e. a vector containing one negative expected free energy per policy.
docstr_tok: ["Perform","policy","inference","by","optimizing","a","posterior","(","categorical",")","distribution","over","policies",".","This","distribution","is","computed","as","the","softmax","of","``","G","*","gamma","+","lnE","``","where","``","G","``","is","the","negative","expected","free","energy","of","policies",",","``","gamma","``","is","a","policy","precision","and","``","lnE","``","is","the","(","log",")","prior","probability","of","policies",".","This","function","returns","the","posterior","over","policies","as","well","as","the","negative","expected","free","energy","of","each","policy",".","Returns","--","--","--","--","--","q_pi",":","1D","``","numpy.ndarray","``","Posterior","beliefs","over","policies",",","i.e",".","a","vector","containing","one","posterior","probability","per","policy",".","G",":","1D","``","numpy.ndarray","``","Negative","expected","free","energies","of","each","policy",",","i.e",".","a","vector","containing","one","negative","expected","free","energy","per","policy","."]
code: def infer_policies(self):
      """
      Perform policy inference by optimizing a posterior (categorical) distribution over policies.
      This distribution is computed as the softmax of ``G * gamma + lnE`` where ``G`` is the negative expected
      free energy of policies, ``gamma`` is a policy precision and ``lnE`` is the (log) prior probability of policies.
      This function returns the posterior over policies as well as the negative expected free energy of each policy.
  
      Returns
      ----------
      q_pi: 1D ``numpy.ndarray``
          Posterior beliefs over policies, i.e. a vector containing one posterior probability per policy.
      G: 1D ``numpy.ndarray``
          Negative expected free energies of each policy, i.e. a vector containing one negative expected free energy per policy.
      """
  
      if self.inference_algo == "VANILLA":
          q_pi, G = control.update_posterior_policies(
              self.qs,
              self.A,
              self.B,
              self.C,
              self.policies,
              self.use_utility,
              self.use_states_info_gain,
              self.use_param_info_gain,
              self.pA,
              self.pB,
              E=self.E,
              gamma=self.gamma,
          )
      elif self.inference_algo == "MMP":
          future_qs_seq = self.get_future_qs()
  
          q_pi, G = control.update_posterior_policies_full(
              future_qs_seq,
              self.A,
              self.B,
              self.C,
              self.policies,
              self.use_utility,
              self.use_states_info_gain,
              self.use_param_info_gain,
              self.latest_belief,
              self.pA,
              self.pB,
              F=self.F,
              E=self.E,
              gamma=self.gamma,
          )
  
      if hasattr(self, "q_pi_hist"):
          self.q_pi_hist.append(q_pi)
          if len(self.q_pi_hist) > self.inference_horizon:
              self.q_pi_hist = self.q_pi_hist[
                  -(self.inference_horizon - 1) :
              ]
  
      self.q_pi = q_pi
      self.G = G
      return q_pi, G
  
imports: import warnings
  import numpy
  from pymdp import inference, control, learning
  from pymdp import utils, maths
  import copy
label_desc: Use image node_id 13 for calling the Agent obj's underlying member method code with example usage: obj.infer_policies() and returns: q_pi,  G