tensorflow_probability/python/distributions/beta.py
def _kl_beta_beta(d1, d2, name=None):
  """Calculate the batchwise KL divergence KL(d1 || d2) with d1 and d2 Beta.

  Args:
    d1: instance of a Beta distribution object.
    d2: instance of a Beta distribution object.
    name: (optional) Name to use for created operations.
      default is "kl_beta_beta".

  Returns:
    Batchwise KL(d1 || d2)
  """
  def delta(fn, is_property=True):
    fn1 = getattr(d1, fn)
    fn2 = getattr(d2, fn)
    return (fn2 - fn1) if is_property else (fn2() - fn1())

  with tf.name_scope(name or "kl_beta_beta"):
    return (delta("_log_normalization", is_property=False) -
            tf.math.digamma(d1.concentration1) * delta("concentration1") -
            tf.math.digamma(d1.concentration0) * delta("concentration0") +
            (tf.math.digamma(d1.total_concentration) *
             delta("total_concentration")))
def _kl_beta_beta(d1, d2, name=None):
  """Calculate the batchwise KL divergence KL(d1 || d2) with d1 and d2 Beta.

  Args:
    d1: instance of a Beta distribution object.
    d2: instance of a Beta distribution object.
    name: (optional) Name to use for created operations.
      default is "kl_beta_beta".

  Returns:
    Batchwise KL(d1 || d2)
  """
  def delta(fn, is_property=True):
    fn1 = getattr(d1, fn)
    fn2 = getattr(d2, fn)
    return (fn2 - fn1) if is_property else (fn2() - fn1())

  with tf.name_scope(name or "kl_beta_beta"):
    return (delta("_log_normalization", is_property=False) -
            tf.math.digamma(d1.concentration1) * delta("concentration1") -
            tf.math.digamma(d1.concentration0) * delta("concentration0") +
            (tf.math.digamma(d1.total_concentration) *
             delta("total_concentration")))
def _kl_beta_beta ( d1 , d2 , name = None ) : def delta ( fn , is_property = True ) : fn1 = getattr ( d1 , fn ) fn2 = getattr ( d2 , fn ) return ( fn2 - fn1 ) if is_property else ( fn2 ( ) - fn1 ( ) ) with tf . name_scope ( name or "kl_beta_beta" ) : return ( delta ( "_log_normalization" , is_property = False ) - tf . math . digamma ( d1 . concentration1 ) * delta ( "concentration1" ) - tf . math . digamma ( d1 . concentration0 ) * delta ( "concentration0" ) + ( tf . math . digamma ( d1 . total_concentration ) * delta ( "total_concentration" ) ) )
Calculate the batchwise KL divergence KL(d1 || d2) with d1 and d2 Beta.

  Args:
    d1: instance of a Beta distribution object.
    d2: instance of a Beta distribution object.
    name: (optional) Name to use for created operations.
      default is "kl_beta_beta".

  Returns:
    Batchwise KL(d1 || d2)
Calculate the batchwise KL divergence KL ( d1 || d2 ) with d1 and d2 Beta .