class_docstr: Implements ``Wasserstein Adversarial Examples via Projected Sinkhorn Iterations`` as evasion attack.
  
  | Paper link: https://arxiv.org/abs/1902.07906
class_docstr_tok: ["Implements","``","Wasserstein","Adversarial","Examples","via","Projected","Sinkhorn","Iterations","``","as","evasion","attack",".","|","Paper","link",":","https",":","\/\/arxiv.org\/abs\/1902.07906"]
docstr: Compute and apply perturbations.
  
  :param x: Current adversarial examples.
  :param y: Target values (class labels) one-hot-encoded of shape `(nb_samples, nb_classes)` or indices of shape
            (nb_samples,). Only provide this parameter if you'd like to use true labels when crafting adversarial
            samples. Otherwise, model predictions are used as labels to avoid the "label leaking" effect
            (explained in this paper: https://arxiv.org/abs/1611.01236). Default is `None`.
  :param cost_matrix: A non-negative cost matrix.
  :return: Adversarial examples.
docstr_tok: ["Compute","and","apply","perturbations",".",":","param","x",":","Current","adversarial","examples",".",":","param","y",":","Target","values","(","class","labels",")","one-hot-encoded","of","shape","`","(","nb_samples",",","nb_classes",")","`","or","indices","of","shape","(","nb_samples",",",")",".","Only","provide","this","parameter","if","you","'d","like","to","use","true","labels","when","crafting","adversarial","samples",".","Otherwise",",","model","predictions","are","used","as","labels","to","avoid","the","``","label","leaking","''","effect","(","explained","in","this","paper",":","https",":","\/\/arxiv.org\/abs\/1611.01236",")",".","Default","is","`","None","`",".",":","param","cost_matrix",":","A","non-negative","cost","matrix",".",":","return",":","Adversarial","examples","."]
code: def _compute_apply_perturbation(
      self, x: np.ndarray, y: np.ndarray, cost_matrix: np.ndarray
  ) -> np.ndarray:
      """
      Compute and apply perturbations.
  
      :param x: Current adversarial examples.
      :param y: Target values (class labels) one-hot-encoded of shape `(nb_samples, nb_classes)` or indices of shape
                (nb_samples,). Only provide this parameter if you'd like to use true labels when crafting adversarial
                samples. Otherwise, model predictions are used as labels to avoid the "label leaking" effect
                (explained in this paper: https://arxiv.org/abs/1611.01236). Default is `None`.
      :param cost_matrix: A non-negative cost matrix.
      :return: Adversarial examples.
      """
      # Pick a small scalar to avoid division by 0
      tol = 10e-8
  
      # Get gradient wrt loss; invert it if attack is targeted
      grad = self.estimator.loss_gradient(x, y) * (
          1 - 2 * int(self.targeted)
      )
  
      # Apply norm bound
      if self.norm == "inf":
          grad = np.sign(grad)
          x_adv = x + self.eps_step * grad
  
      elif self.norm == "1":
          ind = tuple(range(1, len(x.shape)))
          grad = grad / (
              np.sum(np.abs(grad), axis=ind, keepdims=True) + tol
          )
          x_adv = x + self.eps_step * grad
  
      elif self.norm == "2":
          ind = tuple(range(1, len(x.shape)))
          grad = grad / (
              np.sqrt(np.sum(np.square(grad), axis=ind, keepdims=True))
              + tol
          )
          x_adv = x + self.eps_step * grad
  
      elif self.norm == "wasserstein":
          x_adv = self._conjugate_sinkhorn(x, grad, cost_matrix)
  
      else:
          raise NotImplementedError(
              "Values of `norm` different from `1`, `2`, `inf` and `wasserstein` are currently not supported."
          )
  
      return x_adv
  
imports: from __future__ import absolute_import, division, print_function, unicode_literals
  import logging
  from typing import Optional, TYPE_CHECKING
  import numpy
  from scipy.special import lambertw
  from tqdm.auto import trange
  from art.config import ART_NUMPY_DTYPE
  from art.estimators.estimator import BaseEstimator, LossGradientsMixin
  from art.estimators.classification.classifier import ClassifierMixin
  from art.attacks.attack import EvasionAttack
  from art.utils import get_labels_np_array, check_and_transform_label_format
label_desc: Use image node_id 5 for calling the Wasserstein obj's underlying member method code with example usage: obj._compute_apply_perturbation(x, y, cost_matrix) and returns: x_adv