class_docstr: A PPO Agent.
class_docstr_tok: ["A","PPO","Agent","."]
docstr: Create update op for adaptive KL penalty coefficient.
  
  Args:
    kl_divergence: KL divergence of old policy to new policy for all
      timesteps.
  
  Returns:
    update_op: An op which runs the update for the adaptive kl penalty term.
docstr_tok: ["Create","update","op","for","adaptive","KL","penalty","coefficient",".","Args",":","kl_divergence",":","KL","divergence","of","old","policy","to","new","policy","for","all","timesteps",".","Returns",":","update_op",":","An","op","which","runs","the","update","for","the","adaptive","kl","penalty","term","."]
code: def update_adaptive_kl_beta(
      self, kl_divergence: types.Tensor
  ) -> Optional[tf.Operation]:
      """Create update op for adaptive KL penalty coefficient.
  
      Args:
        kl_divergence: KL divergence of old policy to new policy for all
          timesteps.
  
      Returns:
        update_op: An op which runs the update for the adaptive kl penalty term.
      """
      if self._adaptive_kl_beta is None:
          return tf.no_op()
  
      mean_kl = tf.reduce_mean(input_tensor=kl_divergence)
  
      # Update the adaptive kl beta after each time it is computed.
      mean_kl_below_bound = mean_kl < self._adaptive_kl_target * (
          1.0 - self._adaptive_kl_tolerance
      )
      mean_kl_above_bound = mean_kl > self._adaptive_kl_target * (
          1.0 + self._adaptive_kl_tolerance
      )
      adaptive_kl_update_factor = tf.case(
          [
              (
                  mean_kl_below_bound,
                  lambda: tf.constant(1.0 / 1.5, dtype=tf.float32),
              ),
              (
                  mean_kl_above_bound,
                  lambda: tf.constant(1.5, dtype=tf.float32),
              ),
          ],
          default=lambda: tf.constant(1.0, dtype=tf.float32),
          exclusive=True,
      )
  
      new_adaptive_kl_beta = tf.clip_by_value(
          self._adaptive_kl_beta * adaptive_kl_update_factor,
          clip_value_min=10e-16,
          clip_value_max=10e16,
      )
      tf.compat.v1.assign(self._adaptive_kl_beta, new_adaptive_kl_beta)
  
      if self._debug_summaries:
          tf.compat.v2.summary.scalar(
              name="adaptive_kl_update_factor",
              data=adaptive_kl_update_factor,
              step=self.train_step_counter,
          )
          tf.compat.v2.summary.scalar(
              name="mean_kl_divergence",
              data=mean_kl,
              step=self.train_step_counter,
          )
          tf.compat.v2.summary.scalar(
              name="adaptive_kl_beta",
              data=self._adaptive_kl_beta,
              step=self.train_step_counter,
          )
  
      return self._adaptive_kl_beta
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import collections
  from typing import Optional, Text, Tuple
  from absl import logging
  import gin
  from six.moves import range
  from six.moves import zip
  import tensorflow
  from tf_agents.agents import data_converter
  from tf_agents.agents import tf_agent
  from tf_agents.agents.ppo import ppo_policy
  from tf_agents.agents.ppo import ppo_utils
  from tf_agents.networks import network
  from tf_agents.policies import greedy_policy
  from tf_agents.specs import tensor_spec
  from tf_agents.trajectories import time_step
  from tf_agents.trajectories import trajectory
  from tf_agents.typing import types
  from tf_agents.utils import common
  from tf_agents.utils import eager_utils
  from tf_agents.utils import nest_utils
  from tf_agents.utils import object_identity
  from tf_agents.utils import tensor_normalizer
  from tf_agents.utils import value_ops
label_desc: Use image node_id 20 for calling the PPOAgent obj's underlying member method code with example usage: obj.update_adaptive_kl_beta(kl_divergence) and returns: self, tf