class_docstr: Computes binary confusion matrix.
docstr: Adds a single example input to the accumulator.
  
  Args:
    accumulator: Accumulator to add input to.
    labels: Expected values.
    predictions: Predicted values.
    example_weights: Weights for this example.
    example_id: ID for this example.
  
  Returns:
    Merged MatrixAccumulator of the original accumulator and the added inputs.
code: def add_input(
      self,
      accumulator: MatrixAccumulator,
      labels: Sequence[float],
      predictions: Sequence[float],
      example_weights: Optional[Sequence[float]],
      example_id: Optional[str],
  ) -> MatrixAccumulator:
      """Adds a single example input to the accumulator.
  
      Args:
        accumulator: Accumulator to add input to.
        labels: Expected values.
        predictions: Predicted values.
        example_weights: Weights for this example.
        example_id: ID for this example.
  
      Returns:
        Merged MatrixAccumulator of the original accumulator and the added inputs.
      """
      if example_weights is None or all(
          w is None for w in example_weights
      ):
          example_weights = [1] * len(labels)
  
      for threshold in self._thresholds:
          tp = 0.0
          tn = 0.0
          fp = 0.0
          fn = 0.0
          tp_example = None
          tn_example = None
          fp_example = None
          fn_example = None
          # We need to iterate here even though it is one example because one
          # example can contain multiple labels/predictions/example_weights.
          for label, prediction, example_weight in zip(
              labels, predictions, example_weights
          ):
              if (
                  label == 1.0
                  if self._enable_fractional_labels
                  else label > threshold
              ):
                  if prediction > threshold:
                      tp += example_weight
                      tp_example = example_id
                  else:
                      fn += example_weight
                      fn_example = example_id
              else:
                  if prediction > threshold:
                      fp += example_weight
                      fp_example = example_id
                  else:
                      tn += example_weight
                      tn_example = example_id
  
          accumulator[threshold] = self._merge_entry(
              accumulator=accumulator,
              threshold=threshold,
              entry=_ThresholdEntry(
                  Matrix(tp=tp, tn=tn, fp=fp, fn=fn),
                  tp_examples=[tp_example]
                  if tp_example is not None
                  else [],
                  tn_examples=[tn_example]
                  if tn_example is not None
                  else [],
                  fp_examples=[fp_example]
                  if fp_example is not None
                  else [],
                  fn_examples=[fn_example]
                  if fn_example is not None
                  else [],
              ),
          )
  
      return accumulator
  
file_path: model-analysis/tensorflow_model_analysis/contrib/aggregates/binary_confusion_matrices.py
imports: from typing import Dict, Iterable, List, NamedTuple, Optional, Sequence
  from tensorflow_model_analysis.experimental.lazytf import api
label_desc: Use image node_id 5 for calling the BinaryConfusionMatrices obj's underlying member method code with example usage: obj.add_input(accumulator, labels, predictions, example_weights, example_id) and returns: accumulator