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
sample (
Tensor
) – A 1D vector of valuesp (
float
) – The desired quantile in (0,1)type (
int
) – The method for computing the quantile. See https://wikipedia.org/wiki/Quantile#Estimating_quantiles_from_a_samplesorted (
bool
) – Whether or not the vector is already sorted into ascending order
- Return type
- Returns
An estimate of the quantile