class_docstr: Optimizer for gradient-free attacks in https://arxiv.org/abs/1802.05666.
  
  Gradients estimates are computed using Simultaneous Perturbation Stochastic Approximation (SPSA),
  combined with the ADAM update rule (https://arxiv.org/abs/1412.6980).
class_docstr_tok: ["Optimizer","for","gradient-free","attacks","in","https",":","\/\/arxiv.org\/abs\/1802.05666",".","Gradients","estimates","are","computed","using","Simultaneous","Perturbation","Stochastic","Approximation","(","SPSA",")",",","combined","with","the","ADAM","update","rule","(","https",":","\/\/arxiv.org\/abs\/1412.6980",")","."]
docstr: Given a gradient, make one optimization step.
  
  :param grads: list of tensors, same length as `x`, containing the corresponding gradients
  :param x: list of tensors to update
  :param optim_state: dict
  
  Returns:
    new_x: list of tensors, updated version of `x`
    new_optim_state: dict, updated version of `optim_state`
docstr_tok: ["Given","a","gradient",",","make","one","optimization","step",".",":","param","grads",":","list","of","tensors",",","same","length","as","`","x","`",",","containing","the","corresponding","gradients",":","param","x",":","list","of","tensors","to","update",":","param","optim_state",":","dict","Returns",":","new_x",":","list","of","tensors",",","updated","version","of","`","x","`","new_optim_state",":","dict",",","updated","version","of","`","optim_state","`"]
code: def _apply_gradients(self, grads, x, optim_state):
      """Given a gradient, make one optimization step.
  
      :param grads: list of tensors, same length as `x`, containing the corresponding gradients
      :param x: list of tensors to update
      :param optim_state: dict
  
      Returns:
        new_x: list of tensors, updated version of `x`
        new_optim_state: dict, updated version of `optim_state`
      """
  
      new_x = [None] * len(x)
      new_optim_state = {
          "t": optim_state["t"] + 1.0,
          "m": [None] * len(x),
          "u": [None] * len(x),
      }
      t = new_optim_state["t"]
      for i in range(len(x)):
          g = grads[i]
          m_old = optim_state["m"][i]
          u_old = optim_state["u"][i]
          new_optim_state["m"][i] = (
              self.beta_1 * m_old + (1.0 - self.beta_1) * g
          )
          new_optim_state["u"][i] = (
              self.beta_2 * u_old + (1.0 - self.beta_2) * g * g
          )
          m_hat = new_optim_state["m"][i] / (
              1.0 - tf.pow(self.beta_1, t)
          )
          u_hat = new_optim_state["u"][i] / (
              1.0 - tf.pow(self.beta_2, t)
          )
          new_x[i] = x[i] - self.lr * m_hat / (
              tf.sqrt(u_hat) + self.epsilon
          )
      return new_x, new_optim_state
  
file_path: cleverhans/cleverhans/tf2/attacks/spsa.py
imports: import tensorflow
label_desc: Use image node_id 4 for calling the SPSAAdam obj's underlying member method code with example usage: obj._apply_gradients(grads, x, optim_state) and returns: new_x,  new_optim_state