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 a batch of adversarial samples and return them in an array.
  
  :param x: An array with the original inputs.
  :param targets: Target values (class labels) one-hot-encoded of shape `(nb_samples, nb_classes)`.
  :param cost_matrix: A non-negative cost matrix.
  :return: Adversarial examples.
docstr_tok: ["Generate","a","batch","of","adversarial","samples","and","return","them","in","an","array",".",":","param","x",":","An","array","with","the","original","inputs",".",":","param","targets",":","Target","values","(","class","labels",")","one-hot-encoded","of","shape","`","(","nb_samples",",","nb_classes",")","`",".",":","param","cost_matrix",":","A","non-negative","cost","matrix",".",":","return",":","Adversarial","examples","."]
code: def _generate_batch(
      self, x: np.ndarray, targets: np.ndarray, cost_matrix: np.ndarray
  ) -> np.ndarray:
      """
      Generate a batch of adversarial samples and return them in an array.
  
      :param x: An array with the original inputs.
      :param targets: Target values (class labels) one-hot-encoded of shape `(nb_samples, nb_classes)`.
      :param cost_matrix: A non-negative cost matrix.
      :return: Adversarial examples.
      """
      adv_x = x.copy().astype(ART_NUMPY_DTYPE)
      adv_x_best = x.copy().astype(ART_NUMPY_DTYPE)
  
      if self.targeted:
          err = np.argmax(
              self.estimator.predict(adv_x, batch_size=x.shape[0]),
              axis=1,
          ) == np.argmax(targets, axis=1)
      else:
          err = np.argmax(
              self.estimator.predict(adv_x, batch_size=x.shape[0]),
              axis=1,
          ) != np.argmax(targets, axis=1)
  
      err_best = err
      eps_ = np.ones(x.shape[0]) * self.eps
  
      for i in range(self.max_iter):
          adv_x = self._compute(
              adv_x, x, targets, cost_matrix, eps_, err
          )
  
          if self.targeted:
              err = np.argmax(
                  self.estimator.predict(adv_x, batch_size=x.shape[0]),
                  axis=1,
              ) == np.argmax(targets, axis=1)
  
          else:
              err = np.argmax(
                  self.estimator.predict(adv_x, batch_size=x.shape[0]),
                  axis=1,
              ) != np.argmax(targets, axis=1)
  
          if np.mean(err) > np.mean(err_best):
              err_best = err
              adv_x_best = adv_x.copy()
  
          if np.mean(err) == 1:
              break
  
          if (i + 1) % self.eps_iter == 0:
              eps_[~err] *= self.eps_factor
  
      return adv_x_best
  
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 3 for calling the Wasserstein obj's underlying member method code with example usage: obj._generate_batch(x, targets, cost_matrix) and returns: adv_x_best