alibi_detect.od.pytorch.mahalanobis module

class alibi_detect.od.pytorch.mahalanobis.MahalanobisTorch(min_eigenvalue=1e-06, device=None)[source]

Bases: TorchOutlierDetector

__init__(min_eigenvalue=1e-06, device=None)[source]

PyTorch backend for Mahalanobis detector.

Parameters:
  • min_eigenvalue (float) – Eigenvectors with eigenvalues below this value will be discarded.

  • device (Union[Literal[‘cuda’, ‘gpu’, ‘cpu’], device, 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.

ensemble = False
fit(x_ref)[source]

Fits the detector

Parameters:

x_ref (Tensor) – The Dataset tensor.

forward(x)[source]

Detect if x is an outlier.

Parameters:

x (Tensor) – torch.Tensor with leading batch dimension.

Return type:

Tensor

Returns:

torch.Tensor of bool values with leading batch dimension.

Raises:

ThresholdNotInferredException – If called before detector has had infer_threshold method called.

score(x)[source]

Computes the score of x

Parameters:

x (Tensor) – The tensor of instances. First dimension corresponds to batch.

Return type:

Tensor

Returns:

Tensor of scores for each element in x.

Raises:

NotFitException – If called before detector has been fit.