class_docstr: Implementation of methods in Neural Cleanse: Identifying and Mitigating Backdoor Attacks in Neural Networks.
  Wang et al. (2019).
  
  | Paper link: https://people.cs.uchicago.edu/~ravenben/publications/pdf/backdoor-sp19.pdf
class_docstr_tok: ["Implementation","of","methods","in","Neural","Cleanse",":","Identifying","and","Mitigating","Backdoor","Attacks","in","Neural","Networks",".","Wang","et","al",".","(","2019",")",".","|","Paper","link",":","https",":","\/\/people.cs.uchicago.edu\/~ravenben\/publications\/pdf\/backdoor-sp19.pdf"]
docstr: Returns a tuple of suspected of suspected poison labels and their mask and pattern
  :return: A list of tuples containing the the class index, mask, and pattern for suspected labels
docstr_tok: ["Returns","a","tuple","of","suspected","of","suspected","poison","labels","and","their","mask","and","pattern",":","return",":","A","list","of","tuples","containing","the","the","class","index",",","mask",",","and","pattern","for","suspected","labels"]
code: def outlier_detection(
      self, x_val: np.ndarray, y_val: np.ndarray
  ) -> List[Tuple[int, np.ndarray, np.ndarray]]:
      """
      Returns a tuple of suspected of suspected poison labels and their mask and pattern
      :return: A list of tuples containing the the class index, mask, and pattern for suspected labels
      """
      l1_norms = []
      masks = []
      patterns = []
      num_classes = self.nb_classes
      for class_idx in range(num_classes):
          # Assuming classes are indexed
          target_label = to_categorical(
              [class_idx], num_classes
          ).flatten()
          mask, pattern = self.generate_backdoor(
              x_val, y_val, target_label
          )
          norm = np.sum(np.abs(mask))
          l1_norms.append(norm)
          masks.append(mask)
          patterns.append(pattern)
  
      # assuming l1 norms would naturally create a normal distribution
      consistency_constant = 1.4826
  
      median = np.median(l1_norms)
      mad = consistency_constant * np.median(np.abs(l1_norms - median))
      # min_mad = np.abs(np.min(l1_norms) - median) / mad
      flagged_labels = []
  
      for class_idx in range(num_classes):
          anomaly_index = np.abs(l1_norms[class_idx] - median) / mad
          # Points with anomaly_index > 2 have 95% probability of being an outlier
          # Backdoor outliers show up as masks with small l1 norms
          if l1_norms[class_idx] <= median and anomaly_index > 2:
              logger.warning(
                  "Detected potential backdoor in class: %s",
                  str(class_idx),
              )
              flagged_labels.append(class_idx)
  
      return [
          (label, masks[label], patterns[label])
          for label in flagged_labels
      ]
  
file_path: adversarial-robustness-toolbox/art/estimators/poison_mitigation/neural_cleanse/neural_cleanse.py
imports: from __future__ import absolute_import, division, print_function, unicode_literals
  import logging
  from typing import Union, Tuple, List
  import numpy
  from art.estimators.certification.abstain import AbstainPredictorMixin
  from art.utils import to_categorical
label_desc: Use image node_id 11 for calling the NeuralCleanseMixin obj's underlying member method code with example usage: obj.outlier_detection(x_val, y_val) and returns: unknown