class_docstr: Implementation of the boundary attack from Brendel et al. (2018). This is a powerful black-box attack that
  only requires final class prediction.
  
  | Paper link: https://arxiv.org/abs/1712.04248
class_docstr_tok: ["Implementation","of","the","boundary","attack","from","Brendel","et","al",".","(","2018",")",".","This","is","a","powerful","black-box","attack","that","only","requires","final","class","prediction",".","|","Paper","link",":","https",":","\/\/arxiv.org\/abs\/1712.04248"]
docstr: Find initial adversarial example for the attack.
  
  :param x: An array with one original input to be attacked.
  :param y: If `self.targeted` is true, then `y` represents the target label.
  :param y_p: The predicted label of x.
  :param init_pred: The predicted label of the initial image.
  :param adv_init: Initial array to act as an initial adversarial example.
  :param clip_min: Minimum value of an example.
  :param clip_max: Maximum value of an example.
  :return: an adversarial example.
docstr_tok: ["Find","initial","adversarial","example","for","the","attack",".",":","param","x",":","An","array","with","one","original","input","to","be","attacked",".",":","param","y",":","If","`","self.targeted","`","is","true",",","then","`","y","`","represents","the","target","label",".",":","param","y_p",":","The","predicted","label","of","x.",":","param","init_pred",":","The","predicted","label","of","the","initial","image",".",":","param","adv_init",":","Initial","array","to","act","as","an","initial","adversarial","example",".",":","param","clip_min",":","Minimum","value","of","an","example",".",":","param","clip_max",":","Maximum","value","of","an","example",".",":","return",":","an","adversarial","example","."]
code: def _init_sample(
      self,
      x: np.ndarray,
      y: int,
      y_p: int,
      init_pred: int,
      adv_init: np.ndarray,
      clip_min: float,
      clip_max: float,
  ) -> Optional[Tuple[np.ndarray, int]]:
      """
      Find initial adversarial example for the attack.
  
      :param x: An array with one original input to be attacked.
      :param y: If `self.targeted` is true, then `y` represents the target label.
      :param y_p: The predicted label of x.
      :param init_pred: The predicted label of the initial image.
      :param adv_init: Initial array to act as an initial adversarial example.
      :param clip_min: Minimum value of an example.
      :param clip_max: Maximum value of an example.
      :return: an adversarial example.
      """
      nprd = np.random.RandomState()
      initial_sample = None
  
      if self.targeted:
          # Attack satisfied
          if y == y_p:
              return None
  
          # Attack unsatisfied yet and the initial image satisfied
          if adv_init is not None and init_pred == y:
              return adv_init.astype(ART_NUMPY_DTYPE), init_pred
  
          # Attack unsatisfied yet and the initial image unsatisfied
          for _ in range(self.init_size):
              random_img = nprd.uniform(
                  clip_min, clip_max, size=x.shape
              ).astype(x.dtype)
              random_class = np.argmax(
                  self.estimator.predict(
                      np.array([random_img]), batch_size=self.batch_size
                  ),
                  axis=1,
              )[0]
  
              if random_class == y:
                  initial_sample = random_img, random_class
  
                  logger.info(
                      "Found initial adversarial image for targeted attack."
                  )
                  break
          else:
              logger.warning(
                  "Failed to draw a random image that is adversarial, attack failed."
              )
  
      else:
          # The initial image satisfied
          if adv_init is not None and init_pred != y_p:
              return adv_init.astype(ART_NUMPY_DTYPE), init_pred
  
          # The initial image unsatisfied
          for _ in range(self.init_size):
              random_img = nprd.uniform(
                  clip_min, clip_max, size=x.shape
              ).astype(x.dtype)
              random_class = np.argmax(
                  self.estimator.predict(
                      np.array([random_img]), batch_size=self.batch_size
                  ),
                  axis=1,
              )[0]
  
              if random_class != y_p:
                  initial_sample = random_img, random_class
  
                  logger.info(
                      "Found initial adversarial image for untargeted attack."
                  )
                  break
          else:  # pragma: no cover
              logger.warning(
                  "Failed to draw a random image that is adversarial, attack failed."
              )
  
      return initial_sample
  
imports: from __future__ import absolute_import, division, print_function, unicode_literals
  import logging
  from typing import List, Optional, Tuple, TYPE_CHECKING
  import numpy
  from tqdm.auto import tqdm, trange
  from art.attacks.attack import EvasionAttack
  from art.config import ART_NUMPY_DTYPE
  from art.estimators.estimator import BaseEstimator
  from art.estimators.classification.classifier import ClassifierMixin
  from art.utils import compute_success, to_categorical, check_and_transform_label_format, get_labels_np_array
label_desc: Use image node_id 6 for calling the BoundaryAttack obj's underlying member method code with example usage: obj._init_sample(x, y, y_p, init_pred, adv_init, clip_min, clip_max) and returns: initial_sample, None, adv_init,  init_pred, adv_init,  init_pred