class_docstr: Policy that chooses an action based on a categorical distribution.
  
  The distribution is specified by a set of weights for each action and an
  inverse temperature. The unnormalized probability distribution is given by
  `exp(weight * inv_temp)`. Weights and inverse temperature are typically
  maintained as `Variable`s, and are updated by an `Agent`.
  
  Note that this policy does not make use of `time_step.observation` at all.
  That is, it is a non-contextual bandit policy.
class_docstr_tok: ["Policy","that","chooses","an","action","based","on","a","categorical","distribution",".","The","distribution","is","specified","by","a","set","of","weights","for","each","action","and","an","inverse","temperature",".","The","unnormalized","probability","distribution","is","given","by","`","exp","(","weight","*","inv_temp",")","`",".","Weights","and","inverse","temperature","are","typically","maintained","as","`","Variable","`","s",",","and","are","updated","by","an","`","Agent","`",".","Note","that","this","policy","does","not","make","use","of","`","time_step.observation","`","at","all",".","That","is",",","it","is","a","non-contextual","bandit","policy","."]
docstr: Initializes `CategoricalPolicy`.
  
  The `weights` and `inverse_temperature` arguments may be either `Tensor`s or
    `tf.Variable`s. If they are variables, then any assignments to those
    variables will be reflected in the output of the policy. The shape of
    `weights` is used to determine the action_spec for this policy;
    `action_spec.maximum = weights.shape[0]`.
  
  
  If `emit_log_probability=True`, the info field of the `PolicyStep` returned
    will be a `PolicyInfo` tuple with log-probability that can be accessed
    using `policy_step.get_log_probability(step.info)`.
  
  Args:
    weights: a vector of weights, corresponding to the unscaled log
      probabilities of a categorical distribution.
    time_step_spec: A `TimeStep` spec of the expected time_steps.
    action_spec: A `tensor_spec` of action specification.
    inverse_temperature: a float value used to scale `weights`. Lower values
      will induce a more uniform distribution over actions; higher values will
      result in a sharper distribution.
    emit_log_probability: Whether to emit log probabilities or not.
    name: The name of this policy.
  
  Raises:
    ValueError: If the number of actions specified by the action_spec does not
      match the dimension of weights.
docstr_tok: ["Initializes","`","CategoricalPolicy","`",".","The","`","weights","`","and","`","inverse_temperature","`","arguments","may","be","either","`","Tensor","`","s","or","`","tf.Variable","`","s",".","If","they","are","variables",",","then","any","assignments","to","those","variables","will","be","reflected","in","the","output","of","the","policy",".","The","shape","of","`","weights","`","is","used","to","determine","the","action_spec","for","this","policy",";","`","action_spec.maximum","=","weights.shape","[","0","]","`",".","If","`","emit_log_probability=True","`",",","the","info","field","of","the","`","PolicyStep","`","returned","will","be","a","`","PolicyInfo","`","tuple","with","log-probability","that","can","be","accessed","using","`","policy_step.get_log_probability","(","step.info",")","`",".","Args",":","weights",":","a","vector","of","weights",",","corresponding","to","the","unscaled","log","probabilities","of","a","categorical","distribution",".","time_step_spec",":","A","`","TimeStep","`","spec","of","the","expected","time_steps",".","action_spec",":","A","`","tensor_spec","`","of","action","specification",".","inverse_temperature",":","a","float","value","used","to","scale","`","weights","`",".","Lower","values","will","induce","a","more","uniform","distribution","over","actions",";","higher","values","will","result","in","a","sharper","distribution",".","emit_log_probability",":","Whether","to","emit","log","probabilities","or","not",".","name",":","The","name","of","this","policy",".","Raises",":","ValueError",":","If","the","number","of","actions","specified","by","the","action_spec","does","not","match","the","dimension","of","weights","."]
code: def __init__(
      self,
      weights: types.Tensor,
      time_step_spec: types.TimeStep,
      action_spec: types.BoundedTensorSpec,
      inverse_temperature: float = 1.0,
      emit_log_probability: bool = True,
      name: Optional[Text] = None,
  ):
      """Initializes `CategoricalPolicy`.
  
      The `weights` and `inverse_temperature` arguments may be either `Tensor`s or
        `tf.Variable`s. If they are variables, then any assignments to those
        variables will be reflected in the output of the policy. The shape of
        `weights` is used to determine the action_spec for this policy;
        `action_spec.maximum = weights.shape[0]`.
  
  
      If `emit_log_probability=True`, the info field of the `PolicyStep` returned
        will be a `PolicyInfo` tuple with log-probability that can be accessed
        using `policy_step.get_log_probability(step.info)`.
  
      Args:
        weights: a vector of weights, corresponding to the unscaled log
          probabilities of a categorical distribution.
        time_step_spec: A `TimeStep` spec of the expected time_steps.
        action_spec: A `tensor_spec` of action specification.
        inverse_temperature: a float value used to scale `weights`. Lower values
          will induce a more uniform distribution over actions; higher values will
          result in a sharper distribution.
        emit_log_probability: Whether to emit log probabilities or not.
        name: The name of this policy.
  
      Raises:
        ValueError: If the number of actions specified by the action_spec does not
          match the dimension of weights.
      """
      _validate_weights(weights)
      self._weights = weights
      self._inverse_temperature = inverse_temperature
      if action_spec.maximum + 1 != tf.compat.dimension_value(
          weights.shape[0]
      ):
          raise ValueError(
              "Number of actions ({}) does not match weights dimension ({}).".format(
                  action_spec.maximum + 1,
                  tf.compat.dimension_value(weights.shape[0]),
              )
          )
      super(CategoricalPolicy, self).__init__(
          time_step_spec=time_step_spec,
          action_spec=action_spec,
          emit_log_probability=True,
          name=name,
      )
  
file_path: agents/tf_agents/bandits/policies/categorical_policy.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  from typing import Optional, Text
  import tensorflow
  import tensorflow_probability
  from tf_agents.policies import tf_policy
  from tf_agents.trajectories import policy_step
  from tf_agents.typing import types
  from tf_agents.utils import common
  from tf_agents.utils import nest_utils
label_desc: Use image node_id 1 to create a new CategoricalPolicy object from inherited base classes: tf_policy with example: obj = CategoricalPolicy(weights, time_step_spec, action_spec, inverse_temperature, emit_log_probability, name)