def gaussian_kl_divergence(mean, ln_var):
 assert isinstance(mean, variable.Variable)
 assert isinstance(ln_var, variable.Variable)
 J = mean.size
 var = exponential.exp(ln_var)
 return ((((sum.sum((mean * mean)) + sum.sum(var)) - sum.sum(ln_var)) - J) * 0.5)

def gaussian_kl_divergence ( mean , ln_var ) : assert isinstance ( mean , variable . Variable ) assert isinstance ( ln_var , variable . Variable ) J = mean . size var = exponential . exp ( ln_var ) return ( ( ( ( sum . sum ( ( mean * mean ) ) + sum . sum ( var ) ) - sum . sum ( ln_var ) ) - J ) * 0.5 )
computes the kl-divergence of gaussian variables from the standard one .