docstr: PyTorch backend for LOF detector.
  
  Parameters
  ----------
  k
      Number of nearest neighbors used to compute the local outlier factor. `k` can be a single
      value or an array of integers. If `k` is a single value the score method uses the
      distance/kernel similarity to the `k`-th nearest neighbor. If `k` is a list then it uses
      the distance/kernel similarity to each of the specified `k` neighbors.
  kernel
      If a kernel is specified then instead of using `torch.cdist` the kernel defines the `k` nearest
      neighbor distance.
  ensembler
      If `k` is an array of integers then the ensembler must not be ``None``. Should be an instance
      of :py:obj:`alibi_detect.od.pytorch.ensemble.ensembler`. Responsible for combining
      multiple scores into a single score.
  device
      Device type used. The default tries to use the GPU and falls back on CPU if needed.
      Can be specified by passing either ``'cuda'``, ``'gpu'``, ``'cpu'`` or an instance of
      ``torch.device``.
docstr_tok: ["PyTorch","backend","for","LOF","detector",".","Parameters","--","--","--","--","--","k","Number","of","nearest","neighbors","used","to","compute","the","local","outlier","factor",".","`","k","`","can","be","a","single","value","or","an","array","of","integers",".","If","`","k","`","is","a","single","value","the","score","method","uses","the","distance\/kernel","similarity","to","the","`","k","`","-th","nearest","neighbor",".","If","`","k","`","is","a","list","then","it","uses","the","distance\/kernel","similarity","to","each","of","the","specified","`","k","`","neighbors",".","kernel","If","a","kernel","is","specified","then","instead","of","using","`","torch.cdist","`","the","kernel","defines","the","`","k","`","nearest","neighbor","distance",".","ensembler","If","`","k","`","is","an","array","of","integers","then","the","ensembler","must","not","be","``","None","``",".","Should","be","an","instance","of",":","py",":","obj",":","`","alibi_detect.od.pytorch.ensemble.ensembler","`",".","Responsible","for","combining","multiple","scores","into","a","single","score",".","device","Device","type","used",".","The","default","tries","to","use","the","GPU","and","falls","back","on","CPU","if","needed",".","Can","be","specified","by","passing","either","``","'cuda","'","``",",","``","'gpu","'","``",",","``","'cpu","'","``","or","an","instance","of","``","torch.device","``","."]
code: def __init__(
      self,
      k: Union[np.ndarray, List, Tuple, int],
      kernel: Optional[torch.nn.Module] = None,
      ensembler: Optional[Ensembler] = None,
      device: TorchDeviceType = None,
  ):
      """PyTorch backend for LOF detector.
  
      Parameters
      ----------
      k
          Number of nearest neighbors used to compute the local outlier factor. `k` can be a single
          value or an array of integers. If `k` is a single value the score method uses the
          distance/kernel similarity to the `k`-th nearest neighbor. If `k` is a list then it uses
          the distance/kernel similarity to each of the specified `k` neighbors.
      kernel
          If a kernel is specified then instead of using `torch.cdist` the kernel defines the `k` nearest
          neighbor distance.
      ensembler
          If `k` is an array of integers then the ensembler must not be ``None``. Should be an instance
          of :py:obj:`alibi_detect.od.pytorch.ensemble.ensembler`. Responsible for combining
          multiple scores into a single score.
      device
          Device type used. The default tries to use the GPU and falls back on CPU if needed.
          Can be specified by passing either ``'cuda'``, ``'gpu'``, ``'cpu'`` or an instance of
          ``torch.device``.
      """
      TorchOutlierDetector.__init__(self, device=device)
      self.kernel = kernel
      self.ensemble = isinstance(k, (np.ndarray, list, tuple))
      self.ks = (
          torch.tensor(k)
          if self.ensemble
          else torch.tensor([k], device=self.device)
      )
      self.ensembler = ensembler
  
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 1 to create a new LOFTorch object from inherited base classes: TorchOutlierDetector with example: obj = LOFTorch(k, kernel, ensembler, device)