alibi_detect.od.pytorch.pca

KernelPCATorch

Inherits from: PCATorch, TorchOutlierDetector, Module, FitMixinTorch, ABC

Constructor

KernelPCATorch(self, n_components: int, kernel: Optional[Callable], device: Union[typing_extensions.Literal['cuda', 'gpu', 'cpu'], ForwardRef('torch.device'), NoneType] = None)
Name
Type
Default
Description

n_components

int

The number of dimensions in the principal subspace.

kernel

Optional[Callable]

Kernel function to use for outlier detection.

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

compute_kernel_mat

compute_kernel_mat(x: torch.Tensor) -> torch.Tensor

Computes the centered kernel matrix.

Name
Type
Default
Description

x

torch.Tensor

The reference data.

Returns

  • Type: torch.Tensor

LinearPCATorch

Inherits from: PCATorch, TorchOutlierDetector, Module, FitMixinTorch, ABC

Constructor

LinearPCATorch(self, n_components: int, device: Union[typing_extensions.Literal['cuda', 'gpu', 'cpu'], ForwardRef('torch.device'), NoneType] = None)
Name
Type
Default
Description

n_components

int

The number of dimensions in the principal subspace.

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.

PCATorch

Inherits from: TorchOutlierDetector, Module, FitMixinTorch, ABC

Constructor

PCATorch(self, n_components: int, device: Union[typing_extensions.Literal['cuda', 'gpu', 'cpu'], ForwardRef('torch.device'), NoneType] = None)
Name
Type
Default
Description

n_components

int

The number of dimensions in the principal subspace. For linear PCA should have 1 <= n_components < dim(data). For kernel pca should have 1 <= n_components < len(data).

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

fit(x_ref: torch.Tensor) -> None

Fits the PCA detector.

Name
Type
Default
Description

x_ref

torch.Tensor

The Dataset tensor.

Returns

  • Type: None

forward

forward(x: torch.Tensor) -> torch.Tensor

Detect if x is an outlier.

Name
Type
Default
Description

x

torch.Tensor

torch.Tensor with leading batch dimension.

Returns

  • Type: torch.Tensor

score

score(x: torch.Tensor) -> torch.Tensor

Computes the score of x

Name
Type
Default
Description

x

torch.Tensor

The tensor of instances. First dimension corresponds to batch.

Returns

  • Type: torch.Tensor

Last updated

Was this helpful?