code: def construct_policies(
      num_states, num_controls=None, policy_len=1, control_fac_idx=None
  ):
      """
      Generate a ``list`` of policies. The returned array ``policies`` is a ``list`` that stores one policy per entry.
      A particular policy (``policies[i]``) has shape ``(num_timesteps, num_factors)``
      where ``num_timesteps`` is the temporal depth of the policy and ``num_factors`` is the number of control factors.
  
      Parameters
      ----------
      num_states: ``list`` of ``int``
          ``list`` of the dimensionalities of each hidden state factor
      num_controls: ``list`` of ``int``, default ``None``
          ``list`` of the dimensionalities of each control state factor. If ``None``, then is automatically computed as the dimensionality of each hidden state factor that is controllable
      policy_len: ``int``, default 1
          temporal depth ("planning horizon") of policies
      control_fac_idx: ``list`` of ``int``
          ``list`` of indices of the hidden state factors that are controllable (i.e. those state factors ``i`` where ``num_controls[i] > 1``)
  
      Returns
      ----------
      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_factors = len(num_states)
      if control_fac_idx is None:
          if num_controls is not None:
              control_fac_idx = [
                  f for f, n_c in enumerate(num_controls) if n_c > 1
              ]
          else:
              control_fac_idx = list(range(num_factors))
  
      if num_controls is None:
          num_controls = [
              num_states[c_idx] if c_idx in control_fac_idx else 1
              for c_idx in range(num_factors)
          ]
  
      x = num_controls * policy_len
      policies = list(itertools.product(*[list(range(i)) for i in x]))
      for pol_i in range(len(policies)):
          policies[pol_i] = np.array(policies[pol_i]).reshape(
              policy_len, num_factors
          )
  
      return 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 9 for calling a global function with example usage: construct_policies(num_states, num_controls, policy_len, control_fac_idx) and returns: policies