code: def _sample_policy_test(
      q_pi,
      policies,
      num_controls,
      action_selection="deterministic",
      alpha=16.0,
      seed=None,
  ):
      """
      Test version of sampling a policy from the posterior over policies, taking the action (per control factor) entailed by the first timestep of the selected policy.
      This test version also returns the probability distribution over policies, and also has a seed argument for reproducibility.
      Parameters
      ----------
      q_pi: 1D ``numpy.ndarray``
          Posterior beliefs over policies, i.e. a vector containing one posterior probability per policy.
      policies: ``list`` of 2D ``numpy.ndarray``
          ``list`` that stores each policy as a 2D array in ``policies[p_idx]``. Shape of ``policies[p_idx]``
          is ``(num_timesteps, num_factors)`` where ``num_timesteps`` is the temporal
          depth of the policy and ``num_factors`` is the number of control factors.
      num_controls: ``list`` of ``int``
          ``list`` of the dimensionalities of each control state factor.
      action_selection: string, default "deterministic"
          String indicating whether whether the selected policy is chosen as the maximum of the posterior over policies,
          or whether it's sampled from the posterior over policies.
      alpha: float, default 16.0
          Action selection precision -- the inverse temperature of the softmax that is used to scale the
          policy posterior before sampling. This is only used if ``action_selection`` argument is "stochastic"
      seed: ``int``, default None
          The seed can be set to control the random sampling that occurs when ``action_selection`` is "deterministic" but there are more than one actions with the same maximum posterior probability.
  
  
      Returns
      ----------
      selected_policy: 1D ``numpy.ndarray``
          Vector containing the indices of the actions for each control factor
      """
  
      num_factors = len(num_controls)
  
      if action_selection == "deterministic":
          p_policies = q_pi
          policy_idx = _select_highest_test(p_policies, seed=seed)
      elif action_selection == "stochastic":
          log_qpi = spm_log_single(q_pi)
          p_policies = softmax(log_qpi * alpha)
          policy_idx = utils.sample(p_policies)
  
      selected_policy = np.zeros(num_factors)
      for factor_i in range(num_factors):
          selected_policy[factor_i] = policies[policy_idx][0, factor_i]
  
      return selected_policy, p_policies
  
imports: import itertools
  import numpy
  from pymdp.maths import softmax, softmax_obj_arr, spm_dot, spm_wnorm, spm_MDP_G, spm_log_single, spm_log_obj_array
  from pymdp import utils
  import copy
label_desc: Use image node_id 14 for calling a global function with example usage: _sample_policy_test(q_pi, policies, num_controls, action_selection, alpha, seed) and returns: selected_policy,  p_policies