alibi_detect.od.pytorch.pca
KernelPCATorch
KernelPCATorchInherits 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)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_matcompute_kernel_mat(x: torch.Tensor) -> torch.TensorComputes the centered kernel matrix.
x
torch.Tensor
The reference data.
Returns
Type:
torch.Tensor
LinearPCATorch
LinearPCATorchInherits 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)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
PCATorchInherits from: TorchOutlierDetector, Module, FitMixinTorch, ABC
Constructor
PCATorch(self, n_components: int, device: Union[typing_extensions.Literal['cuda', 'gpu', 'cpu'], ForwardRef('torch.device'), NoneType] = None)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
fitfit(x_ref: torch.Tensor) -> NoneFits the PCA detector.
x_ref
torch.Tensor
The Dataset tensor.
Returns
Type:
None
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?

