alibi_detect.od.pytorch.lof
LOFTorch
LOFTorchInherits from: TorchOutlierDetector, Module, FitMixinTorch, ABC
Constructor
LOFTorch(self, k: Union[numpy.ndarray, List, Tuple, int], kernel: Optional[torch.nn.modules.module.Module] = None, ensembler: Optional[alibi_detect.od.pytorch.ensemble.Ensembler] = None, device: Union[typing_extensions.Literal['cuda', 'gpu', 'cpu'], ForwardRef('torch.device'), NoneType] = None)k
Union[numpy.ndarray, List[Any], Tuple, int]
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
Optional[torch.nn.modules.module.Module]
None
If a kernel is specified then instead of using torch.cdist the kernel defines the k nearest neighbor distance.
ensembler
Optional[alibi_detect.od.pytorch.ensemble.Ensembler]
None
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
Union[Literal[cuda, gpu, cpu], torch.device, None]
None
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.
Methods
fit
fitfit(x_ref: torch.Tensor)Fits the detector
x_ref
torch.Tensor
The Dataset tensor.
forward
forwardforward(x: torch.Tensor) -> torch.TensorDetect if x is an outlier.
x
torch.Tensor
torch.Tensor with leading batch dimension.
Returns
Type:
torch.Tensor
score
scorescore(x: torch.Tensor) -> torch.TensorComputes the score of x
x
torch.Tensor
The tensor of instances. First dimension corresponds to batch.
Returns
Type:
torch.Tensor
Last updated
Was this helpful?

