class_docstr: A unittest class for testing the Simple Black-box Adversarial Attacks (SimBA).
  
  This module tests SimBA.
  
  | Paper link: https://arxiv.org/abs/1905.07121
docstr: Test with SimBA
  :return:
docstr_tok: ["Test","with","SimBA",":","return",":"]
code: def _test_attack(self, classifier, x_test, y_test, targeted):
      """
      Test with SimBA
      :return:
      """
      x_test_original = x_test.copy()
  
      # set the targeted label
      if targeted:
          y_target = np.zeros(10)
          y_target[8] = 1.0
  
      #######
      # dct #
      #######
  
      df = SimBA(classifier, attack="dct", targeted=targeted)
  
      x_i = x_test_original[0][None, ...]
      if targeted:
          x_test_adv = df.generate(x_i, y=y_target.reshape(1, 10))
      else:
          x_test_adv = df.generate(x_i)
  
      for i in range(1, len(x_test_original)):
          x_i = x_test_original[i][None, ...]
          if targeted:
              tmp_x_test_adv = df.generate(
                  x_i, y=y_target.reshape(1, 10)
              )
              x_test_adv = np.concatenate([x_test_adv, tmp_x_test_adv])
          else:
              tmp_x_test_adv = df.generate(x_i)
              x_test_adv = np.concatenate([x_test_adv, tmp_x_test_adv])
  
      self.assertFalse((x_test == x_test_adv).all())
      self.assertFalse((0.0 == x_test_adv).all())
  
      y_pred = get_labels_np_array(classifier.predict(x_test_adv))
      self.assertFalse((y_test == y_pred).all())
  
      # Check that x_test has not been modified by attack and classifier
      self.assertAlmostEqual(
          float(np.max(np.abs(x_test_original - x_test))),
          0.0,
          delta=0.00001,
      )
  
      ######
      # px #
      ######
      df_px = SimBA(classifier, attack="px", targeted=targeted)
  
      x_i = x_test_original[0][None, ...]
      if targeted:
          x_test_adv = df_px.generate(x_i, y=y_target.reshape(1, 10))
      else:
          x_test_adv = df_px.generate(x_i)
  
      for i in range(1, len(x_test_original)):
          x_i = x_test_original[i][None, ...]
          if targeted:
              tmp_x_test_adv = df_px.generate(
                  x_i, y=y_target.reshape(1, 10)
              )
              x_test_adv = np.concatenate([x_test_adv, tmp_x_test_adv])
          else:
              tmp_x_test_adv = df_px.generate(x_i)
              x_test_adv = np.concatenate([x_test_adv, tmp_x_test_adv])
  
      self.assertFalse((x_test == x_test_adv).all())
      self.assertFalse((0.0 == x_test_adv).all())
  
      y_pred = get_labels_np_array(classifier.predict(x_test_adv))
      self.assertFalse((y_test == y_pred).all())
  
      # Check that x_test has not been modified by attack and classifier
      self.assertAlmostEqual(
          float(np.max(np.abs(x_test_original - x_test))),
          0.0,
          delta=0.00001,
      )
  
      #############
      # px - diag #
      #############
      df_px = SimBA(
          classifier, attack="px", targeted=targeted, order="diag"
      )
  
      x_i = x_test_original[0][None, ...]
      if targeted:
          x_test_adv = df_px.generate(x_i, y=y_target.reshape(1, 10))
      else:
          x_test_adv = df_px.generate(x_i)
  
      for i in range(1, len(x_test_original)):
          x_i = x_test_original[i][None, ...]
          if targeted:
              tmp_x_test_adv = df_px.generate(
                  x_i, y=y_target.reshape(1, 10)
              )
              x_test_adv = np.concatenate([x_test_adv, tmp_x_test_adv])
          else:
              tmp_x_test_adv = df_px.generate(x_i)
              x_test_adv = np.concatenate([x_test_adv, tmp_x_test_adv])
  
      self.assertFalse((x_test == x_test_adv).all())
      self.assertFalse((0.0 == x_test_adv).all())
  
      y_pred = get_labels_np_array(classifier.predict(x_test_adv))
      self.assertFalse((y_test == y_pred).all())
  
      # Check that x_test has not been modified by attack and classifier
      self.assertAlmostEqual(
          float(np.max(np.abs(x_test_original - x_test))),
          0.0,
          delta=0.00001,
      )
  
imports: from __future__ import absolute_import, division, print_function, unicode_literals
  import logging
  import unittest
  import numpy
  from art.attacks.evasion.simba import SimBA
  from art.estimators.estimator import BaseEstimator, NeuralNetworkMixin
  from art.estimators.classification.classifier import ClassifierMixin
  from art.utils import get_labels_np_array
  from tests.utils import TestBase
  from tests.utils import get_image_classifier_tf, get_image_classifier_kr, get_image_classifier_pt
  from tests.attacks.utils import backend_test_classifier_type_check_fail
label_desc: Use image node_id 8 for calling the TestSimBA obj's underlying member method code with example usage: obj._test_attack(classifier, x_test, y_test, targeted) without return types