class_docstr: Beta distribution.
  
  The Beta distribution is defined over the `(0, 1)` interval using parameters
  `concentration1` (aka "alpha") and `concentration0` (aka "beta").
  
  #### Mathematical Details
  
  The probability density function (pdf) is,
  
  ```none
  pdf(x; alpha, beta) = x**(alpha - 1) (1 - x)**(beta - 1) / Z
  Z = Gamma(alpha) Gamma(beta) / Gamma(alpha + beta)
  ```
  
  where:
  
  * `concentration1 = alpha`,
  * `concentration0 = beta`,
  * `Z` is the normalization constant, and,
  * `Gamma` is the [gamma function](
    https://en.wikipedia.org/wiki/Gamma_function).
  
  The concentration parameters represent mean total counts of a `1` or a `0`,
  i.e.,
  
  ```none
  concentration1 = alpha = mean * total_concentration
  concentration0 = beta  = (1. - mean) * total_concentration
  ```
  
  where `mean` in `(0, 1)` and `total_concentration` is a positive real number
  representing a mean `total_count = concentration1 + concentration0`.
  
  Distribution parameters are automatically broadcast in all functions; see
  examples for details.
  
  Warning: 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
  (Figurnov et al., 2018).
  
  #### Examples
  
  ```python
  import tensorflow_probability as tfp
  tfd = tfp.distributions
  
  # Create a batch of three Beta distributions.
  alpha = [1, 2, 3]
  beta = [1, 2, 3]
  dist = tfd.Beta(alpha, beta)
  
  dist.sample([4, 5])  # Shape [4, 5, 3]
  
  # `x` has three batch entries, each with two samples.
  x = [[.1, .4, .5],
       [.2, .3, .5]]
  # Calculate the probability of each pair of samples under the corresponding
  # distribution in `dist`.
  dist.prob(x)         # Shape [2, 3]
  ```
  
  ```python
  # Create batch_shape=[2, 3] via parameter broadcast:
  alpha = [[1.], [2]]      # Shape [2, 1]
  beta = [3., 4, 5]        # Shape [3]
  dist = tfd.Beta(alpha, beta)
  
  # alpha broadcast as: [[1., 1, 1,],
  #                      [2, 2, 2]]
  # beta broadcast as:  [[3., 4, 5],
  #                      [3, 4, 5]]
  # batch_Shape [2, 3]
  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, 3]
  ```
  
  Compute the gradients of samples w.r.t. the parameters:
  
  ```python
  alpha = tf.constant(1.0)
  beta = tf.constant(2.0)
  dist = tfd.Beta(alpha, beta)
  samples = dist.sample(5)  # Shape [5]
  loss = tf.reduce_mean(tf.square(samples))  # Arbitrary loss function
  # Unbiased stochastic gradients of the loss function
  grads = tf.gradients(loss, [alpha, beta])
  ```
  
  References:
    Implicit Reparameterization Gradients:
      [Figurnov et al., 2018]
      (http://papers.nips.cc/paper/7326-implicit-reparameterization-gradients)
      ([pdf]
      (http://papers.nips.cc/paper/7326-implicit-reparameterization-gradients.pdf))
class_docstr_tok: ["Beta","distribution",".","The","Beta","distribution","is","defined","over","the","`","(","0",",","1",")","`","interval","using","parameters","`","concentration1","`","(","aka","``","alpha","''",")","and","`","concentration0","`","(","aka","``","beta","''",")",".","#","#","#","#","Mathematical","Details","The","probability","density","function","(","pdf",")","is",",","``","`","none","pdf","(","x",";","alpha",",","beta",")","=","x","*","*","(","alpha","-","1",")","(","1","-","x",")","*","*","(","beta","-","1",")","\/","Z","Z","=","Gamma","(","alpha",")","Gamma","(","beta",")","\/","Gamma","(","alpha","+","beta",")","``","`","where",":","*","`","concentration1","=","alpha","`",",","*","`","concentration0","=","beta","`",",","*","`","Z","`","is","the","normalization","constant",",","and",",","*","`","Gamma","`","is","the","[","gamma","function","]","(","https",":","\/\/en.wikipedia.org\/wiki\/Gamma_function",")",".","The","concentration","parameters","represent","mean","total","counts","of","a","`","1","`","or","a","`","0","`",",","i.e.",",","``","`","none","concentration1","=","alpha","=","mean","*","total_concentration","concentration0","=","beta","=","(","1",".","-","mean",")","*","total_concentration","``","`","where","`","mean","`","in","`","(","0",",","1",")","`","and","`","total_concentration","`","is","a","positive","real","number","representing","a","mean","`","total_count","=","concentration1","+","concentration0","`",".","Distribution","parameters","are","automatically","broadcast","in","all","functions",";","see","examples","for","details",".","Warning",":","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","(","Figurnov","et","al.",",","2018",")",".","#","#","#","#","Examples","``","`","python","import","tensorflow_probability","as","tfp","tfd","=","tfp.distributions","#","Create","a","batch","of","three","Beta","distributions",".","alpha","=","[","1",",","2",",","3","]","beta","=","[","1",",","2",",","3","]","dist","=","tfd.Beta","(","alpha",",","beta",")","dist.sample","(","[","4",",","5","]",")","#","Shape","[","4",",","5",",","3","]","#","`","x","`","has","three","batch","entries",",","each","with","two","samples",".","x","=","[","[",".1",",",".4",",",".5","]",",","[",".2",",",".3",",",".5","]","]","#","Calculate","the","probability","of","each","pair","of","samples","under","the","corresponding","#","distribution","in","`","dist","`",".","dist.prob","(","x",")","#","Shape","[","2",",","3","]","``","`","``","`","python","#","Create","batch_shape=","[","2",",","3","]","via","parameter","broadcast",":","alpha","=","[","[","1",".","]",",","[","2","]","]","#","Shape","[","2",",","1","]","beta","=","[","3.",",","4",",","5","]","#","Shape","[","3","]","dist","=","tfd.Beta","(","alpha",",","beta",")","#","alpha","broadcast","as",":","[","[","1.",",","1",",","1",",","]",",","#","[","2",",","2",",","2","]","]","#","beta","broadcast","as",":","[","[","3.",",","4",",","5","]",",","#","[","3",",","4",",","5","]","]","#","batch_Shape","[","2",",","3","]","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",",","3","]","``","`","Compute","the","gradients","of","samples","w.r.t",".","the","parameters",":","``","`","python","alpha","=","tf.constant","(","1.0",")","beta","=","tf.constant","(","2.0",")","dist","=","tfd.Beta","(","alpha",",","beta",")","samples","=","dist.sample","(","5",")","#","Shape","[","5","]","loss","=","tf.reduce_mean","(","tf.square","(","samples",")",")","#","Arbitrary","loss","function","#","Unbiased","stochastic","gradients","of","the","loss","function","grads","=","tf.gradients","(","loss",",","[","alpha",",","beta","]",")","``","`","References",":","Implicit","Reparameterization","Gradients",":","[","Figurnov","et","al.",",","2018","]","(","http",":","\/\/papers.nips.cc\/paper\/7326-implicit-reparameterization-gradients",")","(","[","pdf","]","(","http",":","\/\/papers.nips.cc\/paper\/7326-implicit-reparameterization-gradients.pdf",")",")"]
code: def _mode(self):
      mode = (self.concentration1 - 1.0) / (
          self.total_concentration - 2.0
      )
      if self.allow_nan_stats:
          nan = array_ops.fill(
              self.batch_shape_tensor(),
              np.array(np.nan, dtype=self.dtype.as_numpy_dtype()),
              name="nan",
          )
          is_defined = math_ops.logical_and(
              self.concentration1 > 1.0, self.concentration0 > 1.0
          )
          return array_ops.where_v2(is_defined, mode, nan)
      return control_flow_ops.with_dependencies(
          [
              check_ops.assert_less(
                  array_ops.ones([], dtype=self.dtype),
                  self.concentration1,
                  message="Mode undefined for concentration1 <= 1.",
              ),
              check_ops.assert_less(
                  array_ops.ones([], dtype=self.dtype),
                  self.concentration0,
                  message="Mode undefined for concentration0 <= 1.",
              ),
          ],
          mode,
      )
  
imports: import numpy
  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 check_ops
  from tensorflow.python.ops import control_flow_ops
  from tensorflow.python.ops import math_ops
  from tensorflow.python.ops import nn
  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 20 for calling the Beta obj's underlying member method code with example usage: obj._mode() and returns: control_flow_ops, array_ops