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: Update Dirichlet parameters of the initial hidden state distribution 
  (prior beliefs about hidden states at the beginning of the inference window).
  
  Parameters
  -----------
  qs_t0: 1D ``numpy.ndarray``, ``numpy.ndarray`` of dtype object, or ``None``
      Marginal posterior beliefs over hidden states at current timepoint. If ``None``, the 
      value of ``qs_t0`` is set to ``self.qs_hist[0]`` (i.e. the initial hidden state beliefs at the first timepoint).
      If ``self.inference_algo == "MMP"``, then ``qs_t0`` is set to be the Bayesian model average of beliefs about hidden states
      at the first timestep of the backwards inference horizon, where the average is taken with respect to posterior beliefs about policies.
  
  Returns
  -----------
  qD: ``numpy.ndarray`` of dtype object
      Posterior Dirichlet parameters over initial hidden state prior (same shape as ``qs_t0``), after having updated it with state beliefs.
docstr_tok: ["Update","Dirichlet","parameters","of","the","initial","hidden","state","distribution","(","prior","beliefs","about","hidden","states","at","the","beginning","of","the","inference","window",")",".","Parameters","--","--","--","--","--","-","qs_t0",":","1D","``","numpy.ndarray","``",",","``","numpy.ndarray","``","of","dtype","object",",","or","``","None","``","Marginal","posterior","beliefs","over","hidden","states","at","current","timepoint",".","If","``","None","``",",","the","value","of","``","qs_t0","``","is","set","to","``","self.qs_hist","[","0","]","``","(","i.e",".","the","initial","hidden","state","beliefs","at","the","first","timepoint",")",".","If","``","self.inference_algo","==","``","MMP","''","``",",","then","``","qs_t0","``","is","set","to","be","the","Bayesian","model","average","of","beliefs","about","hidden","states","at","the","first","timestep","of","the","backwards","inference","horizon",",","where","the","average","is","taken","with","respect","to","posterior","beliefs","about","policies",".","Returns","--","--","--","--","--","-","qD",":","``","numpy.ndarray","``","of","dtype","object","Posterior","Dirichlet","parameters","over","initial","hidden","state","prior","(","same","shape","as","``","qs_t0","``",")",",","after","having","updated","it","with","state","beliefs","."]
code: def update_D(self, qs_t0=None):
      """
      Update Dirichlet parameters of the initial hidden state distribution
      (prior beliefs about hidden states at the beginning of the inference window).
  
      Parameters
      -----------
      qs_t0: 1D ``numpy.ndarray``, ``numpy.ndarray`` of dtype object, or ``None``
          Marginal posterior beliefs over hidden states at current timepoint. If ``None``, the
          value of ``qs_t0`` is set to ``self.qs_hist[0]`` (i.e. the initial hidden state beliefs at the first timepoint).
          If ``self.inference_algo == "MMP"``, then ``qs_t0`` is set to be the Bayesian model average of beliefs about hidden states
          at the first timestep of the backwards inference horizon, where the average is taken with respect to posterior beliefs about policies.
  
      Returns
      -----------
      qD: ``numpy.ndarray`` of dtype object
          Posterior Dirichlet parameters over initial hidden state prior (same shape as ``qs_t0``), after having updated it with state beliefs.
      """
  
      if self.inference_algo == "VANILLA":
          if qs_t0 is None:
              try:
                  qs_t0 = self.qs_hist[0]
              except ValueError:
                  print(
                      "qs_t0 must either be passed as argument to `update_D` or `save_belief_hist` must be set to True!"
                  )
  
      elif self.inference_algo == "MMP":
          if self.edge_handling_params["use_BMA"]:
              qs_t0 = self.latest_belief
          elif self.edge_handling_params["policy_sep_prior"]:
              qs_pi_t0 = self.latest_belief
  
              # get beliefs about policies at the time at the beginning of the inference horizon
              if hasattr(self, "q_pi_hist"):
                  begin_horizon_step = max(
                      0, self.curr_timestep - self.inference_horizon
                  )
                  q_pi_t0 = np.copy(self.q_pi_hist[begin_horizon_step])
              else:
                  q_pi_t0 = np.copy(self.q_pi)
  
              qs_t0 = inference.average_states_over_policies(
                  qs_pi_t0, q_pi_t0
              )  # beliefs about hidden states at the first timestep of the inference horizon
  
      qD = learning.update_state_prior_dirichlet(
          self.pD, qs_t0, self.lr_pD, factors=self.factors_to_learn
      )
  
      self.pD = qD  # set new prior to posterior
      self.D = utils.norm_dist_obj_arr(
          qD
      )  # take expected value of posterior Dirichlet parameters to calculate posterior over D array
  
      return qD
  
imports: import warnings
  import numpy
  from pymdp import inference, control, learning
  from pymdp import utils, maths
  import copy
label_desc: Use image node_id 18 for calling the Agent obj's underlying member method code with example usage: obj.update_D(qs_t0) and returns: qD