class_docstr: Implementation of the attack from Uyeong Jang et al. (2017).
  
  | Paper link: http://doi.acm.org/10.1145/3134600.3134635
class_docstr_tok: ["Implementation","of","the","attack","from","Uyeong","Jang","et","al",".","(","2017",")",".","|","Paper","link",":","http",":","\/\/doi.acm.org\/10.1145\/3134600.3134635"]
docstr: Function to compute the perturbation at each step.
  
  :param theta: Theta value at the current step.
  :param grads: Gradient values at the attacked class.
  :param norm_grad: Norm of gradient values at the attacked class.
  :return: Computed perturbation.
docstr_tok: ["Function","to","compute","the","perturbation","at","each","step",".",":","param","theta",":","Theta","value","at","the","current","step",".",":","param","grads",":","Gradient","values","at","the","attacked","class",".",":","param","norm_grad",":","Norm","of","gradient","values","at","the","attacked","class",".",":","return",":","Computed","perturbation","."]
code: def _compute_pert(
      theta: np.ndarray, grads: np.ndarray, norm_grad: np.ndarray
  ) -> np.ndarray:
      """
      Function to compute the perturbation at each step.
  
      :param theta: Theta value at the current step.
      :param grads: Gradient values at the attacked class.
      :param norm_grad: Norm of gradient values at the attacked class.
      :return: Computed perturbation.
      """
      # Pick a small scalar to avoid division by 0
      tol = 10e-8
  
      nom = (
          -theta.reshape((-1,) + (1,) * (len(grads.shape) - 1)) * grads
      )
      denom = norm_grad**2
      denom[denom < tol] = tol
      result = nom / denom.reshape(
          (-1,) + (1,) * (len(grads.shape) - 1)
      )
  
      return result
  
file_path: adversarial-robustness-toolbox/art/attacks/evasion/newtonfool.py
imports: from __future__ import absolute_import, division, print_function, unicode_literals
  import logging
  from typing import Optional, TYPE_CHECKING
  import numpy
  from tqdm.auto import 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 ClassGradientsMixin
  from art.utils import to_categorical
label_desc: Use image node_id 4 for calling the NewtonFool obj's underlying member method code with example usage: obj._compute_pert(theta, grads, norm_grad) and returns: result