<s> import math <EOL> from chainer . functions . activation import softplus <EOL> from chainer . functions . math import exponential <EOL> from chainer . functions . math import sum <EOL> from chainer import variable <EOL> def gaussian_kl_divergence ( mean , ln_var ) : <EOL> """<STR_LIT>""" <EOL> assert isinstance ( mean , variable . Variable ) <EOL> assert isinstance ( ln_var , variable . Variable ) <EOL> J = mean . data . size <EOL> var = exponential . exp ( ln_var ) <EOL> return ( sum . sum ( mean * mean ) + sum . sum ( var ) - sum . sum ( ln_var ) - J ) * <NUM_LIT:0.5> <EOL> def bernoulli_nll ( x , y ) : <EOL> """<STR_LIT>""" <EOL> assert isinstance ( x , variable . Variable ) <EOL> assert isinstance ( y , variable . Variable ) <EOL> return sum . sum ( softplus . softplus ( y ) ) - sum . sum ( x * y ) <EOL> def gaussian_nll ( x , mean , ln_var ) : <EOL> """<STR_LIT>""" <EOL> assert isinstance ( x , variable . Variable ) <EOL> assert isinstance ( mean , variable . Variable ) <EOL> assert isinstance ( ln_var , variable . Variable ) <EOL> D = x . data . size <EOL> x_prec = exponential . exp ( - ln_var ) <EOL> x_diff = x - mean <EOL> x_power = ( x_diff * x_diff ) * x_prec * - <NUM_LIT:0.5> <EOL> return ( sum . sum ( ln_var ) + D * math . log ( <NUM_LIT:2> * math . pi ) ) / <NUM_LIT:2> - sum . sum ( x_power ) </s>
