alibi_detect.utils.pytorch.misc module

alibi_detect.utils.pytorch.misc.get_device(device=None)[source]

Instantiates a PyTorch device object.

Parameters

device (Union[str, device, None]) – Either None, a str (‘gpu’ or ‘cpu’) indicating the device to choose, or an already instantiated device object. If None, the GPU is selected if it is detected, otherwise the CPU is used as a fallback.

Return type

device

Returns

The instantiated device object.

alibi_detect.utils.pytorch.misc.quantile(sample, p, type=7, sorted=False)[source]

Estimate a desired quantile of a univariate distribution from a vector of samples

Parameters
Return type

float

Returns

An estimate of the quantile

alibi_detect.utils.pytorch.misc.zero_diag(mat)[source]

Set the diagonal of a matrix to 0

Parameters

mat (Tensor) – A 2D square matrix

Return type

Tensor

Returns

A 2D square matrix with zeros along the diagonal