docstr: Test for passing in `sampling_mode` argument to `agent.Agent()` constructor, which determines whether you sample
  from posterior marginal over actions ("marginal", default) or posterior over policies ("full")
docstr_tok: ["Test","for","passing","in","`","sampling_mode","`","argument","to","`","agent.Agent","(",")","`","constructor",",","which","determines","whether","you","sample","from","posterior","marginal","over","actions","(","``","marginal","''",",","default",")","or","posterior","over","policies","(","``","full","''",")"]
code: def test_agent_with_sampling_mode(self):
      """
      Test for passing in `sampling_mode` argument to `agent.Agent()` constructor, which determines whether you sample
      from posterior marginal over actions ("marginal", default) or posterior over policies ("full")
      """
  
      num_obs = [2]
      num_states = [2]
      num_controls = [2]
      A = utils.to_obj_array(np.eye(num_obs[0], num_states[0]))
      B = utils.construct_controllable_B(num_states, num_controls)
      C = utils.to_obj_array(np.array([1.01, 1.0]))
  
      agent = Agent(
          A=A,
          B=B,
          C=C,
          alpha=16.0,
          sampling_mode="full",
          action_selection="stochastic",
      )
      agent.infer_states(([0]))
      agent.infer_policies()
      chosen_action, p_policies = agent._sample_action_test()
      self.assertEqual(len(p_policies), len(agent.q_pi))
  
      agent = Agent(
          A=A,
          B=B,
          C=C,
          alpha=16.0,
          sampling_mode="full",
          action_selection="deterministic",
      )
      agent.infer_states(([0]))
      agent.infer_policies()
      chosen_action, p_policies = agent._sample_action_test()
      self.assertEqual(len(p_policies), len(agent.q_pi))
  
      agent = Agent(
          A=A,
          B=B,
          C=C,
          alpha=16.0,
          sampling_mode="marginal",
          action_selection="stochastic",
      )
      agent.infer_states(([0]))
      agent.infer_policies()
      chosen_action, p_actions = agent._sample_action_test()
      self.assertEqual(len(p_actions[0]), num_controls[0])
  
imports: import os
  import unittest
  import numpy
  from copy import deepcopy
  from pymdp.agent import Agent
  from pymdp import utils, maths
  from pymdp import inference, control, learning
  from pymdp.default_models import generate_grid_world_transitions
label_desc: Use image node_id 11 for calling the TestAgent obj's underlying member method code with example usage: obj.test_agent_with_sampling_mode() without return types