alibi_detect.utils.tensorflow.kernels module
- class alibi_detect.utils.tensorflow.kernels.DeepKernel(proj, kernel_a=tensorflow.keras.Model, kernel_b=tensorflow.keras.Model, eps='trainable')[source]
Bases:
tensorflow.keras.Model
Computes similarities as k(x,y) = (1-eps)*k_a(proj(x), proj(y)) + eps*k_b(x,y). A forward pass takes a batch of instances x [Nx, features] and y [Ny, features] and returns the kernel matrix [Nx, Ny].
- Parameters
proj (
Model
) – The projection to be applied to the inputs before applying kernel_akernel_a (
Model
) – The kernel to apply to the projected inputs. Defaults to a Gaussian RBF with trainable bandwidth.kernel_b (
Optional
[Model
]) – The kernel to apply to the raw inputs. Defaults to a Gaussian RBF with trainable bandwidth. Set to None in order to use only the deep component (i.e. eps=0).eps (
Union
[float
,str
]) – The proportion (in [0,1]) of weight to assign to the kernel applied to raw inputs. This can be either specified or set to ‘trainable’. Only relavent is kernel_b is not None.
- property eps: tensorflow.Tensor
- Return type
Tensor
- class alibi_detect.utils.tensorflow.kernels.GaussianRBF(sigma=None, trainable=False)[source]
Bases:
tensorflow.keras.Model
- __init__(sigma=None, trainable=False)[source]
Gaussian RBF kernel: k(x,y) = exp(-(1/(2*sigma^2)||x-y||^2). A forward pass takes a batch of instances x [Nx, features] and y [Ny, features] and returns the kernel matrix [Nx, Ny].
- property sigma: tensorflow.Tensor
- Return type
Tensor