class_docstr: Wrapper class for GPy Gaussian Process classification models.
class_docstr_tok: ["Wrapper","class","for","GPy","Gaussian","Process","classification","models","."]
docstr: Compute the gradient of the loss function w.r.t. `x`.
  
  :param x: Sample input with shape as expected by the model.
  :param y: Target values (class labels) one-hot-encoded of shape `(nb_samples, nb_classes)` or indices of shape
            `(nb_samples,)`.
  :return: Array of gradients of the same shape as `x`.
docstr_tok: ["Compute","the","gradient","of","the","loss","function","w.r.t",".","`","x","`",".",":","param","x",":","Sample","input","with","shape","as","expected","by","the","model",".",":","param","y",":","Target","values","(","class","labels",")","one-hot-encoded","of","shape","`","(","nb_samples",",","nb_classes",")","`","or","indices","of","shape","`","(","nb_samples",",",")","`",".",":","return",":","Array","of","gradients","of","the","same","shape","as","`","x","`","."]
code: def loss_gradient(
      self, x: np.ndarray, y: np.ndarray, **kwargs
  ) -> np.ndarray:
      """
      Compute the gradient of the loss function w.r.t. `x`.
  
      :param x: Sample input with shape as expected by the model.
      :param y: Target values (class labels) one-hot-encoded of shape `(nb_samples, nb_classes)` or indices of shape
                `(nb_samples,)`.
      :return: Array of gradients of the same shape as `x`.
      """
      # Apply preprocessing
      x_preprocessed, _ = self._apply_preprocessing(x, y, fit=False)
  
      eps = 0.00001
      grads = np.zeros(np.shape(x))
      for i in range(np.shape(x)[0]):
          # 1.0 - to mimic loss, [0,np.argmax] to get right class
          ind = (
              1.0
              - self.predict(x_preprocessed[i].reshape(1, -1))[
                  0, np.argmax(y[i])
              ]
          )
          sur = (
              1.0
              - self.predict(
                  np.repeat(
                      x_preprocessed[i].reshape(1, -1),
                      np.shape(x_preprocessed)[1],
                      0,
                  )
                  + eps * np.eye(np.shape(x_preprocessed)[1])
              )[:, np.argmax(y[i])]
          )
          grads[i] = ((sur - ind) * eps).reshape(1, -1)
  
      grads = self._apply_preprocessing_gradient(x, grads)
  
      return grads
  
file_path: adversarial-robustness-toolbox/art/estimators/classification/GPy.py
imports: from __future__ import absolute_import, division, print_function, unicode_literals
  import logging
  import os
  from typing import List, Optional, Union, Tuple, TYPE_CHECKING
  import numpy
  from art.estimators.classification.classifier import ClassifierClassLossGradients
  from art import config
label_desc: Use image node_id 4 for calling the GPyGaussianProcessClassifier obj's underlying member method code with example usage: obj.loss_gradient(x, y) and returns: grads