class_docstr: SPSA Attack (Uesato et al. 2018).
  Based on: https://arxiv.org/abs/1802.05666
  
  :param predict: predict function (single argument: input).
  :param eps: the L_inf budget of the attack.
  :param delta: scaling parameter of SPSA.
  :param lr: the learning rate of the `Adam` optimizer.
  :param nb_iter: number of iterations of the attack.
  :param nb_sample: number of samples for SPSA gradient approximation.
  :param max_batch_size: maximum batch size to be evaluated at once.
  :param targeted: [description]
  :param loss_fn: loss function (dual arguments: output, target).
  :param clip_min: upper bound of image values.
  :param clip_max: lower bound of image values.
class_docstr_tok: ["SPSA","Attack","(","Uesato","et","al",".","2018",")",".","Based","on",":","https",":","\/\/arxiv.org\/abs\/1802.05666",":","param","predict",":","predict","function","(","single","argument",":","input",")",".",":","param","eps",":","the","L_inf","budget","of","the","attack",".",":","param","delta",":","scaling","parameter","of","SPSA",".",":","param","lr",":","the","learning","rate","of","the","`","Adam","`","optimizer",".",":","param","nb_iter",":","number","of","iterations","of","the","attack",".",":","param","nb_sample",":","number","of","samples","for","SPSA","gradient","approximation",".",":","param","max_batch_size",":","maximum","batch","size","to","be","evaluated","at","once",".",":","param","targeted",":","[","description","]",":","param","loss_fn",":","loss","function","(","dual","arguments",":","output",",","target",")",".",":","param","clip_min",":","upper","bound","of","image","values",".",":","param","clip_max",":","lower","bound","of","image","values","."]
docstr: Perturbs the input `x` based on SPSA attack.
  
  :param x: input tensor.
  :param y: label tensor (default=`None`). if `self.targeted` is `False`,
            `y` is the ground-truth label. if it's `None`, then `y` is
            computed as the predicted label of `x`.
            if `self.targeted` is `True`, `y` is the target label.
  
  :return: the perturbated input.
docstr_tok: ["Perturbs","the","input","`","x","`","based","on","SPSA","attack",".",":","param","x",":","input","tensor",".",":","param","y",":","label","tensor","(","default=","`","None","`",")",".","if","`","self.targeted","`","is","`","False","`",",","`","y","`","is","the","ground-truth","label",".","if","it","'s","`","None","`",",","then","`","y","`","is","computed","as","the","predicted","label","of","`","x","`",".","if","`","self.targeted","`","is","`","True","`",",","`","y","`","is","the","target","label",".",":","return",":","the","perturbated","input","."]
code: def perturb(self, x, y=None):  # pylint: disable=arguments-differ
      """Perturbs the input `x` based on SPSA attack.
  
      :param x: input tensor.
      :param y: label tensor (default=`None`). if `self.targeted` is `False`,
                `y` is the ground-truth label. if it's `None`, then `y` is
                computed as the predicted label of `x`.
                if `self.targeted` is `True`, `y` is the target label.
  
      :return: the perturbated input.
      """
  
      x, y = self._verify_and_process_inputs(x, y)
  
      if self.targeted:
  
          def loss_fn(*args):
              return self.loss_fn(*args)
  
      else:
  
          def loss_fn(*args):
              return -self.loss_fn(*args)
  
      return spsa_perturb(
          self.predict,
          loss_fn,
          x,
          y,
          self.eps,
          self.delta,
          self.lr,
          self.nb_iter,
          self.nb_sample,
          self.max_batch_size,
          self.clip_min,
          self.clip_max,
      )
  
file_path: advertorch/advertorch/attacks/spsa.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  from __future__ import unicode_literals
  import warnings
  import torch
  from .base import Attack
  from .base import LabelMixin
  from .utils import MarginalLoss
  from ..utils import is_float_or_torch_tensor, batch_clamp, clamp
label_desc: Use image node_id 2 for calling the LinfSPSAAttack obj's underlying member method code with example usage: obj.perturb(x, y) and returns: spsa_perturb, self, unknown