class_docstr: Base class for similarity explainers.
docstr: Fit the explainer. If ``self.precompute_grads == True`` then the gradients are precomputed and stored.
  
  Parameters
  ----------
  X_train
      Training data.
  Y_train
      Training labels.
  
  Returns
  -------
  self
      Returns self.
docstr_tok: ["Fit","the","explainer",".","If","``","self.precompute_grads","==","True","``","then","the","gradients","are","precomputed","and","stored",".","Parameters","--","--","--","--","--","X_train","Training","data",".","Y_train","Training","labels",".","Returns","--","--","--","-","self","Returns","self","."]
code: def fit(
      self, X_train: Union[np.ndarray, List[Any]], Y_train: np.ndarray
  ) -> "Explainer":
      """Fit the explainer. If ``self.precompute_grads == True`` then the gradients are precomputed and stored.
  
      Parameters
      ----------
      X_train
          Training data.
      Y_train
          Training labels.
  
      Returns
      -------
      self
          Returns self.
      """
      self.X_train = X_train
      self.Y_train = Y_train
      self.X_dims = (
          self.X_train.shape[1:]
          if isinstance(self.X_train, np.ndarray)
          else None
      )
      self.Y_dims = self.Y_train.shape[1:]
      self.grad_X_train = np.array([])
  
      # compute and store gradients
      if self.precompute_grads:
          grads = []
          X: Union[np.ndarray, List[Any]]
          for X, Y in tqdm(
              zip(self.X_train, self.Y_train), disable=not self.verbose
          ):
              grad_X_train = self._compute_grad(
                  self._format(X), Y[None]
              )
              grads.append(grad_X_train[None])
  
          self.grad_X_train = np.concatenate(grads, axis=0)
      return self
  
imports: from abc import ABC
  from typing import TYPE_CHECKING, Any, Callable, List, Optional, Union
  import numpy
  from alibi.api.interfaces import Explainer
  from alibi.explainers.similarity.backends import _select_backend
  from alibi.utils.frameworks import Framework, has_pytorch, has_tensorflow
  from alibi.utils.missing_optional_dependency import import_optional
  from tqdm import tqdm
  from typing_extensions import Literal
label_desc: Use image node_id 2 for calling the BaseSimilarityExplainer obj's underlying member method code with example usage: obj.fit(X_train, Y_train) and returns: self