docstr: Helper function to run the tests.
  
  Creates the right q_func and tests for correctness. See the _create_q_func
  documentation to understand the various arguments.
docstr_tok: ["Helper","function","to","run","the","tests",".","Creates","the","right","q_func","and","tests","for","correctness",".","See","the","_create_q_func","documentation","to","understand","the","various","arguments","."]
code: def test_actor_func(
      self,
      sampler_type=None,
      anchor_point=0.0,
      dist=DIST_BIMODAL,
      categorical_action_returns=None,
      num_iters=5,
  ):  # pylint: disable=g-doc-args
      """Helper function to run the tests.
  
      Creates the right q_func and tests for correctness. See the _create_q_func
      documentation to understand the various arguments.
      """
      logging.info("==== Anchor point = %.2f ====", anchor_point)
      logging.info("dist = %s", dist)
  
      # we need more samples for test to guarantee convergence.
      num_samples = 64 * 4
  
      if sampler_type == "continuous_and_one_hot":
          action_spec = self._action_spec_hybrid
          # Initiate random mean and var.
          np.random.seed(1999)
          samples = np.random.rand(
              num_samples, _ACTION_SIZE - _ACTION_SIZE_DISCRETE
          ).astype(
              np.float32
          )  # [N, A-S]
          mean = {
              "continuous": np.mean(samples, axis=0),
              "discrete": np.zeros(
                  [_ACTION_SIZE_DISCRETE, _ACTION_SIZE_DISCRETE],
                  dtype=np.float32,
              ),
          }
          var = {
              "continuous": np.var(samples, axis=0),
              "discrete": np.zeros(
                  [_ACTION_SIZE_DISCRETE, _ACTION_SIZE_DISCRETE],
                  dtype=np.float32,
              ),
          }
  
          sampler = qtopt_cem_actions_sampler_continuous_and_one_hot.GaussianActionsSampler(
              action_spec=action_spec,
              sample_clippers=[[], []],
              sub_actions_fields=[["discrete"], ["continuous"]],
          )
      elif sampler_type == "hybrid":
          action_spec = self._action_spec_hybrid
          # Initiate random mean and var.
          np.random.seed(1999)
          samples = np.random.rand(
              num_samples, _ACTION_SIZE - _ACTION_SIZE_DISCRETE
          ).astype(
              np.float32
          )  # [N, A-S]
          samples_discrete = np.random.rand(
              num_samples, _ACTION_SIZE_DISCRETE
          ).astype(
              np.float32
          )  # [N, A-S]
          mean = {
              "continuous": np.mean(samples, axis=0),
              "discrete": np.mean(samples_discrete, axis=0),
          }
          var = {
              "continuous": np.var(samples, axis=0),
              "discrete": np.var(samples_discrete, axis=0),
          }
  
          sampler = (
              qtopt_cem_actions_sampler_hybrid.GaussianActionsSampler(
                  action_spec=action_spec
              )
          )
      elif sampler_type == "continuous":
          action_spec = self._action_spec
          # Initiate random mean and var.
          np.random.seed(1999)
          samples = np.random.rand(num_samples, _ACTION_SIZE).astype(
              np.float32
          )  # [N, A]
          mean = np.mean(samples, axis=0).tolist()
          var = np.var(samples, axis=0).tolist()
          sampler = qtopt_cem_actions_sampler_continuous.GaussianActionsSampler(
              action_spec=action_spec
          )
  
      cem_fn = qtopt_cem_policy.CEMPolicy(
          self._time_step_spec,
          action_spec,
          q_network=DummyNet(
              (self._obs_spec, action_spec),
              sampler_type=sampler_type,
              anchor_point=anchor_point,
              dist=dist,
              categorical_action_returns=categorical_action_returns,
          ),
          sampler=sampler,
          init_mean=mean,
          init_var=var,
          num_samples=num_samples,
          num_elites=7,
          num_iterations=num_iters,
      )
      out, _, _ = cem_fn.actor_func(
          observation=tf.zeros([_BATCH, 2]),
          step_type=(),
          policy_state=(),
      )
  
      self._assert_correctness(
          out,
          sampler_type=sampler_type,
          anchor_point=anchor_point,
          categorical_action_returns=categorical_action_returns,
      )
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  from absl import flags
  from absl import logging
  from absl.testing import parameterized
  import numpy
  import tensorflow
  import tensorflow_probability
  from tf_agents.networks import network
  from tf_agents.policies import qtopt_cem_policy
  from tf_agents.policies.samplers import qtopt_cem_actions_sampler_continuous
  from tf_agents.policies.samplers import qtopt_cem_actions_sampler_continuous_and_one_hot
  from tf_agents.policies.samplers import qtopt_cem_actions_sampler_hybrid
  from tf_agents.specs import tensor_spec
  from tf_agents.trajectories import time_step
label_desc: Use image node_id 4 for calling the CEMPolicyTest obj's underlying member method code with example usage: obj.test_actor_func(sampler_type, anchor_point, dist, categorical_action_returns, num_iters) without return types