docstr: Computes similarities as k(x,y) = (1-eps)*k_a(proj(x), proj(y)) + eps*k_b(x,y).
  A forward pass takes an already projected batch of instances x_proj and y_proj and optionally
  (if k_b is present) a batch of instances x and y and returns the kernel matrix.
  x_proj can be of shape [Nx, 1, features_proj] or [batch_size, Nx, 1, features_proj].
  y_proj can be of shape [1, Ny, features_proj] or [batch_size, 1, Ny, features_proj].
  x can be of shape [Nx, 1, features] or [batch_size, Nx, 1, features].
  y can be of shape [1, Ny, features] or [batch_size, 1, Ny, features].
  The returned kernel matrix can be of shape [Nx, Ny] or [batch_size, Nx, Ny].
  x, y and the returned kernel matrix are all lazy tensors.
  
  Parameters
  ----------
  proj
      The projection to be applied to the inputs before applying kernel_a
  kernel_a
      The kernel to apply to the projected inputs. Defaults to a Gaussian RBF with trainable bandwidth.
  kernel_b
      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
      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 if kernel_b is not None.
docstr_tok: ["Computes","similarities","as","k","(","x",",","y",")","=","(","1-eps",")","*","k_a","(","proj","(","x",")",",","proj","(","y",")",")","+","eps","*","k_b","(","x",",","y",")",".","A","forward","pass","takes","an","already","projected","batch","of","instances","x_proj","and","y_proj","and","optionally","(","if","k_b","is","present",")","a","batch","of","instances","x","and","y","and","returns","the","kernel","matrix",".","x_proj","can","be","of","shape","[","Nx",",","1",",","features_proj","]","or","[","batch_size",",","Nx",",","1",",","features_proj","]",".","y_proj","can","be","of","shape","[","1",",","Ny",",","features_proj","]","or","[","batch_size",",","1",",","Ny",",","features_proj","]",".","x","can","be","of","shape","[","Nx",",","1",",","features","]","or","[","batch_size",",","Nx",",","1",",","features","]",".","y","can","be","of","shape","[","1",",","Ny",",","features","]","or","[","batch_size",",","1",",","Ny",",","features","]",".","The","returned","kernel","matrix","can","be","of","shape","[","Nx",",","Ny","]","or","[","batch_size",",","Nx",",","Ny","]",".","x",",","y","and","the","returned","kernel","matrix","are","all","lazy","tensors",".","Parameters","--","--","--","--","--","proj","The","projection","to","be","applied","to","the","inputs","before","applying","kernel_a","kernel_a","The","kernel","to","apply","to","the","projected","inputs",".","Defaults","to","a","Gaussian","RBF","with","trainable","bandwidth",".","kernel_b","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","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","if","kernel_b","is","not","None","."]
code: def __init__(
      self,
      proj: nn.Module,
      kernel_a: Union[nn.Module, Literal["rbf"]] = "rbf",
      kernel_b: Optional[Union[nn.Module, Literal["rbf"]]] = "rbf",
      eps: Union[float, Literal["trainable"]] = "trainable",
  ) -> None:
      """
      Computes similarities as k(x,y) = (1-eps)*k_a(proj(x), proj(y)) + eps*k_b(x,y).
      A forward pass takes an already projected batch of instances x_proj and y_proj and optionally
      (if k_b is present) a batch of instances x and y and returns the kernel matrix.
      x_proj can be of shape [Nx, 1, features_proj] or [batch_size, Nx, 1, features_proj].
      y_proj can be of shape [1, Ny, features_proj] or [batch_size, 1, Ny, features_proj].
      x can be of shape [Nx, 1, features] or [batch_size, Nx, 1, features].
      y can be of shape [1, Ny, features] or [batch_size, 1, Ny, features].
      The returned kernel matrix can be of shape [Nx, Ny] or [batch_size, Nx, Ny].
      x, y and the returned kernel matrix are all lazy tensors.
  
      Parameters
      ----------
      proj
          The projection to be applied to the inputs before applying kernel_a
      kernel_a
          The kernel to apply to the projected inputs. Defaults to a Gaussian RBF with trainable bandwidth.
      kernel_b
          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
          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 if kernel_b is not None.
      """
      super().__init__()
      self.config = {
          "proj": proj,
          "kernel_a": kernel_a,
          "kernel_b": kernel_b,
          "eps": eps,
      }
      if kernel_a == "rbf":
          kernel_a = GaussianRBF(trainable=True)
      if kernel_b == "rbf":
          kernel_b = GaussianRBF(trainable=True)
      self.kernel_a: Callable = kernel_a
      self.kernel_b: Callable = kernel_b
      self.proj = proj
      if kernel_b is not None:
          self._init_eps(eps)
  
imports: from pykeops.torch import LazyTensor
  import torch
  import torch.nn
  from typing import Callable, Optional, Union
  from alibi_detect.utils.frameworks import Framework
  from alibi_detect.utils._types import Literal
  from copy import deepcopy
label_desc: Use image node_id 1 to create a new DeepKernel object from inherited base classes: nn with example: obj = DeepKernel(proj, kernel_a, kernel_b, eps)