class_docstr: A combiner which computes binary cross entropy.
code: def _cross_entropy(
      self,
      label: np.ndarray,
      prediction: np.ndarray,
  ) -> float:
      # smooth labels
      label = (
          label * (1.0 - self._label_smoothing)
          + 0.5 * self._label_smoothing
      )
  
      # If predictions are logits rather than probability, then the probability
      # should be sigmoid(logits). In this case, starting from logits, we can
      # derive the formula for cross entropy which is expressed in logits.
      # Let y = label, x = prediction logits
      # If x > 0,
      #  Cross entropy loss = y * - log(sigmoid(x)) + (1-y) * -log(1-sigmoid(x))
      #                    = x - x * y + log(1 + exp(-x))
      # If x < 0,
      #  Cross entropy loss = -x * y + log(1 + exp(x))
      # In summary, to merge the x > 0 and x < 0 cases, we obtain,
      # Cross entryopy loss = max(x, 0) - x * y + log(1 + exp(-abs(x)))
      if self._from_logits:
          elementwise_binary_cross_entropy = (
              np.maximum(prediction, 0)
              - np.multiply(prediction, label)
              + np.log(1 + np.exp(-np.abs(prediction)))
          )
      else:
          elementwise_binary_cross_entropy = -np.multiply(
              label, np.log(prediction)
          ) - np.multiply((1 - label), np.log(1 - prediction))
      binary_cross_entropy = np.mean(elementwise_binary_cross_entropy)
      # The np.item method makes sure the result is a one element numpy array and
      # returns the single element as a float.
      return metric_util.safe_to_scalar(binary_cross_entropy)
  
imports: import abc
  import dataclasses
  from typing import Iterable, Optional, Dict
  import apache_beam
  import numpy
  from tensorflow_model_analysis.metrics import metric_types
  from tensorflow_model_analysis.metrics import metric_util
  from tensorflow_model_analysis.proto import config_pb2
label_desc: Use image node_id 1 for calling the _BinaryCrossEntropyCombiner obj's underlying member method code with example usage: obj._cross_entropy(label, prediction) and returns: metric_util