models/moa_model.py
def kl_div(x, y):
        """
        Calculate KL divergence between two distributions.
        :param x: A distribution
        :param y: A distribution
        :return: The KL-divergence between x and y. Returns zeros if the KL-divergence contains NaN
        or Infinity.
        """
        dist_x = tf.distributions.Categorical(probs=x)
        dist_y = tf.distributions.Categorical(probs=y)
        result = tf.distributions.kl_divergence(dist_x, dist_y)

        # Don't return nans or infs
        is_finite = tf.reduce_all(tf.is_finite(result))

        def true_fn():
            return result

        def false_fn():
            return tf.zeros(tf.shape(result))

        result = tf.cond(is_finite, true_fn=true_fn, false_fn=false_fn)
        return result

        Calculate KL divergence between two distributions.
        :param x: A distribution
        :param y: A distribution
        :return: The KL-divergence between x and y. Returns zeros if the KL-divergence contains NaN
        or Infinity.
        
Calculate KL divergence between two distributions.
Calculate KL divergence between two distributions .
def kl_div(x, y):
        dist_x = tf.distributions.Categorical(probs=x)
        dist_y = tf.distributions.Categorical(probs=y)
        result = tf.distributions.kl_divergence(dist_x, dist_y)
        is_finite = tf.reduce_all(tf.is_finite(result))
        def true_fn():
            return result
        def false_fn():
            return tf.zeros(tf.shape(result))
        result = tf.cond(is_finite, true_fn=true_fn, false_fn=false_fn)
        return result
def kl_div ( x , y ) : dist_x = tf . distributions . Categorical ( probs = x ) dist_y = tf . distributions . Categorical ( probs = y ) result = tf . distributions . kl_divergence ( dist_x , dist_y ) is_finite = tf . reduce_all ( tf . is_finite ( result ) ) def true_fn ( ) : return result def false_fn ( ) : return tf . zeros ( tf . shape ( result ) ) result = tf . cond ( is_finite , true_fn = true_fn , false_fn = false_fn ) return result
Calculate KL divergence between two distributions.
Calculate KL divergence between two distributions .
"""
        Calculate KL divergence between two distributions.
        :param x: A distribution
        :param y: A distribution
        :return: The KL-divergence between x and y. Returns zeros if the KL-divergence contains NaN
        or Infinity.
        """ # Don't return nans or infs
The KL-divergence between x and y. Returns zeros if the KL-divergence contains NaN
or Infinity.
The KL - divergence between x and y . Returns zeros if the KL - divergence contains NaN or Infinity .
x
None
y
None