docstr: Compute the principal components of the reference data.
  
  We compute the principal components of the reference data using the kernel matrix and then
  return the largest `n_components` eigenvectors. These are then normalized to have length
  equal to `1/eigenvalue`. Note that this differs from the linear case where we remove the
  largest eigenvectors.
  
  Parameters
  ----------
  x
      The reference data.
  
  Returns
  -------
  The principal components of the reference data.
  
  Raises
  ------
  ValueError
      If `n_components` is greater than or equal to the number of reference samples.
docstr_tok: ["Compute","the","principal","components","of","the","reference","data",".","We","compute","the","principal","components","of","the","reference","data","using","the","kernel","matrix","and","then","return","the","largest","`","n_components","`","eigenvectors",".","These","are","then","normalized","to","have","length","equal","to","`","1\/eigenvalue","`",".","Note","that","this","differs","from","the","linear","case","where","we","remove","the","largest","eigenvectors",".","Parameters","--","--","--","--","--","x","The","reference","data",".","Returns","--","--","--","-","The","principal","components","of","the","reference","data",".","Raises","--","--","--","ValueError","If","`","n_components","`","is","greater","than","or","equal","to","the","number","of","reference","samples","."]
code: def _fit(self, x: torch.Tensor) -> torch.Tensor:
      """Compute the principal components of the reference data.
  
      We compute the principal components of the reference data using the kernel matrix and then
      return the largest `n_components` eigenvectors. These are then normalized to have length
      equal to `1/eigenvalue`. Note that this differs from the linear case where we remove the
      largest eigenvectors.
  
      Parameters
      ----------
      x
          The reference data.
  
      Returns
      -------
      The principal components of the reference data.
  
      Raises
      ------
      ValueError
          If `n_components` is greater than or equal to the number of reference samples.
      """
      if self.n_components >= x.shape[0]:
          raise ValueError(
              "n_components must be less than the number of reference instances."
          )
  
      self.x_ref = x
      K = self.compute_kernel_mat(x)
      D, V = torch.linalg.eigh(K)
      pcs = V / torch.sqrt(D)[None, :]
      return pcs[:, -self.n_components :]
  
imports: from typing import Optional, Callable
  import torch
  from alibi_detect.od.pytorch.base import TorchOutlierDetector
  from alibi_detect.utils._types import TorchDeviceType
label_desc: Use image node_id 2 for calling the KernelPCATorch obj's underlying member method code with example usage: obj._fit(x) and returns: pcs