code: def gaussian_nll(x, mean, ln_var, reduce="sum"):
      """Computes the negative log-likelihood of a Gaussian distribution.
  
      Given two variable ``mean`` representing :math:`\\mu` and ``ln_var``
      representing :math:`\\log(\\sigma^2)`, this function computes in
      elementwise manner the negative log-likelihood of :math:`x` on a
      Gaussian distribution :math:`N(\\mu, S)`,
  
      .. math::
  
          -\\log N(x; \\mu, \\sigma^2) =
          \\log\\left(\\sqrt{(2\\pi)^D |S|}\\right) +
          \\frac{1}{2}(x - \\mu)^\\top S^{-1}(x - \\mu),
  
      where :math:`D` is a dimension of :math:`x` and :math:`S` is a diagonal
      matrix where :math:`S_{ii} = \\sigma_i^2`.
  
      The output is a variable whose value depends on the value of
      the option ``reduce``. If it is ``'no'``, it holds the elementwise
      loss values. If it is ``'sum'`` or ``'mean'``, loss values are summed up
      or averaged respectively.
  
      Args:
          x (:class:`~chainer.Variable` or :ref:`ndarray`): Input variable.
          mean (:class:`~chainer.Variable` or :ref:`ndarray`): A variable
              representing mean of a Gaussian distribution, :math:`\\mu`.
          ln_var (:class:`~chainer.Variable` or :ref:`ndarray`): A variable
              representing logarithm of variance of a Gaussian distribution,
              :math:`\\log(\\sigma^2)`.
          reduce (str): Reduction option. Its value must be either
              ``'sum'``, ``'mean'`` or ``'no'``. Otherwise, :class:`ValueError`
              is raised.
  
      Returns:
          ~chainer.Variable:
              A variable representing the negative log-likelihood.
              If ``reduce`` is ``'no'``, the output variable holds array
              whose shape is same as one of (hence both of) input variables.
              If it is ``'sum'`` or ``'mean'``, the output variable holds a
              scalar value.
  
      """
      if reduce not in ("sum", "mean", "no"):
          raise ValueError(
              "only 'sum', 'mean' and 'no' are valid for 'reduce', but "
              "'%s' is given" % reduce
          )
  
      x_prec = exponential.exp(-ln_var)
      x_diff = x - mean
      x_power = (x_diff * x_diff) * x_prec * -0.5
      loss = (ln_var + math.log(2 * math.pi)) / 2 - x_power
      if reduce == "sum":
          return sum.sum(loss)
      elif reduce == "mean":
          return average.average(loss)
      else:
          return loss
  
file_path: chainer/chainer/functions/loss/vae.py
imports: import math
  from chainer.functions.activation import softplus
  from chainer.functions.math import average
  from chainer.functions.math import exponential
  from chainer.functions.math import sum
label_desc: Use image node_id 3 for calling a global function with example usage: gaussian_nll(x, mean, ln_var, reduce) and returns: sum, average, loss