class_docstr: Implementation of the epsilon-greedy policy.
docstr: Initializes the epsilon-greedy policy.
  
  Args:
    greedy_policy: An instance of py_policy.PyPolicy to use as the greedy
      policy.
    epsilon: The probability 0.0 <= epsilon <= 1.0 with which an action will
      be selected at random.
    random_policy: An instance of random_py_policy.RandomPyPolicy to use as
      the random policy, if None is provided, a RandomPyPolicy will be
      automatically created with the greedy_policy's action_spec and
      observation_spec and random_seed.
    epsilon_decay_end_count: if set, anneal the epislon every time this policy
      is used, until it hits the epsilon_decay_end_value.
    epsilon_decay_end_value: the value of epislon to use when the policy usage
      count hits epsilon_decay_end_count.
    random_seed: seed used to create numpy.random.RandomState. /dev/urandom
      will be used if it's None.
  
  Raises:
    ValueError: If epsilon is not between 0.0 and 1.0. Or if
    epsilon_decay_end_value is invalid when epsilon_decay_end_count is
    set.
docstr_tok: ["Initializes","the","epsilon-greedy","policy",".","Args",":","greedy_policy",":","An","instance","of","py_policy.PyPolicy","to","use","as","the","greedy","policy",".","epsilon",":","The","probability","0.0","<","=","epsilon","<","=","1.0","with","which","an","action","will","be","selected","at","random",".","random_policy",":","An","instance","of","random_py_policy.RandomPyPolicy","to","use","as","the","random","policy",",","if","None","is","provided",",","a","RandomPyPolicy","will","be","automatically","created","with","the","greedy_policy","'s","action_spec","and","observation_spec","and","random_seed",".","epsilon_decay_end_count",":","if","set",",","anneal","the","epislon","every","time","this","policy","is","used",",","until","it","hits","the","epsilon_decay_end_value",".","epsilon_decay_end_value",":","the","value","of","epislon","to","use","when","the","policy","usage","count","hits","epsilon_decay_end_count",".","random_seed",":","seed","used","to","create","numpy.random.RandomState",".","\/dev\/urandom","will","be","used","if","it","'s","None",".","Raises",":","ValueError",":","If","epsilon","is","not","between","0.0","and","1.0",".","Or","if","epsilon_decay_end_value","is","invalid","when","epsilon_decay_end_count","is","set","."]
code: def __init__(
      self,
      greedy_policy: py_policy.PyPolicy,
      epsilon: types.Float,
      random_policy: Optional[random_py_policy.RandomPyPolicy] = None,
      epsilon_decay_end_count: Optional[types.Float] = None,
      epsilon_decay_end_value: Optional[types.Float] = None,
      random_seed: Optional[types.Seed] = None,
  ):
      """Initializes the epsilon-greedy policy.
  
      Args:
        greedy_policy: An instance of py_policy.PyPolicy to use as the greedy
          policy.
        epsilon: The probability 0.0 <= epsilon <= 1.0 with which an action will
          be selected at random.
        random_policy: An instance of random_py_policy.RandomPyPolicy to use as
          the random policy, if None is provided, a RandomPyPolicy will be
          automatically created with the greedy_policy's action_spec and
          observation_spec and random_seed.
        epsilon_decay_end_count: if set, anneal the epislon every time this policy
          is used, until it hits the epsilon_decay_end_value.
        epsilon_decay_end_value: the value of epislon to use when the policy usage
          count hits epsilon_decay_end_count.
        random_seed: seed used to create numpy.random.RandomState. /dev/urandom
          will be used if it's None.
  
      Raises:
        ValueError: If epsilon is not between 0.0 and 1.0. Or if
        epsilon_decay_end_value is invalid when epsilon_decay_end_count is
        set.
      """
      if not 0 <= epsilon <= 1.0:
          raise ValueError("epsilon should be in [0.0, 1.0]")
  
      self._greedy_policy = greedy_policy
      if random_policy is None:
          self._random_policy = random_py_policy.RandomPyPolicy(
              time_step_spec=greedy_policy.time_step_spec,
              action_spec=greedy_policy.action_spec,
              seed=random_seed,
          )
      else:
          self._random_policy = random_policy
      # TODO(b/110841809) consider making epsilon be provided by a function.
      self._epsilon = epsilon
      self._epsilon_decay_end_count = epsilon_decay_end_count
      if epsilon_decay_end_count is not None:
          if (
              epsilon_decay_end_value is None
              or epsilon_decay_end_value >= epsilon
          ):
              raise ValueError(
                  "Invalid value for epsilon_decay_end_value {}".format(
                      epsilon_decay_end_value
                  )
              )
          self._epsilon_decay_step_factor = (
              float(epsilon - epsilon_decay_end_value)
              / epsilon_decay_end_count
          )
      self._epsilon_decay_end_value = epsilon_decay_end_value
  
      self._random_seed = random_seed  # Keep it for copy method.
      self._rng = np.random.RandomState(random_seed)
  
      # Total times action method has been called.
      self._count = 0
  
      super(EpsilonGreedyPolicy, self).__init__(
          greedy_policy.time_step_spec,
          greedy_policy.action_spec,
          greedy_policy.policy_state_spec,
          greedy_policy.info_spec,
      )
  
file_path: agents/tf_agents/policies/py_epsilon_greedy_policy.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  from typing import Optional
  import numpy
  from tf_agents.policies import py_policy
  from tf_agents.policies import random_py_policy
  from tf_agents.trajectories import policy_step
  from tf_agents.typing import types
label_desc: Use image node_id 1 to create a new EpsilonGreedyPolicy object from inherited base classes: py_policy with example: obj = EpsilonGreedyPolicy(greedy_policy, epsilon, random_policy, epsilon_decay_end_count, epsilon_decay_end_value, random_seed)