class_docstr: Categorical distribution.
  
  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}`.
  
  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",".","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","}","`",".","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 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).
    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.
docstr_tok: ["Initialize","Categorical","distributions","using","class","log-probabilities",".","Args",":","logits",":","An","N-D","`","Tensor","`",",","`","N",">","=","1","`",",","representing","the","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",")",".","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=dtypes.int32,
      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 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).
        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())
      with ops.name_scope(name, values=[logits, probs]) as name:
          (
              self._logits,
              self._probs,
          ) = distribution_util.get_logits_and_probs(
              logits=logits,
              probs=probs,
              validate_args=validate_args,
              multidimensional=True,
              name=name,
          )
  
          if validate_args:
              self._logits = (
                  distribution_util.embed_check_categorical_event_shape(
                      self._logits
                  )
              )
  
          logits_shape_static = (
              self._logits.get_shape().with_rank_at_least(1)
          )
          if logits_shape_static.ndims is not None:
              self._batch_rank = ops.convert_to_tensor(
                  logits_shape_static.ndims - 1,
                  dtype=dtypes.int32,
                  name="batch_rank",
              )
          else:
              with ops.name_scope(name="batch_rank"):
                  self._batch_rank = array_ops.rank(self._logits) - 1
  
          logits_shape = array_ops.shape(
              self._logits, name="logits_shape"
          )
          if (
              tensor_shape.dimension_value(logits_shape_static[-1])
              is not None
          ):
              self._event_size = ops.convert_to_tensor(
                  logits_shape_static.dims[-1].value,
                  dtype=dtypes.int32,
                  name="event_size",
              )
          else:
              with ops.name_scope(name="event_size"):
                  self._event_size = logits_shape[self._batch_rank]
  
          if logits_shape_static[:-1].is_fully_defined():
              self._batch_shape_val = constant_op.constant(
                  logits_shape_static[:-1].as_list(),
                  dtype=dtypes.int32,
                  name="batch_shape",
              )
          else:
              with ops.name_scope(name="batch_shape"):
                  self._batch_shape_val = logits_shape[:-1]
      super(Categorical, self).__init__(
          dtype=dtype,
          reparameterization_type=distribution.NOT_REPARAMETERIZED,
          validate_args=validate_args,
          allow_nan_stats=allow_nan_stats,
          parameters=parameters,
          graph_parents=[self._logits, self._probs],
          name=name,
      )
  
imports: from tensorflow.python.framework import constant_op
  from tensorflow.python.framework import dtypes
  from tensorflow.python.framework import ops
  from tensorflow.python.framework import tensor_shape
  from tensorflow.python.ops import array_ops
  from tensorflow.python.ops import math_ops
  from tensorflow.python.ops import nn_ops
  from tensorflow.python.ops import random_ops
  from tensorflow.python.ops.distributions import distribution
  from tensorflow.python.ops.distributions import kullback_leibler
  from tensorflow.python.ops.distributions import util
  from tensorflow.python.util import deprecation
  from tensorflow.python.util.tf_export import tf_export
label_desc: Use image node_id 1 to create a new Categorical object from inherited base classes: distribution with example: obj = Categorical(logits, probs, dtype, validate_args, allow_nan_stats, name)