docstr: Fits the detector
  
  Parameters
  ----------
  x_ref
      The Dataset tensor.
docstr_tok: ["Fits","the","detector","Parameters","--","--","--","--","--","x_ref","The","Dataset","tensor","."]
code: def fit(self, x_ref: torch.Tensor):
      """Fits the detector
  
      Parameters
      ----------
      x_ref
          The Dataset tensor.
      """
      # compute the distance matrix
      K = self._compute_K(x_ref, x_ref)
      # set diagonal to max distance to prevent torch.topk from returning the instance itself
      K += torch.eye(len(K), device=self.device) * torch.max(K)
  
      # compute k nearest neighbors for maximum k in self.ks
      max_k = torch.max(self.ks)
      bot_k_items = torch.topk(K, int(max_k), dim=1, largest=False)
      bot_k_inds, bot_k_dists = bot_k_items.indices, bot_k_items.values
  
      # store the k-distances for each instance for each k.
      self.knn_dists_ref = bot_k_dists[:, self.ks - 1]
  
      # To compute the reachabilities we get the k-distances of each object in the instances
      # k nearest neighbors. Then we take the maximum of their k-distances and the distance
      # to the instance.
      lower_bounds = self.knn_dists_ref[bot_k_inds]
      reachabilities = torch.max(bot_k_dists[:, :, None], lower_bounds)
  
      # Compute the average reachability for each instance. We use a mask to manage each k in
      # self.ks separately.
      mask = self._make_mask(reachabilities)
      avg_reachabilities = (reachabilities * mask[None, :, :]).sum(1)
  
      # Compute the inverse average reachability for each instance.
      self.ref_inv_avg_reachabilities = 1 / avg_reachabilities
  
      self.x_ref = x_ref
      self._set_fitted()
  
file_path: alibi-detect/alibi_detect/od/pytorch/lof.py
imports: from typing import Optional, Union, List, Tuple
  import numpy
  import torch
  from alibi_detect.od.pytorch.ensemble import Ensembler
  from alibi_detect.od.pytorch.base import TorchOutlierDetector
  from alibi_detect.utils._types import TorchDeviceType
label_desc: Use image node_id 6 for calling the LOFTorch obj's underlying member method code with example usage: obj.fit(x_ref) without return types