class_docstr: This class implements the `SquareAttack` attack.
  
  | Paper link: https://arxiv.org/abs/1912.00049
class_docstr_tok: ["This","class","implements","the","`","SquareAttack","`","attack",".","|","Paper","link",":","https",":","\/\/arxiv.org\/abs\/1912.00049"]
docstr: Create a :class:`.SquareAttack` instance.
  
  :param estimator: An trained estimator.
  :param norm: The norm of the adversarial perturbation. Possible values: "inf", np.inf, 1 or 2.
  :param adv_criterion: The criterion which the attack should use in determining adversariality.
  :param loss: The loss function which the attack should use for optimization.
  :param max_iter: Maximum number of iterations.
  :param eps: Maximum perturbation that the attacker can introduce.
  :param p_init: Initial fraction of elements.
  :param nb_restarts: Number of restarts.
  :param batch_size: Batch size for estimator evaluations.
  :param verbose: Show progress bars.
docstr_tok: ["Create","a",":","class",":","`",".SquareAttack","`","instance",".",":","param","estimator",":","An","trained","estimator",".",":","param","norm",":","The","norm","of","the","adversarial","perturbation",".","Possible","values",":","``","inf","''",",","np.inf",",","1","or","2.",":","param","adv_criterion",":","The","criterion","which","the","attack","should","use","in","determining","adversariality",".",":","param","loss",":","The","loss","function","which","the","attack","should","use","for","optimization",".",":","param","max_iter",":","Maximum","number","of","iterations",".",":","param","eps",":","Maximum","perturbation","that","the","attacker","can","introduce",".",":","param","p_init",":","Initial","fraction","of","elements",".",":","param","nb_restarts",":","Number","of","restarts",".",":","param","batch_size",":","Batch","size","for","estimator","evaluations",".",":","param","verbose",":","Show","progress","bars","."]
code: def __init__(
      self,
      estimator: "CLASSIFIER_TYPE",
      norm: Union[int, float, str] = np.inf,
      adv_criterion: Union[
          Callable[[np.ndarray, np.ndarray], bool], None
      ] = None,
      loss: Union[
          Callable[[np.ndarray, np.ndarray], np.ndarray], None
      ] = None,
      max_iter: int = 100,
      eps: float = 0.3,
      p_init: float = 0.8,
      nb_restarts: int = 1,
      batch_size: int = 128,
      verbose: bool = True,
  ):
      """
      Create a :class:`.SquareAttack` instance.
  
      :param estimator: An trained estimator.
      :param norm: The norm of the adversarial perturbation. Possible values: "inf", np.inf, 1 or 2.
      :param adv_criterion: The criterion which the attack should use in determining adversariality.
      :param loss: The loss function which the attack should use for optimization.
      :param max_iter: Maximum number of iterations.
      :param eps: Maximum perturbation that the attacker can introduce.
      :param p_init: Initial fraction of elements.
      :param nb_restarts: Number of restarts.
      :param batch_size: Batch size for estimator evaluations.
      :param verbose: Show progress bars.
      """
      super().__init__(estimator=estimator)
  
      self.norm = norm
  
      if adv_criterion is not None:
          self.adv_criterion = adv_criterion
      elif isinstance(self.estimator, ClassifierMixin):
          self.adv_criterion = lambda y_pred, y: np.argmax(
              y_pred, axis=1
          ) != np.argmax(y, axis=1)
      else:  # pragma: no cover
          raise ValueError(
              "No acceptable adversarial criterion available."
          )
  
      if loss is not None:
          self.loss = loss
      elif isinstance(self.estimator, ClassifierMixin):
          self.loss = self._get_logits_diff
      else:  # pragma: no cover
          raise ValueError("No acceptable loss available.")
  
      self.max_iter = max_iter
      self.eps = eps
      self.p_init = p_init
      self.nb_restarts = nb_restarts
      self.batch_size = batch_size
      self.verbose = verbose
      self._check_params()
  
file_path: adversarial-robustness-toolbox/art/attacks/evasion/square_attack.py
imports: import bisect
  import logging
  import math
  import random
  from typing import Optional, Union, Callable, TYPE_CHECKING
  import numpy
  from tqdm.auto import trange
  from art.config import ART_NUMPY_DTYPE
  from art.attacks.attack import EvasionAttack
  from art.estimators.estimator import BaseEstimator, NeuralNetworkMixin
  from art.estimators.classification.classifier import ClassifierMixin
  from art.utils import check_and_transform_label_format, get_labels_np_array
label_desc: Use image node_id 1 to create a new SquareAttack object from inherited base classes: EvasionAttack with example: obj = SquareAttack(estimator, norm, adv_criterion, loss, max_iter, eps, p_init, nb_restarts, batch_size, verbose)