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: Generate a single poison attack the model, using `x_val` and `y_val` as validation points.
  The attack begins at the point init_attack. The attack class will be the opposite of the model's
  classification for `init_attack`.
  
  :param x_attack: The initial attack point.
  :param y_attack: The initial attack label.
  :return: A tuple containing the final attack point and the poisoned model.
docstr_tok: ["Generate","a","single","poison","attack","the","model",",","using","`","x_val","`","and","`","y_val","`","as","validation","points",".","The","attack","begins","at","the","point","init_attack",".","The","attack","class","will","be","the","opposite","of","the","model's","classification","for","`","init_attack","`",".",":","param","x_attack",":","The","initial","attack","point",".",":","param","y_attack",":","The","initial","attack","label",".",":","return",":","A","tuple","containing","the","final","attack","point","and","the","poisoned","model","."]
code: def generate_attack_point(
      self, x_attack: np.ndarray, y_attack: np.ndarray
  ) -> np.ndarray:
      """
      Generate a single poison attack the model, using `x_val` and `y_val` as validation points.
      The attack begins at the point init_attack. The attack class will be the opposite of the model's
      classification for `init_attack`.
  
      :param x_attack: The initial attack point.
      :param y_attack: The initial attack label.
      :return: A tuple containing the final attack point and the poisoned model.
      """
      # pylint: disable=W0212
      from sklearn.preprocessing import normalize
  
      if self.y_train is None or self.x_train is None:
          raise ValueError(
              "`x_train` and `y_train` cannot be None for generating an attack point."
          )
  
      poisoned_model = self.estimator.model
      y_t = np.argmax(self.y_train, axis=1)
      poisoned_model.fit(self.x_train, y_t)
      y_a = np.argmax(y_attack)
      attack_point = np.expand_dims(x_attack, axis=0)
      var_g = poisoned_model.decision_function(self.x_val)
      k_values = np.where(-var_g > 0)
      new_p = np.sum(var_g[k_values])
      old_p = np.copy(new_p)
      i = 0
  
      while new_p - old_p < self.eps and i < self.max_iter:
          old_p = new_p
          poisoned_input = np.vstack([self.x_train, attack_point])
          poisoned_labels = np.append(y_t, y_a)
          poisoned_model.fit(poisoned_input, poisoned_labels)
  
          unit_grad = normalize(self.attack_gradient(attack_point))
          attack_point += self.step * unit_grad
          lower, upper = self.estimator.clip_values
          new_attack = np.clip(attack_point, lower, upper)
          new_g = poisoned_model.decision_function(self.x_val)
          k_values = np.where(-new_g > 0)
          new_p = np.sum(new_g[k_values])
          i += 1
          attack_point = new_attack
  
      poisoned_input = np.vstack([self.x_train, attack_point])
      poisoned_labels = np.append(y_t, y_a)
      poisoned_model.fit(poisoned_input, poisoned_labels)
      return attack_point
  
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 3 for calling the PoisoningAttackSVM obj's underlying member method code with example usage: obj.generate_attack_point(x_attack, y_attack) and returns: attack_point