docstr: Computes the score of `x`
  
  Parameters
  ----------
  x
      The tensor of instances. First dimension corresponds to batch.
  
  Returns
  -------
  Tensor of scores for each element in `x`.
  
  Raises
  ------
  NotFittedError
      If called before detector has been fit.
docstr_tok: ["Computes","the","score","of","`","x","`","Parameters","--","--","--","--","--","x","The","tensor","of","instances",".","First","dimension","corresponds","to","batch",".","Returns","--","--","--","-","Tensor","of","scores","for","each","element","in","`","x","`",".","Raises","--","--","--","NotFittedError","If","called","before","detector","has","been","fit","."]
code: def score(self, x: torch.Tensor) -> torch.Tensor:
      """Computes the score of `x`
  
      Parameters
      ----------
      x
          The tensor of instances. First dimension corresponds to batch.
  
      Returns
      -------
      Tensor of scores for each element in `x`.
  
      Raises
      ------
      NotFittedError
          If called before detector has been fit.
      """
      self.check_fitted()
  
      # compute the distance matrix between x and x_ref
      K = self._compute_K(x, self.x_ref)
  
      # 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
  
      # 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 LOF score for each instance. Note we don't take 1/avg_reachabilities as
      # avg_reachabilities is the denominator in the LOF formula.
      factors = (
          self.ref_inv_avg_reachabilities[bot_k_inds] * mask[None, :, :]
      ).sum(1)
      lofs = avg_reachabilities * factors
      return lofs if self.ensemble else lofs[:, 0]
  
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 5 for calling the LOFTorch obj's underlying member method code with example usage: obj.score(x) and returns: unknown