alibi_detect.utils.tensorflow.distance module
- alibi_detect.utils.tensorflow.distance.batch_compute_kernel_matrix(x, y, kernel, batch_size=10000000000, preprocess_fn=None)[source]
Compute the kernel matrix between x and y by filling in blocks of size batch_size x batch_size at a time.
- Parameters:
- Return type:
Tensor
- Returns:
Kernel matrix in the form of a tensorflow tensor
- alibi_detect.utils.tensorflow.distance.mmd2_from_kernel_matrix(kernel_mat, m, permute=False, zero_diag=True)[source]
Compute maximum mean discrepancy (MMD^2) between 2 samples x and y from the full kernel matrix between the samples.
- Parameters:
- Return type:
Tensor
- Returns:
MMD^2 between the samples from the kernel matrix.
- alibi_detect.utils.tensorflow.distance.permed_lsdds(k_all_c, x_perms, y_perms, H, H_lam_inv=None, lam_rd_max=0.2, return_unpermed=False)[source]
Compute LSDD estimates from kernel matrix across various ref and test window samples
- Parameters:
k_all_c (
Tensor
) – Kernel matrix of similarities between all samples and the kernel centers.x_perms (
List
[Tensor
]) – List of B reference window index vectorsy_perms (
List
[Tensor
]) – List of B test window index vectorsH (
Tensor
) – Special (scaled) kernel matrix of similarities between kernel centersH_lam_inv (
Optional
[Tensor
]) – Function of H corresponding to a particular regulariation parameter lambda. See Eqn 11 of Bu et al. (2017)lam_rd_max (
float
) – The maximum relative difference between two estimates of LSDD that the regularization parameter lambda is allowed to cause. Defaults to 0.2. Only relavent if H_lam_inv is not supplied.return_unpermed (
bool
) – Whether or not to return value corresponding to unpermed order defined by k_all_c
- Return type:
- Returns:
Vector of B LSDD estimates for each permutation, H_lam_inv which may have been inferred, and optionally the unpermed LSDD estimate.
- alibi_detect.utils.tensorflow.distance.relative_euclidean_distance(x, y, eps=1e-12, axis=-1)[source]
Relative Euclidean distance.
- Parameters:
- Return type:
Tensor
- Returns:
Tensor with relative Euclidean distance across specified axis.