class_docstr: Relative Entropy Policy Search.
  
  References
  ----------
  [1] J. Peters, K. Mulling, and Y. Altun, "Relative Entropy Policy Search,"
      Artif. Intell., pp. 1607-1612, 2008.
  
  Example:
      $ python garage/examples/tf/reps_gym_cartpole.py
  
  Args:
      env_spec (EnvSpec): Environment specification.
      policy (garage.tf.policies.StochasticPolicy): Policy.
      baseline (garage.tf.baselines.Baseline): The baseline.
      sampler (garage.sampler.Sampler): Sampler.
      scope (str): Scope for identifying the algorithm.
          Must be specified if running multiple algorithms
          simultaneously, each using different environments
          and policies.
      discount (float): Discount.
      gae_lambda (float): Lambda used for generalized advantage
          estimation.
      center_adv (bool): Whether to rescale the advantages
          so that they have mean 0 and standard deviation 1.
      positive_adv (bool): Whether to shift the advantages
          so that they are always positive. When used in
          conjunction with center_adv the advantages will be
          standardized before shifting.
      fixed_horizon (bool): Whether to fix horizon.
      epsilon (float): Dual func parameter.
      l2_reg_dual (float): Coefficient for dual func l2 regularization.
      l2_reg_loss (float): Coefficient for policy loss l2 regularization.
      optimizer (object): The optimizer of the algorithm. Should be the
          optimizers in garage.tf.optimizers.
      optimizer_args (dict): Arguments of the optimizer.
      dual_optimizer (object): Dual func optimizer.
      dual_optimizer_args (dict): Arguments of the dual optimizer.
      name (str): Name of the algorithm.
docstr: Build policy loss and other output tensors.
  
  Args:
      i (namedtuple): Collection of variables to compute policy loss.
  
  Returns:
      tf.Tensor: Policy loss.
      tf.Tensor: Mean policy KL divergence.
  
  Raises:
      NotImplementedError: If is_recurrent is True.
docstr_tok: ["Build","policy","loss","and","other","output","tensors",".","Args",":","i","(","namedtuple",")",":","Collection","of","variables","to","compute","policy","loss",".","Returns",":","tf.Tensor",":","Policy","loss",".","tf.Tensor",":","Mean","policy","KL","divergence",".","Raises",":","NotImplementedError",":","If","is_recurrent","is","True","."]
code: def _build_policy_loss(self, i):
      """Build policy loss and other output tensors.
  
      Args:
          i (namedtuple): Collection of variables to compute policy loss.
  
      Returns:
          tf.Tensor: Policy loss.
          tf.Tensor: Mean policy KL divergence.
  
      Raises:
          NotImplementedError: If is_recurrent is True.
  
      """
      pol_dist = self._policy_network.dist
      old_pol_dist = self._old_policy_network.dist
  
      # Initialize dual params
      self._param_eta = 15.0
      self._param_v = np.random.rand(
          self._env_spec.observation_space.flat_dim * 2 + 4
      )
  
      with tf.name_scope("bellman_error"):
          delta_v = tf.boolean_mask(
              i.reward_var, i.valid_var
          ) + tf.tensordot(i.feat_diff, i.param_v, 1)
  
      with tf.name_scope("policy_loss"):
          ll = pol_dist.log_prob(i.action_var)
          ll = tf.boolean_mask(ll, i.valid_var)
          loss = -tf.reduce_mean(
              ll
              * tf.exp(
                  delta_v / i.param_eta
                  - tf.reduce_max(delta_v / i.param_eta)
              )
          )
  
          reg_params = self.policy.get_regularizable_vars()
          loss += (
              self._l2_reg_loss
              * tf.reduce_sum(
                  [
                      tf.reduce_mean(tf.square(param))
                      for param in reg_params
                  ]
              )
              / len(reg_params)
          )
  
      with tf.name_scope("kl"):
          kl = old_pol_dist.kl_divergence(pol_dist)
          pol_mean_kl = tf.reduce_mean(kl)
  
      with tf.name_scope("dual"):
          dual_loss = i.param_eta * self._epsilon + (
              i.param_eta
              * tf.math.log(
                  tf.reduce_mean(
                      tf.exp(
                          delta_v / i.param_eta
                          - tf.reduce_max(delta_v / i.param_eta)
                      )
                  )
              )
              + i.param_eta * tf.reduce_max(delta_v / i.param_eta)
          )
  
          dual_loss += self._l2_reg_dual * (
              tf.square(i.param_eta) + tf.square(1 / i.param_eta)
          )
  
          dual_grad = tf.gradients(dual_loss, [i.param_eta, i.param_v])
  
      self._f_dual = compile_function(
          flatten_inputs(self._dual_opt_inputs), dual_loss
      )
  
      self._f_dual_grad = compile_function(
          flatten_inputs(self._dual_opt_inputs), dual_grad
      )
  
      self._f_policy_kl = compile_function(
          flatten_inputs(self._policy_opt_inputs), pol_mean_kl
      )
  
      return loss
  
imports: import collections
  from dowel import logger, tabular
  import numpy
  import scipy.optimize
  import tensorflow
  from garage import _Default, log_performance, make_optimizer
  from garage.np import pad_batch_array
  from garage.np.algos import RLAlgorithm
  from garage.tf import compile_function, flatten_inputs, graph_inputs, new_tensor
  from garage.tf.optimizers import LBFGSOptimizer
label_desc: Use image node_id 9 for calling the REPS obj's underlying member method code with example usage: obj._build_policy_loss(i) and returns: loss