code: def bernoulli_nll(x, y, reduce="sum"):
      """Computes the negative log-likelihood of a Bernoulli distribution.
  
      This function calculates the negative log-likelihood of a Bernoulli
      distribution.
  
      .. math::
  
          -\\log B(x; p) = -\\sum_i \\{x_i \\log(p_i) + \
          (1 - x_i)\\log(1 - p_i)\\},
  
      where :math:`p = \\sigma(y)`, :math:`\\sigma(\\cdot)` is a sigmoid
      function, and :math:`B(x; p)` is a Bernoulli distribution.
  
  
      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.
  
      .. note::
  
         As this function uses a sigmoid function, you can pass a result of
         fully-connected layer (that means :class:`Linear`) to this function
         directly.
  
      Args:
          x (:class:`~chainer.Variable` or :ref:`ndarray`): Input variable.
          y (:class:`~chainer.Variable` or :ref:`ndarray`): A variable
              representing the parameter of Bernoulli distribution.
          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
          )
  
      loss = softplus.softplus(y) - x * y
      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 2 for calling a global function with example usage: bernoulli_nll(x, y, reduce) and returns: sum, average, loss