class_docstr: Categorical distribution over integers.
  
  The Categorical distribution is parameterized by either probabilities or
  log-probabilities of a set of `K` classes. It is defined over the integers
  `{0, 1, ..., K-1}`.
  
  The Categorical distribution is closely related to the `OneHotCategorical` and
  `Multinomial` distributions.  The Categorical distribution can be intuited as
  generating samples according to `argmax{ OneHotCategorical(probs) }` itself
  being identical to `argmax{ Multinomial(probs, total_count=1) }`.
  
  #### Mathematical Details
  
  The probability mass function (pmf) is,
  
  ```none
  pmf(k; pi) = prod_j pi_j**[k == j]
  ```
  
  #### Pitfalls
  
  The number of classes, `K`, must not exceed:
  
  - the largest integer representable by `self.dtype`, i.e.,
    `2**(mantissa_bits+1)` (IEEE 754),
  - the maximum `Tensor` index, i.e., `2**31-1`.
  
  In other words,
  
  ```python
  K <= min(2**31-1, {
    tf.float16: 2**11,
    tf.float32: 2**24,
    tf.float64: 2**53 }[param.dtype])
  ```
  
  Note: This condition is validated only when `self.validate_args = True`.
  
  #### Examples
  
  Creates a 3-class distribution with the 2nd class being most likely.
  
  ```python
  dist = Categorical(probs=[0.1, 0.5, 0.4])
  n = 1e4
  empirical_prob = tf.cast(
      tf.histogram_fixed_width(
        dist.sample(int(n)),
        [0., 2],
        nbins=3),
      dtype=tf.float32) / n
  # ==> array([ 0.1005,  0.5037,  0.3958], dtype=float32)
  ```
  
  Creates a 3-class distribution with the 2nd class being most likely.
  Parameterized by [logits](https://en.wikipedia.org/wiki/Logit) rather than
  probabilities.
  
  ```python
  dist = Categorical(logits=np.log([0.1, 0.5, 0.4])
  n = 1e4
  empirical_prob = tf.cast(
      tf.histogram_fixed_width(
        dist.sample(int(n)),
        [0., 2],
        nbins=3),
      dtype=tf.float32) / n
  # ==> array([0.1045,  0.5047, 0.3908], dtype=float32)
  ```
  
  Creates a 3-class distribution with the 3rd class being most likely.
  The distribution functions can be evaluated on counts.
  
  ```python
  # counts is a scalar.
  p = [0.1, 0.4, 0.5]
  dist = Categorical(probs=p)
  dist.prob(0)  # Shape []
  
  # p will be broadcast to [[0.1, 0.4, 0.5], [0.1, 0.4, 0.5]] to match counts.
  counts = [1, 0]
  dist.prob(counts)  # Shape [2]
  
  # p will be broadcast to shape [3, 5, 7, 3] to match counts.
  counts = [[...]] # Shape [5, 7, 3]
  dist.prob(counts)  # Shape [5, 7, 3]
  ```
class_docstr_tok: ["Categorical","distribution","over","integers",".","The","Categorical","distribution","is","parameterized","by","either","probabilities","or","log-probabilities","of","a","set","of","`","K","`","classes",".","It","is","defined","over","the","integers","`","{","0",",","1",",","...",",","K-1","}","`",".","The","Categorical","distribution","is","closely","related","to","the","`","OneHotCategorical","`","and","`","Multinomial","`","distributions",".","The","Categorical","distribution","can","be","intuited","as","generating","samples","according","to","`","argmax","{","OneHotCategorical","(","probs",")","}","`","itself","being","identical","to","`","argmax","{","Multinomial","(","probs",",","total_count=1",")","}","`",".","#","#","#","#","Mathematical","Details","The","probability","mass","function","(","pmf",")","is",",","``","`","none","pmf","(","k",";","pi",")","=","prod_j","pi_j","*","*","[","k","==","j","]","``","`","#","#","#","#","Pitfalls","The","number","of","classes",",","`","K","`",",","must","not","exceed",":","-","the","largest","integer","representable","by","`","self.dtype","`",",","i.e.",",","`","2","*","*","(","mantissa_bits+1",")","`","(","IEEE","754",")",",","-","the","maximum","`","Tensor","`","index",",","i.e.",",","`","2","*","*","31-1","`",".","In","other","words",",","``","`","python","K","<","=","min","(","2","*","*","31-1",",","{","tf.float16",":","2","*","*","11",",","tf.float32",":","2","*","*","24",",","tf.float64",":","2","*","*","53","}","[","param.dtype","]",")","``","`","Note",":","This","condition","is","validated","only","when","`","self.validate_args","=","True","`",".","#","#","#","#","Examples","Creates","a","3-class","distribution","with","the","2nd","class","being","most","likely",".","``","`","python","dist","=","Categorical","(","probs=","[","0.1",",","0.5",",","0.4","]",")","n","=","1e4","empirical_prob","=","tf.cast","(","tf.histogram_fixed_width","(","dist.sample","(","int","(","n",")",")",",","[","0.",",","2","]",",","nbins=3",")",",","dtype=tf.float32",")","\/","n","#","==",">","array","(","[","0.1005",",","0.5037",",","0.3958","]",",","dtype=float32",")","``","`","Creates","a","3-class","distribution","with","the","2nd","class","being","most","likely",".","Parameterized","by","[","logits","]","(","https",":","\/\/en.wikipedia.org\/wiki\/Logit",")","rather","than","probabilities",".","``","`","python","dist","=","Categorical","(","logits=np.log","(","[","0.1",",","0.5",",","0.4","]",")","n","=","1e4","empirical_prob","=","tf.cast","(","tf.histogram_fixed_width","(","dist.sample","(","int","(","n",")",")",",","[","0.",",","2","]",",","nbins=3",")",",","dtype=tf.float32",")","\/","n","#","==",">","array","(","[","0.1045",",","0.5047",",","0.3908","]",",","dtype=float32",")","``","`","Creates","a","3-class","distribution","with","the","3rd","class","being","most","likely",".","The","distribution","functions","can","be","evaluated","on","counts",".","``","`","python","#","counts","is","a","scalar",".","p","=","[","0.1",",","0.4",",","0.5","]","dist","=","Categorical","(","probs=p",")","dist.prob","(","0",")","#","Shape","[","]","#","p","will","be","broadcast","to","[","[","0.1",",","0.4",",","0.5","]",",","[","0.1",",","0.4",",","0.5","]","]","to","match","counts",".","counts","=","[","1",",","0","]","dist.prob","(","counts",")","#","Shape","[","2","]","#","p","will","be","broadcast","to","shape","[","3",",","5",",","7",",","3","]","to","match","counts",".","counts","=","[","[","...","]","]","#","Shape","[","5",",","7",",","3","]","dist.prob","(","counts",")","#","Shape","[","5",",","7",",","3","]","``","`"]
docstr: Initialize Categorical distributions using class log-probabilities.
  
  Args:
    logits: An N-D `Tensor`, `N >= 1`, representing the unnormalized
      log probabilities of a set of Categorical distributions. The first
      `N - 1` dimensions index into a batch of independent distributions
      and the last dimension represents a vector of logits for each class.
      Only one of `logits` or `probs` should be passed in.
    probs: An N-D `Tensor`, `N >= 1`, representing the probabilities
      of a set of Categorical distributions. The first `N - 1` dimensions
      index into a batch of independent distributions and the last dimension
      represents a vector of probabilities for each class. Only one of
      `logits` or `probs` should be passed in.
    dtype: The type of the event samples (default: int32).
    force_probs_to_zero_outside_support: Python `bool`. When `True`, negative
      values, values greater than N, and non-integer values are evaluated
      "strictly": `log_prob` returns `-inf`, `prob` returns `0`. When `False`,
      the implementation is free to save computation by evaluating something
      that matches the Categorical pmf at integer values in the support but
      produces an unrestricted result on other inputs.
      Default value: `False`.
    validate_args: Python `bool`, default `False`. When `True` distribution
      parameters are checked for validity despite possibly degrading runtime
      performance. When `False` invalid inputs may silently render incorrect
      outputs.
    allow_nan_stats: Python `bool`, default `True`. When `True`, statistics
      (e.g., mean, mode, variance) use the value "`NaN`" to indicate the
      result is undefined. When `False`, an exception is raised if one or
      more of the statistic's batch members are undefined.
    name: Python `str` name prefixed to Ops created by this class.
code: def __init__(
      self,
      logits=None,
      probs=None,
      dtype=tf.int32,
      force_probs_to_zero_outside_support=False,
      validate_args=False,
      allow_nan_stats=True,
      name="Categorical",
  ):
      """Initialize Categorical distributions using class log-probabilities.
  
      Args:
        logits: An N-D `Tensor`, `N >= 1`, representing the unnormalized
          log probabilities of a set of Categorical distributions. The first
          `N - 1` dimensions index into a batch of independent distributions
          and the last dimension represents a vector of logits for each class.
          Only one of `logits` or `probs` should be passed in.
        probs: An N-D `Tensor`, `N >= 1`, representing the probabilities
          of a set of Categorical distributions. The first `N - 1` dimensions
          index into a batch of independent distributions and the last dimension
          represents a vector of probabilities for each class. Only one of
          `logits` or `probs` should be passed in.
        dtype: The type of the event samples (default: int32).
        force_probs_to_zero_outside_support: Python `bool`. When `True`, negative
          values, values greater than N, and non-integer values are evaluated
          "strictly": `log_prob` returns `-inf`, `prob` returns `0`. When `False`,
          the implementation is free to save computation by evaluating something
          that matches the Categorical pmf at integer values in the support but
          produces an unrestricted result on other inputs.
          Default value: `False`.
        validate_args: Python `bool`, default `False`. When `True` distribution
          parameters are checked for validity despite possibly degrading runtime
          performance. When `False` invalid inputs may silently render incorrect
          outputs.
        allow_nan_stats: Python `bool`, default `True`. When `True`, statistics
          (e.g., mean, mode, variance) use the value "`NaN`" to indicate the
          result is undefined. When `False`, an exception is raised if one or
          more of the statistic's batch members are undefined.
        name: Python `str` name prefixed to Ops created by this class.
      """
      parameters = dict(locals())
      if (probs is None) == (logits is None):
          raise ValueError("Must pass probs or logits, but not both.")
      with tf.name_scope(name) as name:
          prob_logit_dtype = dtype_util.common_dtype(
              [probs, logits], tf.float32
          )
          self._probs = tensor_util.convert_nonref_to_tensor(
              probs, dtype_hint=prob_logit_dtype, name="probs"
          )
          self._logits = tensor_util.convert_nonref_to_tensor(
              logits, dtype_hint=prob_logit_dtype, name="logits"
          )
          self._force_probs_to_zero_outside_support = (
              force_probs_to_zero_outside_support
          )
  
          super(Categorical, self).__init__(
              dtype=dtype,
              reparameterization_type=reparameterization.NOT_REPARAMETERIZED,
              validate_args=validate_args,
              allow_nan_stats=allow_nan_stats,
              parameters=parameters,
              name=name,
          )
  
imports: import numpy
  import six
  import tensorflow.compat.v2
  from tensorflow_probability.python.bijectors import softmax_centered
  from tensorflow_probability.python.distributions import distribution
  from tensorflow_probability.python.distributions import kullback_leibler
  from tensorflow_probability.python.internal import assert_util
  from tensorflow_probability.python.internal import distribution_util
  from tensorflow_probability.python.internal import dtype_util
  from tensorflow_probability.python.internal import parameter_properties
  from tensorflow_probability.python.internal import prefer_static
  from tensorflow_probability.python.internal import reparameterization
  from tensorflow_probability.python.internal import samplers
  from tensorflow_probability.python.internal import tensor_util
  from tensorflow_probability.python.internal import tensorshape_util
label_desc: Use image node_id 1 to create a new Categorical object from inherited base classes: distribution, distribution with example: obj = Categorical(logits, probs, dtype, force_probs_to_zero_outside_support, validate_args, allow_nan_stats, name)