Ejemplo n.º 1
0
 def kl(self, other):
     a0 = self.logits - U.max(self.logits, axis=1, keepdims=True)
     a1 = other.logits - U.max(other.logits, axis=1, keepdims=True)
     ea0 = tf.exp(a0)
     ea1 = tf.exp(a1)
     z0 = U.sum(ea0, axis=1, keepdims=True)
     z1 = U.sum(ea1, axis=1, keepdims=True)
     p0 = ea0 / z0
     return U.sum(p0 * (a0 - tf.log(z0) - a1 + tf.log(z1)), axis=1)
Ejemplo n.º 2
0
 def entropy(self):
     a0 = self.logits - U.max(self.logits, axis=1, keepdims=True)
     ea0 = tf.exp(a0)
     z0 = U.sum(ea0, axis=1, keepdims=True)
     p0 = ea0 / z0
     return U.sum(p0 * (tf.log(z0) - a0), axis=1)