class_docstr: Implementation of STRIP: A Defence Against Trojan Attacks on Deep Neural Networks (Gao et. al. 2020)
  
  | Paper link: https://arxiv.org/abs/1902.06531
class_docstr_tok: ["Implementation","of","STRIP",":","A","Defence","Against","Trojan","Attacks","on","Deep","Neural","Networks","(","Gao","et",".","al",".","2020",")","|","Paper","link",":","https",":","\/\/arxiv.org\/abs\/1902.06531"]
docstr: Mitigates the effect of poison on a classifier
  
  :param x_val: Validation data to use to mitigate the effect of poison.
docstr_tok: ["Mitigates","the","effect","of","poison","on","a","classifier",":","param","x_val",":","Validation","data","to","use","to","mitigate","the","effect","of","poison","."]
code: def mitigate(self, x_val: np.ndarray) -> None:
      """
      Mitigates the effect of poison on a classifier
  
      :param x_val: Validation data to use to mitigate the effect of poison.
      """
      self.validation_data = x_val
      entropies = []
  
      # Find normal entropy distribution
      for _, img in enumerate(tqdm(x_val)):
          selected_indices = np.random.choice(
              np.arange(len(x_val)), self.num_samples
          )
          perturbed_images = np.array(
              [
                  combine_images(img, x_val[idx])
                  for idx in selected_indices
              ]
          )
          perturbed_predictions = self.predict_fn(perturbed_images)
          normalized_entropy = np.sum(
              entropy(perturbed_predictions, base=2, axis=0)
          ) / float(self.num_samples)
          entropies.append(normalized_entropy)
  
      mean_entropy, std_entropy = norm.fit(entropies)
  
      # Set threshold to FAR percentile
      self.entropy_threshold = norm.ppf(
          self.false_acceptance_rate,
          loc=mean_entropy,
          scale=std_entropy,
      )
      if (
          self.entropy_threshold is not None
          and self.entropy_threshold < 0
      ):  # pragma: no cover
          logger.warning(
              "Entropy value is negative. Increase FAR for reasonable performance."
          )
  
file_path: adversarial-robustness-toolbox/art/estimators/poison_mitigation/strip/strip.py
imports: from __future__ import absolute_import, division, print_function, unicode_literals
  import logging
  from typing import Callable, Optional
  import numpy
  from scipy.stats import entropy, norm
  from tqdm.auto import tqdm
  from art.estimators.certification.abstain import AbstainPredictorMixin
label_desc: Use image node_id 3 for calling the STRIPMixin obj's underlying member method code with example usage: obj.mitigate(x_val) without return types