alibi_detect.utils.tensorflow.kernels
DeepKernel
DeepKernelInherits from: Model, TensorFlowTrainer, Trainer, Layer, TFLayer, KerasAutoTrackable, AutoTrackable, Trackable, Operation, KerasSaveable
Computes similarities as k(x,y) = (1-eps)k_a(proj(x), proj(y)) + epsk_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].
Constructor
DeepKernel(self, proj: keras.src.models.model.Model, kernel_a: Union[keras.src.models.model.Model, str] = 'rbf', kernel_b: Union[keras.src.models.model.Model, str, NoneType] = 'rbf', eps: Union[float, str] = 'trainable') -> Noneproj
keras.src.models.model.Model
kernel_a
Union[keras.src.models.model.Model, str]
'rbf'
kernel_b
Union[keras.src.models.model.Model, str, None]
'rbf'
eps
Union[float, str]
'trainable'
Properties
eps
tensorflow.python.framework.tensor.Tensor
Methods
call
callcall(x: tensorflow.python.framework.tensor.Tensor, y: tensorflow.python.framework.tensor.Tensor) -> tensorflow.python.framework.tensor.Tensorx
tensorflow.python.framework.tensor.Tensor
y
tensorflow.python.framework.tensor.Tensor
Returns
Type:
tensorflow.python.framework.tensor.Tensor
from_config
from_configfrom_config(config)config
get_config
get_configget_config() -> dictReturns
Type:
dict
GaussianRBF
GaussianRBFInherits from: Model, TensorFlowTrainer, Trainer, Layer, TFLayer, KerasAutoTrackable, AutoTrackable, Trackable, Operation, KerasSaveable
Constructor
GaussianRBF(self, sigma: Optional[tensorflow.python.framework.tensor.Tensor] = None, init_sigma_fn: Optional[Callable] = None, trainable: bool = False) -> Nonesigma
Optional[tensorflow.python.framework.tensor.Tensor]
None
Bandwidth used for the kernel. Needn't be specified if being inferred or trained. Can pass multiple values to eval kernel with and then average.
init_sigma_fn
Optional[Callable]
None
Function used to compute the bandwidth sigma. Used when sigma is to be inferred. The function's signature should match :py:func:~alibi_detect.utils.tensorflow.kernels.sigma_median, meaning that it should take in the tensors x, y and dist and return sigma. If None, it is set to :func:~alibi_detect.utils.tensorflow.kernels.sigma_median.
trainable
bool
False
Whether or not to track gradients w.r.t. sigma to allow it to be trained.
Properties
sigma
tensorflow.python.framework.tensor.Tensor
Methods
call
callcall(x: tensorflow.python.framework.tensor.Tensor, y: tensorflow.python.framework.tensor.Tensor, infer_sigma: bool = False) -> tensorflow.python.framework.tensor.Tensorx
tensorflow.python.framework.tensor.Tensor
y
tensorflow.python.framework.tensor.Tensor
infer_sigma
bool
False
Returns
Type:
tensorflow.python.framework.tensor.Tensor
from_config
from_configfrom_config(config)Instantiates a kernel from a config dictionary.
config
A kernel config dictionary.
get_config
get_configget_config() -> dictReturns a serializable config dict (excluding the input_sigma_fn, which is serialized in alibi_detect.saving).
Returns
Type:
dict
Functions
sigma_median
sigma_mediansigma_median(x: tensorflow.python.framework.tensor.Tensor, y: tensorflow.python.framework.tensor.Tensor, dist: tensorflow.python.framework.tensor.Tensor) -> tensorflow.python.framework.tensor.TensorBandwidth estimation using the median heuristic :cite:t:Gretton2012.
x
tensorflow.python.framework.tensor.Tensor
Tensor of instances with dimension [Nx, features].
y
tensorflow.python.framework.tensor.Tensor
Tensor of instances with dimension [Ny, features].
dist
tensorflow.python.framework.tensor.Tensor
Tensor with dimensions [Nx, Ny], containing the pairwise distances between x and y.
Returns
Type:
tensorflow.python.framework.tensor.Tensor
Last updated
Was this helpful?

