class_docstr: This class represent a Feature Adversaries evasion attack.
  
  | Paper link: https://arxiv.org/abs/1511.05122
docstr: Generate adversarial samples and return them in an array.
  
  :param x: Source samples.
  :param y: Guide samples.
  :param kwargs: The kwargs are used as `options` for the minimisation with `scipy.optimize.minimize` using
                 `method="L-BFGS-B"`. Valid options are based on the output of
                 `scipy.optimize.show_options(solver='minimize', method='L-BFGS-B')`:
                 Minimize a scalar function of one or more variables using the L-BFGS-B algorithm.
  
                 disp : None or int
                     If `disp is None` (the default), then the supplied version of `iprint`
                     is used. If `disp is not None`, then it overrides the supplied version
                     of `iprint` with the behaviour you outlined.
                 maxcor : int
                     The maximum number of variable metric corrections used to
                     define the limited memory matrix. (The limited memory BFGS
                     method does not store the full hessian but uses this many terms
                     in an approximation to it.)
                 ftol : float
                     The iteration stops when ``(f^k -
                     f^{k+1})/max{|f^k|,|f^{k+1}|,1} <= ftol``.
                 gtol : float
                     The iteration will stop when ``max{|proj g_i | i = 1, ..., n}
                     <= gtol`` where ``pg_i`` is the i-th component of the
                     projected gradient.
                 eps : float
                     Step size used for numerical approximation of the Jacobian.
                 maxfun : int
                     Maximum number of function evaluations.
                 maxiter : int
                     Maximum number of iterations.
                 iprint : int, optional
                     Controls the frequency of output. ``iprint < 0`` means no output;
                     ``iprint = 0``    print only one line at the last iteration;
                     ``0 < iprint < 99`` print also f and ``|proj g|`` every iprint iterations;
                     ``iprint = 99``   print details of every iteration except n-vectors;
                     ``iprint = 100``  print also the changes of active set and final x;
                     ``iprint > 100``  print details of every iteration including x and g.
                 callback : callable, optional
                     Called after each iteration, as ``callback(xk)``, where ``xk`` is the
                     current parameter vector.
                 maxls : int, optional
                     Maximum number of line search steps (per iteration). Default is 20.
  
                 The option `ftol` is exposed via the `scipy.optimize.minimize` interface,
                 but calling `scipy.optimize.fmin_l_bfgs_b` directly exposes `factr`. The
                 relationship between the two is ``ftol = factr * numpy.finfo(float).eps``.
                 I.e., `factr` multiplies the default machine floating-point precision to
                 arrive at `ftol`.
  :return: Adversarial examples.
  :raises KeyError: The argument {} in kwargs is not allowed as option for `scipy.optimize.minimize` using
                    `method="L-BFGS-B".`
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: Source samples.
      :param y: Guide samples.
      :param kwargs: The kwargs are used as `options` for the minimisation with `scipy.optimize.minimize` using
                     `method="L-BFGS-B"`. Valid options are based on the output of
                     `scipy.optimize.show_options(solver='minimize', method='L-BFGS-B')`:
                     Minimize a scalar function of one or more variables using the L-BFGS-B algorithm.
  
                     disp : None or int
                         If `disp is None` (the default), then the supplied version of `iprint`
                         is used. If `disp is not None`, then it overrides the supplied version
                         of `iprint` with the behaviour you outlined.
                     maxcor : int
                         The maximum number of variable metric corrections used to
                         define the limited memory matrix. (The limited memory BFGS
                         method does not store the full hessian but uses this many terms
                         in an approximation to it.)
                     ftol : float
                         The iteration stops when ``(f^k -
                         f^{k+1})/max{|f^k|,|f^{k+1}|,1} <= ftol``.
                     gtol : float
                         The iteration will stop when ``max{|proj g_i | i = 1, ..., n}
                         <= gtol`` where ``pg_i`` is the i-th component of the
                         projected gradient.
                     eps : float
                         Step size used for numerical approximation of the Jacobian.
                     maxfun : int
                         Maximum number of function evaluations.
                     maxiter : int
                         Maximum number of iterations.
                     iprint : int, optional
                         Controls the frequency of output. ``iprint < 0`` means no output;
                         ``iprint = 0``    print only one line at the last iteration;
                         ``0 < iprint < 99`` print also f and ``|proj g|`` every iprint iterations;
                         ``iprint = 99``   print details of every iteration except n-vectors;
                         ``iprint = 100``  print also the changes of active set and final x;
                         ``iprint > 100``  print details of every iteration including x and g.
                     callback : callable, optional
                         Called after each iteration, as ``callback(xk)``, where ``xk`` is the
                         current parameter vector.
                     maxls : int, optional
                         Maximum number of line search steps (per iteration). Default is 20.
  
                     The option `ftol` is exposed via the `scipy.optimize.minimize` interface,
                     but calling `scipy.optimize.fmin_l_bfgs_b` directly exposes `factr`. The
                     relationship between the two is ``ftol = factr * numpy.finfo(float).eps``.
                     I.e., `factr` multiplies the default machine floating-point precision to
                     arrive at `ftol`.
      :return: Adversarial examples.
      :raises KeyError: The argument {} in kwargs is not allowed as option for `scipy.optimize.minimize` using
                        `method="L-BFGS-B".`
      """
      from scipy.linalg import norm
      from scipy.optimize import Bounds, minimize
  
      if y is None:
          raise ValueError(
              "The value of guide `y` cannot be None. Please provide a `np.ndarray` of guide inputs."
          )
      if x.shape != y.shape:
          raise ValueError(
              "The shape of source `x` and guide `y` must be of same shape."
          )
      if x.shape[1:] != self.estimator.input_shape:  # pragma: no cover
          raise ValueError(
              "Source and guide inputs must match `input_shape` of estimator."
          )
  
      l_b = x.flatten() - self.delta
      l_b[
          l_b < self.estimator.clip_values[0]
      ] = self.estimator.clip_values[0]
  
      u_b = x.flatten() + self.delta
      u_b[
          u_b > self.estimator.clip_values[1]
      ] = self.estimator.clip_values[1]
  
      bound = Bounds(lb=l_b, ub=u_b, keep_feasible=False)
  
      guide_representation = self.estimator.get_activations(
          x=y.reshape(-1, *self.estimator.input_shape),  # type: ignore
          layer=self.layer,
          batch_size=self.batch_size,
      )
  
      def func(x_i):
          x_i = x_i.astype(x.dtype)
          source_representation = self.estimator.get_activations(
              x=x_i.reshape(-1, *self.estimator.input_shape),
              layer=self.layer,
              batch_size=self.batch_size,
          )
  
          n = (
              norm(
                  source_representation.flatten()
                  - guide_representation.flatten(),
                  ord=2,
              )
              ** 2
          )
  
          return n
  
      x_0 = x.copy().flatten()
  
      options = {"eps": 1e-3, "ftol": 1e-3}
      options_allowed_keys = [
          "disp",
          "maxcor",
          "ftol",
          "gtol",
          "eps",
          "maxfun",
          "maxiter",
          "iprint",
          "callback",
          "maxls",
      ]
  
      for key in kwargs:
          if key not in options_allowed_keys:
              raise KeyError(
                  f"The argument `{key}` in kwargs is not allowed as option for `scipy.optimize.minimize` using "
                  '`method="L-BFGS-B".`'
              )
      options.update(kwargs)
  
      res = minimize(
          func, x_0, method="L-BFGS-B", bounds=bound, options=options
      )
      x_adv = res.x
      logger.info(res)
  
      return x_adv.reshape(-1, *self.estimator.input_shape).astype(
          x.dtype
      )
  
file_path: adversarial-robustness-toolbox/art/attacks/evasion/feature_adversaries/feature_adversaries_numpy.py
imports: import logging
  from typing import TYPE_CHECKING, Optional
  import numpy
  from art.attacks.attack import EvasionAttack
  from art.estimators.estimator import BaseEstimator, NeuralNetworkMixin
label_desc: Use image node_id 2 for calling the FeatureAdversariesNumpy obj's underlying member method code with example usage: obj.generate(x, y) and returns: x_adv, n