class_docstr: Dirichlet distribution.
  
  The Dirichlet distribution is defined over the
  [`(k-1)`-simplex](https://en.wikipedia.org/wiki/Simplex) using a positive,
  length-`k` vector `concentration` (`k > 1`). The Dirichlet is identically the
  Beta distribution when `k = 2`.
  
  #### Mathematical Details
  
  The Dirichlet is a distribution over the open `(k-1)`-simplex, i.e.,
  
  ```none
  S^{k-1} = { (x_0, ..., x_{k-1}) in R^k : sum_j x_j = 1 and all_j x_j > 0 }.
  ```
  
  The probability density function (pdf) is,
  
  ```none
  pdf(x; alpha) = prod_j x_j**(alpha_j - 1) / Z
  Z = prod_j Gamma(alpha_j) / Gamma(sum_j alpha_j)
  ```
  
  where:
  
  * `x in S^{k-1}`, i.e., the `(k-1)`-simplex,
  * `concentration = alpha = [alpha_0, ..., alpha_{k-1}]`, `alpha_j > 0`,
  * `Z` is the normalization constant aka the [multivariate beta function](
    https://en.wikipedia.org/wiki/Beta_function#Multivariate_beta_function),
    and,
  * `Gamma` is the [gamma function](
    https://en.wikipedia.org/wiki/Gamma_function).
  
  The `concentration` represents mean total counts of class occurrence, i.e.,
  
  ```none
  concentration = alpha = mean * total_concentration
  ```
  
  where `mean` in `S^{k-1}` and `total_concentration` is a positive real number
  representing a mean total count.
  
  Distribution parameters are automatically broadcast in all functions; see
  examples for details.
  
  Warning: Some components of the samples can be zero due to finite precision.
  This happens more often when some of the concentrations are very small.
  Make sure to round the samples to `np.finfo(dtype).tiny` before computing the
  density.
  
  Samples of this distribution are reparameterized (pathwise differentiable).
  The derivatives are computed using the approach described in the paper
  
  [Michael Figurnov, Shakir Mohamed, Andriy Mnih.
  Implicit Reparameterization Gradients, 2018](https://arxiv.org/abs/1805.08498)
  
  #### Examples
  
  ```python
  import tensorflow_probability as tfp
  tfd = tfp.distributions
  
  # Create a single trivariate Dirichlet, with the 3rd class being three times
  # more frequent than the first. I.e., batch_shape=[], event_shape=[3].
  alpha = [1., 2, 3]
  dist = tfd.Dirichlet(alpha)
  
  dist.sample([4, 5])  # shape: [4, 5, 3]
  
  # x has one sample, one batch, three classes:
  x = [.2, .3, .5]   # shape: [3]
  dist.prob(x)       # shape: []
  
  # x has two samples from one batch:
  x = [[.1, .4, .5],
       [.2, .3, .5]]
  dist.prob(x)         # shape: [2]
  
  # alpha will be broadcast to shape [5, 7, 3] to match x.
  x = [[...]]   # shape: [5, 7, 3]
  dist.prob(x)  # shape: [5, 7]
  ```
  
  ```python
  # Create batch_shape=[2], event_shape=[3]:
  alpha = [[1., 2, 3],
           [4, 5, 6]]   # shape: [2, 3]
  dist = tfd.Dirichlet(alpha)
  
  dist.sample([4, 5])  # shape: [4, 5, 2, 3]
  
  x = [.2, .3, .5]
  # x will be broadcast as [[.2, .3, .5],
  #                         [.2, .3, .5]],
  # thus matching batch_shape [2, 3].
  dist.prob(x)         # shape: [2]
  ```
  
  Compute the gradients of samples w.r.t. the parameters:
  
  ```python
  alpha = tf.constant([1.0, 2.0, 3.0])
  dist = tfd.Dirichlet(alpha)
  samples = dist.sample(5)  # Shape [5, 3]
  loss = tf.reduce_mean(tf.square(samples))  # Arbitrary loss function
  # Unbiased stochastic gradients of the loss function
  grads = tf.gradients(loss, alpha)
  ```
class_docstr_tok: ["Dirichlet","distribution",".","The","Dirichlet","distribution","is","defined","over","the","[","`","(","k-1",")","`","-simplex","]","(","https",":","\/\/en.wikipedia.org\/wiki\/Simplex",")","using","a","positive",",","length-","`","k","`","vector","`","concentration","`","(","`","k",">","1","`",")",".","The","Dirichlet","is","identically","the","Beta","distribution","when","`","k","=","2","`",".","#","#","#","#","Mathematical","Details","The","Dirichlet","is","a","distribution","over","the","open","`","(","k-1",")","`","-simplex",",","i.e.",",","``","`","none","S^","{","k-1","}","=","{","(","x_0",",","...",",","x_","{","k-1","}",")","in","R^k",":","sum_j","x_j","=","1","and","all_j","x_j",">","0","}",".","``","`","The","probability","density","function","(","pdf",")","is",",","``","`","none","pdf","(","x",";","alpha",")","=","prod_j","x_j","*","*","(","alpha_j","-","1",")","\/","Z","Z","=","prod_j","Gamma","(","alpha_j",")","\/","Gamma","(","sum_j","alpha_j",")","``","`","where",":","*","`","x","in","S^","{","k-1","}","`",",","i.e.",",","the","`","(","k-1",")","`","-simplex",",","*","`","concentration","=","alpha","=","[","alpha_0",",","...",",","alpha_","{","k-1","}","]","`",",","`","alpha_j",">","0","`",",","*","`","Z","`","is","the","normalization","constant","aka","the","[","multivariate","beta","function","]","(","https",":","\/\/en.wikipedia.org\/wiki\/Beta_function","#","Multivariate_beta_function",")",",","and",",","*","`","Gamma","`","is","the","[","gamma","function","]","(","https",":","\/\/en.wikipedia.org\/wiki\/Gamma_function",")",".","The","`","concentration","`","represents","mean","total","counts","of","class","occurrence",",","i.e.",",","``","`","none","concentration","=","alpha","=","mean","*","total_concentration","``","`","where","`","mean","`","in","`","S^","{","k-1","}","`","and","`","total_concentration","`","is","a","positive","real","number","representing","a","mean","total","count",".","Distribution","parameters","are","automatically","broadcast","in","all","functions",";","see","examples","for","details",".","Warning",":","Some","components","of","the","samples","can","be","zero","due","to","finite","precision",".","This","happens","more","often","when","some","of","the","concentrations","are","very","small",".","Make","sure","to","round","the","samples","to","`","np.finfo","(","dtype",")",".tiny","`","before","computing","the","density",".","Samples","of","this","distribution","are","reparameterized","(","pathwise","differentiable",")",".","The","derivatives","are","computed","using","the","approach","described","in","the","paper","[","Michael","Figurnov",",","Shakir","Mohamed",",","Andriy","Mnih",".","Implicit","Reparameterization","Gradients",",","2018","]","(","https",":","\/\/arxiv.org\/abs\/1805.08498",")","#","#","#","#","Examples","``","`","python","import","tensorflow_probability","as","tfp","tfd","=","tfp.distributions","#","Create","a","single","trivariate","Dirichlet",",","with","the","3rd","class","being","three","times","#","more","frequent","than","the","first",".","I.e.",",","batch_shape=","[","]",",","event_shape=","[","3","]",".","alpha","=","[","1.",",","2",",","3","]","dist","=","tfd.Dirichlet","(","alpha",")","dist.sample","(","[","4",",","5","]",")","#","shape",":","[","4",",","5",",","3","]","#","x","has","one","sample",",","one","batch",",","three","classes",":","x","=","[",".2",",",".3",",",".5","]","#","shape",":","[","3","]","dist.prob","(","x",")","#","shape",":","[","]","#","x","has","two","samples","from","one","batch",":","x","=","[","[",".1",",",".4",",",".5","]",",","[",".2",",",".3",",",".5","]","]","dist.prob","(","x",")","#","shape",":","[","2","]","#","alpha","will","be","broadcast","to","shape","[","5",",","7",",","3","]","to","match","x.","x","=","[","[","...","]","]","#","shape",":","[","5",",","7",",","3","]","dist.prob","(","x",")","#","shape",":","[","5",",","7","]","``","`","``","`","python","#","Create","batch_shape=","[","2","]",",","event_shape=","[","3","]",":","alpha","=","[","[","1.",",","2",",","3","]",",","[","4",",","5",",","6","]","]","#","shape",":","[","2",",","3","]","dist","=","tfd.Dirichlet","(","alpha",")","dist.sample","(","[","4",",","5","]",")","#","shape",":","[","4",",","5",",","2",",","3","]","x","=","[",".2",",",".3",",",".5","]","#","x","will","be","broadcast","as","[","[",".2",",",".3",",",".5","]",",","#","[",".2",",",".3",",",".5","]","]",",","#","thus","matching","batch_shape","[","2",",","3","]",".","dist.prob","(","x",")","#","shape",":","[","2","]","``","`","Compute","the","gradients","of","samples","w.r.t",".","the","parameters",":","``","`","python","alpha","=","tf.constant","(","[","1.0",",","2.0",",","3.0","]",")","dist","=","tfd.Dirichlet","(","alpha",")","samples","=","dist.sample","(","5",")","#","Shape","[","5",",","3","]","loss","=","tf.reduce_mean","(","tf.square","(","samples",")",")","#","Arbitrary","loss","function","#","Unbiased","stochastic","gradients","of","the","loss","function","grads","=","tf.gradients","(","loss",",","alpha",")","``","`"]
code: def _mode(self):
      concentration = tf.convert_to_tensor(self.concentration)
      k = tf.cast(tf.shape(concentration)[-1], self.dtype)
      total_concentration = tf.reduce_sum(concentration, axis=-1)
      mode = (concentration - 1.0) / (
          total_concentration[..., tf.newaxis] - k
      )
      if self.allow_nan_stats:
          return tf.where(
              tf.reduce_all(
                  concentration > 1.0, axis=-1, keepdims=True
              ),
              mode,
              dtype_util.as_numpy_dtype(self.dtype)(np.nan),
          )
      assertions = [
          assert_util.assert_less(
              tf.ones([], self.dtype),
              concentration,
              message="Mode undefined when any concentration <= 1",
          )
      ]
      with tf.control_dependencies(assertions):
          return tf.identity(mode)
  
imports: import numpy
  import tensorflow.compat.v2
  from tensorflow_probability.python.bijectors import softmax_centered
  from tensorflow_probability.python.bijectors import softplus
  from tensorflow_probability.python.distributions import distribution
  from tensorflow_probability.python.distributions import gamma
  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 tensor_util
  from tensorflow_probability.python.internal import tensorshape_util
label_desc: Use image node_id 14 for calling the Dirichlet obj's underlying member method code with example usage: obj._mode() and returns: tf, tf