GaussianRBF#

class dataeval.detectors.drift.kernels.GaussianRBF(sigma: Tensor | None = None, init_sigma_fn: Callable | None = None, trainable: bool = False)#

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].

Parameters:
  • sigma (torch.Tensor | None, default 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 (Callable | None, default None) – Function used to compute the bandwidth sigma. Used when sigma is to be inferred. The function’s signature should take in the tensors x, y and dist and return sigma. If None, it is set to sigma_median.

  • trainable (bool, default False) – Whether or not to track gradients w.r.t. sigma to allow it to be trained.

forward(x: ndarray | Tensor, y: ndarray | Tensor, infer_sigma: bool = False) Tensor#

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.