class_docstr: Close implementation of poisoning attack on Support Vector Machines (SVM) by Biggio et al.
  
  | Paper link: https://arxiv.org/pdf/1206.6389.pdf
class_docstr_tok: ["Close","implementation","of","poisoning","attack","on","Support","Vector","Machines","(","SVM",")","by","Biggio","et","al",".","|","Paper","link",":","https",":","\/\/arxiv.org\/pdf\/1206.6389.pdf"]
docstr: Iteratively finds optimal attack points starting at values at `x`.
  
  :param x: An array with the points that initialize attack points.
  :param y: The target labels for the attack.
  :return: A tuple holding the `(poisoning_examples, poisoning_labels)`.
docstr_tok: ["Iteratively","finds","optimal","attack","points","starting","at","values","at","`","x","`",".",":","param","x",":","An","array","with","the","points","that","initialize","attack","points",".",":","param","y",":","The","target","labels","for","the","attack",".",":","return",":","A","tuple","holding","the","`","(","poisoning_examples",",","poisoning_labels",")","`","."]
code: def poison(
      self, x: np.ndarray, y: Optional[np.ndarray] = None, **kwargs
  ) -> Tuple[np.ndarray, np.ndarray]:
      """
      Iteratively finds optimal attack points starting at values at `x`.
  
      :param x: An array with the points that initialize attack points.
      :param y: The target labels for the attack.
      :return: A tuple holding the `(poisoning_examples, poisoning_labels)`.
      """
      if y is None:  # pragma: no cover
          raise ValueError(
              "Target labels `y` need to be provided for a targeted attack."
          )
  
      y_attack = np.copy(y)
  
      num_poison = len(x)
      if num_poison == 0:  # pragma: no cover
          raise ValueError("Must input at least one poison point")
  
      num_features = len(x[0])
      train_data = np.copy(self.x_train)
      train_labels = np.copy(self.y_train)
      all_poison = []
  
      for attack_point, attack_label in tqdm(
          zip(x, y_attack),
          desc="SVM poisoning",
          disable=not self.verbose,
      ):
          poison = self.generate_attack_point(
              attack_point, attack_label
          )
          all_poison.append(poison)
          train_data = np.vstack([train_data, poison])
          train_labels = np.vstack([train_labels, attack_label])
  
      x_adv = np.array(all_poison).reshape((num_poison, num_features))
      targeted = y is not None
  
      logger.info(
          "Success rate of poisoning attack SVM attack: %.2f%%",
          100
          * compute_success(
              self.estimator, x, y, x_adv, targeted=targeted
          ),
      )
  
      return x_adv, y_attack
  
file_path: adversarial-robustness-toolbox/art/attacks/poisoning/poisoning_attack_svm.py
imports: from __future__ import absolute_import, division, print_function, unicode_literals
  import logging
  from typing import Optional, Tuple
  import numpy
  from tqdm.auto import tqdm
  from art.attacks.attack import PoisoningAttackWhiteBox
  from art.estimators.classification.scikitlearn import ScikitlearnSVC
  from art.utils import compute_success
label_desc: Use image node_id 2 for calling the PoisoningAttackSVM obj's underlying member method code with example usage: obj.poison(x, y) and returns: x_adv,  y_attack