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: Generate adversarial samples and return them in an array.
  
  :param x: An array with the original inputs.
  :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.
  :type cost_matrix: `np.ndarray`
  :return: An array holding the adversarial examples.
docstr_tok: ["Generate","adversarial","samples","and","return","them","in","an","array",".",":","param","x",":","An","array","with","the","original","inputs",".",":","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",".",":","type","cost_matrix",":","`","np.ndarray","`",":","return",":","An","array","holding","the","adversarial","examples","."]
code: def generate(
      self, x: np.ndarray, y: Optional[np.ndarray] = None, **kwargs
  ) -> np.ndarray:
      """
      Generate adversarial samples and return them in an array.
  
      :param x: An array with the original inputs.
      :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.
      :type cost_matrix: `np.ndarray`
      :return: An array holding the adversarial examples.
      """
      if y is not None:
          y = check_and_transform_label_format(
              y, nb_classes=self.estimator.nb_classes
          )
      x_adv = x.copy().astype(ART_NUMPY_DTYPE)
  
      if y is None:
          # Throw error if attack is targeted, but no targets are provided
          if self.targeted:
              raise ValueError(
                  "Target labels `y` need to be provided for a targeted attack."
              )
  
          # Use model predictions as correct outputs
          targets = get_labels_np_array(
              self.estimator.predict(x, batch_size=self.batch_size)
          )
      else:
          targets = y
  
      if self.estimator.nb_classes == 2 and targets.shape[1] == 1:
          raise ValueError(
              "This attack has not yet been tested for binary classification with a single output classifier."
          )
  
      # Compute the cost matrix if needed
      cost_matrix = kwargs.get("cost_matrix")
      if cost_matrix is None:
          cost_matrix = self._compute_cost_matrix(
              self.p, self.kernel_size
          )
  
      # Compute perturbation with implicit batching
      nb_batches = int(np.ceil(x.shape[0] / float(self.batch_size)))
      for batch_id in trange(
          nb_batches, desc="Wasserstein", disable=not self.verbose
      ):
          logger.debug(
              "Processing batch %i out of %i", batch_id, nb_batches
          )
  
          batch_index_1, batch_index_2 = (
              batch_id * self.batch_size,
              (batch_id + 1) * self.batch_size,
          )
          batch = x_adv[batch_index_1:batch_index_2]
          batch_labels = targets[batch_index_1:batch_index_2]
  
          x_adv[batch_index_1:batch_index_2] = self._generate_batch(
              batch, batch_labels, cost_matrix
          )
  
      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 2 for calling the Wasserstein obj's underlying member method code with example usage: obj.generate(x, y) and returns: x_adv