class_docstr: Given a latent variable generating a given adversarial sample, either inferred by an inverse GAN or randomly
  generated, the InverseGAN optimizes that latent variable to project a sample as close as possible to the adversarial
  sample without the adversarial noise.
class_docstr_tok: ["Given","a","latent","variable","generating","a","given","adversarial","sample",",","either","inferred","by","an","inverse","GAN","or","randomly","generated",",","the","InverseGAN","optimizes","that","latent","variable","to","project","a","sample","as","close","as","possible","to","the","adversarial","sample","without","the","adversarial","noise","."]
docstr: Compute the gradient of the loss function w.r.t. a `z_encoding` input within a GAN against a
  corresponding adversarial sample.
  
  :param x: The encoding z.
  :param grad: Target values of shape `(nb_samples, nb_classes)`.
  :return: Array of gradients of the same shape as `z_encoding`.
docstr_tok: ["Compute","the","gradient","of","the","loss","function","w.r.t",".","a","`","z_encoding","`","input","within","a","GAN","against","a","corresponding","adversarial","sample",".",":","param","x",":","The","encoding","z.",":","param","grad",":","Target","values","of","shape","`","(","nb_samples",",","nb_classes",")","`",".",":","return",":","Array","of","gradients","of","the","same","shape","as","`","z_encoding","`","."]
code: def estimate_gradient(
      self, x: np.ndarray, grad: np.ndarray
  ) -> np.ndarray:
      """
      Compute the gradient of the loss function w.r.t. a `z_encoding` input within a GAN against a
      corresponding adversarial sample.
  
      :param x: The encoding z.
      :param grad: Target values of shape `(nb_samples, nb_classes)`.
      :return: Array of gradients of the same shape as `z_encoding`.
      """
      logging.info("Calculating Gradients")
  
      gradient = self.sess.run(
          self._grad,
          feed_dict={self._image_adv: grad, self.gan.input_ph: x},
      )
      return gradient
  
file_path: adversarial-robustness-toolbox/art/defences/preprocessor/inverse_gan.py
imports: from __future__ import absolute_import, division, print_function, unicode_literals
  import logging
  from typing import Optional, Tuple, TYPE_CHECKING
  import numpy
  from scipy.optimize import minimize
  from art.defences.preprocessor.preprocessor import Preprocessor
label_desc: Use image node_id 4 for calling the InverseGAN obj's underlying member method code with example usage: obj.estimate_gradient(x, grad) and returns: gradient