Photrek / Nonlinear-Statistical-Coupling

Apache License 2.0
5 stars 1 forks source link

CoupledNormal - entropy function #8

Closed Kevin-Chen0 closed 3 years ago

Kevin-Chen0 commented 3 years ago

Implement the entropy function for CoupledNormal. Use the commented out TFP's Student entropy code as a foundation.

See our latest nsc code here.

See original StudentT code here:

def entropy(df, scale, batch_shape, dtype):
  """Compute entropy of the StudentT distribution.
  Args:
    df: Floating-point `Tensor`. The degrees of freedom of the
      distribution(s). `df` must contain only positive values.
    scale: Floating-point `Tensor`; the scale(s) of the distribution(s). Must
      contain only positive values.
    batch_shape: Floating-point `Tensor` of the batch shape
    dtype: Return dtype.
  Returns:
    A `Tensor` of the entropy for a Student's T with these parameters.
  """
  v = tf.ones(batch_shape, dtype=dtype)
  u = v * df
  return (tf.math.log(tf.abs(scale)) + 0.5 * tf.math.log(df) +
          tfp_math.lbeta(u / 2., v / 2.) + 0.5 * (df + 1.) *
          (tf.math.digamma(0.5 * (df + 1.)) - tf.math.digamma(0.5 * df)))
danielmachinelearning commented 3 years ago

Saw this on StackOverflow on a tensorflow implementation of entropy. Not sure if this might help you.

https://stackoverflow.com/questions/56306943/how-to-calculate-entropy-on-float-numbers-over-a-tensor-in-python-keras