alibi.utils.kernel module

class alibi.utils.kernel.EuclideanDistance[source]

Bases: object

__call__(x, y)[source]

Computes the kernel distance matrix between x and y.

Parameters:
  • x (ndarray) – The first array of data instances.

  • y (ndarray) – The second array of data instances.

Return type:

ndarray

Returns:

Kernel distance matrix between x and y having the size of Nx x Ny, where Nx is the number of instances in x and y is the number of instances in y.

__init__()[source]

Euclidean distance: \(k(x, y) = ||x-y||\). A forward pass takes a batch of instances x of size Nx x f1 x f2 x … ` and `y of size Ny x f1 x f2 x … and returns the kernel matrix Nx x Ny.

class alibi.utils.kernel.GaussianRBF(sigma=None)[source]

Bases: object

__call__(x, y, infer_sigma=False)[source]

Computes the kernel matrix between x and y.

Parameters:
  • x (ndarray) – The first array of data instances.

  • y (ndarray) – The second array of data instances.

  • infer_sigma (bool) – Whether to infer sigma automatically. The sigma value is computed based on the median distance value between the instances from x and y.

Return type:

ndarray

Returns:

Kernel matrix between x and y having the size of Nx x Ny where Nx is the number of instances in x and y is the number of instances in y.

__init__(sigma=None)[source]

Gaussian RBF kernel: \(k(x,y) = \exp(-\frac{||x-y||^2}{2\sigma^2})\). A forward pass takes a batch of instances x of size Nx x f1 x f2 x … and y of size Ny x f1 x f2 x … ` and returns the kernel matrix of size `Nx x Ny.

Parameters:

sigma (Union[float, ndarray, None]) – Kernel bandwidth. Not to be specified if being inferred or trained. Can pass multiple values to evaluate the kernel with and then average.

property sigma: ndarray
Return type:

ndarray

class alibi.utils.kernel.GaussianRBFDistance(sigma=None)[source]

Bases: object

__init__(sigma=None)[source]

Gaussian RBF kernel dissimilarity/distance: \(k(x, y) = 1 - \exp(-\frac{||x-y||^2}{2\sigma^2})\). A forward pass takes a batch of instances x of size Nx x f1 x f2 x … and y of size Ny x f1 x f2 x … and returns the kernel matrix of size Nx x Ny.

Parameters:

sigma (Union[float, ndarray, None]) – See alibi.utils.kernel.GaussianRBF.__init__().