code: def PDTP(  # pylint: disable=C0103
      target_estimator: "CLASSIFIER_TYPE",
      extra_estimator: "CLASSIFIER_TYPE",
      x: np.ndarray,
      y: np.ndarray,
      indexes: Optional[np.ndarray] = None,
      num_iter: int = 10,
      comparison_type: Optional[ComparisonType] = ComparisonType.RATIO,
  ) -> Tuple[np.ndarray, np.ndarray, np.ndarray]:
      """
      Compute the pointwise differential training privacy metric for the given classifier and training set.
  
      | Paper link: https://arxiv.org/abs/1712.09136
  
      :param target_estimator: The classifier to be analyzed.
      :param extra_estimator: Another classifier of the same type as the target classifier, but not yet fit.
      :param x: The training data of the classifier.
      :param y: Target values (class labels) of `x`, one-hot-encoded of shape (nb_samples, nb_classes) or indices of
                shape (nb_samples,).
      :param indexes: the subset of indexes of `x` to compute the PDTP metric on. If not supplied, PDTP will be
                      computed for all samples in `x`.
      :param num_iter: the number of iterations of PDTP computation to run for each sample. If not supplied,
                       defaults to 10. The result is the average across iterations.
      :param comparison_type: the way in which to compare the model outputs between models trained with and without
                              a certain sample. Default is to compute the ratio.
      :return: A tuple of three arrays, containing the average (worse, standard deviation) PDTP value for each sample in
               the training set respectively. The higher the value, the higher the privacy leakage for that sample.
      """
      from art.estimators.classification.pytorch import (
          PyTorchClassifier,
      )
      from art.estimators.classification.tensorflow import (
          TensorFlowV2Classifier,
      )
      from art.estimators.classification.scikitlearn import (
          ScikitlearnClassifier,
      )
  
      supported_classifiers = (
          PyTorchClassifier,
          TensorFlowV2Classifier,
          ScikitlearnClassifier,
      )
  
      if not isinstance(
          target_estimator, supported_classifiers
      ) or not isinstance(extra_estimator, supported_classifiers):
          raise ValueError(
              "PDTP metric only supports classifiers of type PyTorch, TensorFlowV2 and ScikitLearn."
          )
      if target_estimator.input_shape[0] != x.shape[1]:
          raise ValueError(
              "Shape of x does not match input_shape of classifier"
          )
      y = check_and_transform_label_format(
          y, nb_classes=target_estimator.nb_classes
      )
      if y.shape[0] != x.shape[0]:
          raise ValueError("Number of rows in x and y do not match")
  
      results = []
  
      for _ in range(num_iter):
          iter_results = []
          # get probabilities from original model
          pred = target_estimator.predict(x)
          if not is_probability_array(pred):
              try:
                  pred = scipy.special.softmax(pred, axis=1)
              except Exception as exc:  # pragma: no cover
                  raise ValueError(
                      "PDTP metric only supports classifiers that output logits or probabilities."
                  ) from exc
          # divide into 100 bins and return center of bin
          bins = np.array(np.arange(0.0, 1.01, 0.01).round(decimals=2))
          pred_bin_indexes = np.digitize(pred, bins)
          pred_bin_indexes[pred_bin_indexes == 101] = 100
          pred_bin = bins[pred_bin_indexes] - 0.005
  
          if indexes is None:
              indexes = np.array(range(x.shape[0]))
          if indexes is not None:
              for row in indexes:
                  # create new model without sample in training data
                  alt_x = np.delete(x, row, 0)
                  alt_y = np.delete(y, row, 0)
                  try:
                      extra_estimator.reset()
                  except NotImplementedError as exc:  # pragma: no cover
                      raise ValueError(
                          "PDTP metric can only be applied to classifiers that implement the reset method."
                      ) from exc
                  extra_estimator.fit(alt_x, alt_y)
                  # get probabilities from new model
                  alt_pred = extra_estimator.predict(x)
                  if not is_probability_array(alt_pred):
                      alt_pred = scipy.special.softmax(alt_pred, axis=1)
                  # divide into 100 bins and return center of bin
                  alt_pred_bin_indexes = np.digitize(alt_pred, bins)
                  alt_pred_bin_indexes[
                      alt_pred_bin_indexes == 101
                  ] = 100
                  alt_pred_bin = bins[alt_pred_bin_indexes] - 0.005
                  if comparison_type == ComparisonType.RATIO:
                      ratio_1 = pred_bin / alt_pred_bin
                      ratio_2 = alt_pred_bin / pred_bin
                      # get max value
                      max_value: float = max(
                          ratio_1.max(), ratio_2.max()
                      )
                  elif comparison_type == ComparisonType.DIFFERENCE:
                      max_value = float(
                          np.max(abs(pred_bin - alt_pred_bin))
                      )
                  else:
                      raise ValueError("Unsupported comparison type.")
                  iter_results.append(max_value)
              results.append(iter_results)
  
      # get average of iterations for each sample
      # We now have a list of lists, internal lists represent an iteration. We need to transpose and get averages.
      per_sample: list[list[float]] = list(map(list, zip(*results)))
      avg_per_sample = np.array(
          [sum(val) / len(val) for val in per_sample]
      )
      worse_per_sample = np.max(per_sample, axis=1)
      std_dev_per_sample = np.std(per_sample, axis=1)
  
      # return avg+worse leakage + standard deviation per sample
      return avg_per_sample, worse_per_sample, std_dev_per_sample
  
file_path: adversarial-robustness-toolbox/art/metrics/privacy/membership_leakage.py
imports: from __future__ import absolute_import, division, print_function, unicode_literals
  from typing import TYPE_CHECKING, Optional, Tuple
  from enum import Enum, auto
  import numpy
  import scipy
  from sklearn.neighbors import KNeighborsClassifier
  from art.utils import check_and_transform_label_format, is_probability_array
label_desc: Use image node_id 1 for calling a global function with example usage: PDTP(target_estimator, extra_estimator, x, y, indexes, num_iter, comparison_type) and returns: avg_per_sample,  worse_per_sample,  std_dev_per_sample