class_docstr: Natural-evolutionary strategy for gradient estimation.
  For every backward pass, this module makes 2 * nb_samples
  queries per instance.
  
  :param func: A blackbox function.
      - This function must accept, and output, torch tensors.
  :param nb_samples: Number of samples to use in the grad estimation.
  :param fd_eta: Step-size used for the finite-difference estimation.
class_docstr_tok: ["Natural-evolutionary","strategy","for","gradient","estimation",".","For","every","backward","pass",",","this","module","makes","2","*","nb_samples","queries","per","instance",".",":","param","func",":","A","blackbox","function",".","-","This","function","must","accept",",","and","output",",","torch","tensors",".",":","param","nb_samples",":","Number","of","samples","to","use","in","the","grad","estimation",".",":","param","fd_eta",":","Step-size","used","for","the","finite-difference","estimation","."]
code: def estimate_grad(self, x, prior=None):
      # x shape: [nbatch, ndim]
      ndim = np.prod(list(x.shape[1:]))
  
      # [nbatch, ndim, nsamples]
      exp_noise = x.new_full(tuple(x.shape) + (self.nb_samples,), 0)
      exp_noise.normal_()
      exp_noise /= ndim**0.5
  
      fxp = self.batch_query(x.unsqueeze(-1) + self.fd_eta * exp_noise)
  
      fxm = self.batch_query(x.unsqueeze(-1) - self.fd_eta * exp_noise)
  
      gx_s = (fxp - fxm) / (
          2.0 * self.fd_eta
      )  # [nbatch, noutput, nsamples]
  
      grad_est = (gx_s[:, :, None, :] * exp_noise[:, None, :, :]).sum(
          -1
      )
  
      return grad_est
  
file_path: advertorch/advertorch/attacks/blackbox/estimators.py
imports: import torch
  import numpy
label_desc: Use image node_id 2 for calling the NESWrapper obj's underlying member method code with example usage: obj.estimate_grad(x, prior) and returns: grad_est