code: def loss_function(recon_x, x, mu, logvar):
      BCE = dy.binary_log_loss(
          recon_x, x
      )  # equiv to torch.nn.functional.binary_cross_entropy(?,?, size_average=False)
      # see Appendix B from VAE paper:
      # Kingma and Welling. Auto-Encoding Variational Bayes. ICLR, 2014
      # https://arxiv.org/abs/1312.6114
      # 0.5 * sum(1 + log(sigma^2) - mu^2 - sigma^2)
      KLD = -0.5 * dy.sum_elems(
          1 + logvar - dy.pow(mu, dy.scalarInput(2)) - dy.exp(logvar)
      )
  
      return BCE + KLD
  
file_path: dynet/examples/variational-autoencoder/basic-image-recon/vae.py
imports: from __future__ import print_function
  from utils import load_mnist, make_grid, pre_pillow_float_img_process, save_image
  import numpy
  import argparse
  import dynet
  import os
  import time
label_desc: Use image node_id 2 for calling a global function with example usage: loss_function(recon_x, x, mu, logvar) and returns: unknown