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","]","``","`"]
code: def _maximum_likelihood_parameters(cls, value):
      return {
          "probs": tf.reduce_mean(
              tf.one_hot(
                  value,
                  depth=tf.reduce_max(value) + 1,
                  dtype=(
                      value.dtype
                      if dtype_util.is_floating(value.dtype)
                      else tf.float32
                  ),
              ),
              axis=0,
          )
      }
  
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 19 for calling the Categorical obj's underlying member method code with example usage: obj._maximum_likelihood_parameters(cls, value) and returns: dict