code: def calculate_statistic(
      pred: np.ndarray,
      labels: np.ndarray,
      sample_weight: Optional[np.ndarray] = None,
      is_logits: bool = True,
      option: str = "logit",
      small_value: float = 1e-45,
  ):
      """Calculates the statistics of each sample.
  
      The statistics is:
        for option="conf with prob", p, the probability of the true class;
        for option="xe", the cross-entropy loss;
        for option="logit", log(p / (1 - p));
        for option="conf with logit", max(logits);
        for option="hinge", logit of the true class - max(logits of the other
        classes).
  
      Args:
        pred: the logits or probability vectors, depending on the value of is_logit.
          An array of size n by c where n is the number of samples and c is the
          number of classes
        labels: true labels of samples (integer valued)
        sample_weight: a vector of weights of shape (num_samples, ) that are
          assigned to individual samples. If not provided, then each sample is
          given unit weight. Only the LogisticRegressionAttacker and the
          RandomForestAttacker support sample weights.
        is_logits: whether pred is logits or probability vectors
        option: confidence using probability, xe loss, logit of confidence,
          confidence using logits, hinge loss
        small_value: a small value to avoid numerical issue
  
      Returns:
        the computed statistics as size n array
      """
      if option not in [
          "conf with prob",
          "xe",
          "logit",
          "conf with logit",
          "hinge",
      ]:
          raise ValueError(
              'option should be one of ["conf with prob", "xe", "logit", "conf with logit", "hinge"].'
          )
      if option in ["conf with logit", "hinge"]:
          if not is_logits:  # the input needs to be the logits
              raise ValueError(
                  'To compute statistics with option "conf with logit" '
                  'or "hinge", the input must be logits instead of '
                  "probability vectors."
              )
      elif is_logits:
          pred = convert_logit_to_prob(pred)
  
      n = labels.size  # number of samples
      if option in ["conf with prob", "conf with logit"]:
          return pred[range(n), labels]
      if option == "xe":
          return log_loss(labels, pred, sample_weight=sample_weight)
      if option == "logit":
          p_true = pred[range(n), labels]
          pred[range(n), labels] = 0
          p_other = pred.sum(axis=1)
          return np.log(p_true + small_value) - np.log(
              p_other + small_value
          )
      if option == "hinge":
          l_true = pred[range(n), labels]
          pred[range(n), labels] = -np.inf
          return l_true - pred.max(axis=1)
      raise ValueError
  
file_path: privacy/tensorflow_privacy/privacy/privacy_tests/membership_inference_attack/advanced_mia.py
imports: import functools
  from typing import Optional, Sequence, Union
  import numpy
  import scipy.stats
  from tensorflow_privacy.privacy.privacy_tests.utils import log_loss
label_desc: Use image node_id 5 for calling a global function with example usage: calculate_statistic(pred, labels, sample_weight, is_logits, option, small_value) and returns: pred, log_loss, unknown, unknown