class_docstr: Common class for different variations of implementation of the Projected Gradient Descent attack. The attack is an
  iterative method in which, after each iteration, the perturbation is projected on an lp-ball of specified radius (in
  addition to clipping the values of the adversarial sample so that it lies in the permitted data range). This is the
  attack proposed by Madry et al. for adversarial training.
  
  | Paper link: https://arxiv.org/abs/1706.06083
docstr: Create a :class:`.ProjectedGradientDescentCommon` instance.
  
  :param estimator: A trained classifier.
  :param norm: The norm of the adversarial perturbation supporting "inf", np.inf, 1 or 2.
  :param eps: Maximum perturbation that the attacker can introduce.
  :param eps_step: Attack step size (input variation) at each iteration.
  :param random_eps: When True, epsilon is drawn randomly from truncated normal distribution. The literature
      suggests this for FGSM based training to generalize across different epsilons. eps_step is
      modified to preserve the ratio of eps / eps_step. The effectiveness of this method with PGD
      is untested (https://arxiv.org/pdf/1611.01236.pdf).
  :param decay: Decay factor for accumulating the velocity vector when using momentum.
  :param max_iter: The maximum number of iterations.
  :param targeted: Indicates whether the attack is targeted (True) or untargeted (False).
  :param num_random_init: Number of random initialisations within the epsilon ball. For num_random_init=0
      starting at the original input.
  :param batch_size: Size of the batch on which adversarial samples are generated.
  :param summary_writer: Activate summary writer for TensorBoard.
                         Default is `False` and deactivated summary writer.
                         If `True` save runs/CURRENT_DATETIME_HOSTNAME in current directory.
                         If of type `str` save in path.
                         If of type `SummaryWriter` apply provided custom summary writer.
                         Use hierarchical folder structure to compare between runs easily. e.g. pass in
                         ‘runs/exp1’, ‘runs/exp2’, etc. for each new experiment to compare across them.
  :param verbose: Show progress bars.
docstr_tok: ["Create","a",":","class",":","`",".ProjectedGradientDescentCommon","`","instance",".",":","param","estimator",":","A","trained","classifier",".",":","param","norm",":","The","norm","of","the","adversarial","perturbation","supporting","``","inf","''",",","np.inf",",","1","or","2.",":","param","eps",":","Maximum","perturbation","that","the","attacker","can","introduce",".",":","param","eps_step",":","Attack","step","size","(","input","variation",")","at","each","iteration",".",":","param","random_eps",":","When","True",",","epsilon","is","drawn","randomly","from","truncated","normal","distribution",".","The","literature","suggests","this","for","FGSM","based","training","to","generalize","across","different","epsilons",".","eps_step","is","modified","to","preserve","the","ratio","of","eps","\/","eps_step",".","The","effectiveness","of","this","method","with","PGD","is","untested","(","https",":","\/\/arxiv.org\/pdf\/1611.01236.pdf",")",".",":","param","decay",":","Decay","factor","for","accumulating","the","velocity","vector","when","using","momentum",".",":","param","max_iter",":","The","maximum","number","of","iterations",".",":","param","targeted",":","Indicates","whether","the","attack","is","targeted","(","True",")","or","untargeted","(","False",")",".",":","param","num_random_init",":","Number","of","random","initialisations","within","the","epsilon","ball",".","For","num_random_init=0","starting","at","the","original","input",".",":","param","batch_size",":","Size","of","the","batch","on","which","adversarial","samples","are","generated",".",":","param","summary_writer",":","Activate","summary","writer","for","TensorBoard",".","Default","is","`","False","`","and","deactivated","summary","writer",".","If","`","True","`","save","runs\/CURRENT_DATETIME_HOSTNAME","in","current","directory",".","If","of","type","`","str","`","save","in","path",".","If","of","type","`","SummaryWriter","`","apply","provided","custom","summary","writer",".","Use","hierarchical","folder","structure","to","compare","between","runs","easily",".","e.g",".","pass","in","\u2018","runs\/exp1","\u2019",",","\u2018","runs\/exp2","\u2019",",","etc",".","for","each","new","experiment","to","compare","across","them",".",":","param","verbose",":","Show","progress","bars","."]
code: def __init__(
      self,
      estimator: Union[
          "CLASSIFIER_LOSS_GRADIENTS_TYPE", "OBJECT_DETECTOR_TYPE"
      ],
      norm: Union[int, float, str] = np.inf,
      eps: Union[int, float, np.ndarray] = 0.3,
      eps_step: Union[int, float, np.ndarray] = 0.1,
      decay: Optional[float] = None,
      max_iter: int = 100,
      targeted: bool = False,
      num_random_init: int = 0,
      batch_size: int = 32,
      random_eps: bool = False,
      summary_writer: Union[str, bool, SummaryWriter] = False,
      verbose: bool = True,
  ) -> None:
      """
      Create a :class:`.ProjectedGradientDescentCommon` instance.
  
      :param estimator: A trained classifier.
      :param norm: The norm of the adversarial perturbation supporting "inf", np.inf, 1 or 2.
      :param eps: Maximum perturbation that the attacker can introduce.
      :param eps_step: Attack step size (input variation) at each iteration.
      :param random_eps: When True, epsilon is drawn randomly from truncated normal distribution. The literature
          suggests this for FGSM based training to generalize across different epsilons. eps_step is
          modified to preserve the ratio of eps / eps_step. The effectiveness of this method with PGD
          is untested (https://arxiv.org/pdf/1611.01236.pdf).
      :param decay: Decay factor for accumulating the velocity vector when using momentum.
      :param max_iter: The maximum number of iterations.
      :param targeted: Indicates whether the attack is targeted (True) or untargeted (False).
      :param num_random_init: Number of random initialisations within the epsilon ball. For num_random_init=0
          starting at the original input.
      :param batch_size: Size of the batch on which adversarial samples are generated.
      :param summary_writer: Activate summary writer for TensorBoard.
                             Default is `False` and deactivated summary writer.
                             If `True` save runs/CURRENT_DATETIME_HOSTNAME in current directory.
                             If of type `str` save in path.
                             If of type `SummaryWriter` apply provided custom summary writer.
                             Use hierarchical folder structure to compare between runs easily. e.g. pass in
                             ‘runs/exp1’, ‘runs/exp2’, etc. for each new experiment to compare across them.
      :param verbose: Show progress bars.
      """
      super().__init__(
          estimator=estimator,  # type: ignore
          norm=norm,
          eps=eps,
          eps_step=eps_step,
          targeted=targeted,
          num_random_init=num_random_init,
          batch_size=batch_size,
          minimal=False,
          summary_writer=summary_writer,
      )
      self.decay = decay
      self.max_iter = max_iter
      self.random_eps = random_eps
      self.verbose = verbose
      ProjectedGradientDescentCommon._check_params(self)
  
      lower: Union[int, float, np.ndarray]
      upper: Union[int, float, np.ndarray]
      var_mu: Union[int, float, np.ndarray]
      sigma: Union[int, float, np.ndarray]
  
      if self.random_eps:
          if isinstance(eps, (int, float)):
              lower, upper = 0, eps
              var_mu, sigma = 0, (eps / 2)
          else:
              lower, upper = np.zeros_like(eps), eps
              var_mu, sigma = np.zeros_like(eps), (eps / 2)
  
          self.norm_dist = truncnorm(
              (lower - var_mu) / sigma,
              (upper - var_mu) / sigma,
              loc=var_mu,
              scale=sigma,
          )
  
imports: from __future__ import absolute_import, division, print_function, unicode_literals
  import logging
  from typing import Optional, Union, TYPE_CHECKING
  import numpy
  from scipy.stats import truncnorm
  from tqdm.auto import trange
  from art.attacks.evasion.fast_gradient import FastGradientMethod
  from art.config import ART_NUMPY_DTYPE
  from art.estimators.classification.classifier import ClassifierMixin
  from art.estimators.estimator import BaseEstimator, LossGradientsMixin
  from art.utils import compute_success, get_labels_np_array, check_and_transform_label_format, compute_success_array
  from art.summary_writer import SummaryWriter
label_desc: Use image node_id 1 to create a new ProjectedGradientDescentCommon object from inherited base classes: FastGradientMethod with example: obj = ProjectedGradientDescentCommon(estimator, norm, eps, eps_step, decay, max_iter, targeted, num_random_init, batch_size, random_eps, summary_writer, verbose)