docstr: Gaussian RBF kernel: k(x,y) = exp(-(1/(2*sigma^2)||x-y||^2). A forward pass takes
  a batch of instances x and y and returns the kernel matrix.
  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
  ----------
  sigma
      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
      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.keops.kernels.sigma_mean`,
      meaning that it should take in the lazy tensors `x`, `y` and `dist` and return a tensor `sigma`.
  trainable
      Whether or not to track gradients w.r.t. `sigma` to allow it to be trained.
docstr_tok: ["Gaussian","RBF","kernel",":","k","(","x",",","y",")","=","exp","(","-","(","1\/","(","2","*","sigma^2",")","||x-y||^2",")",".","A","forward","pass","takes","a","batch","of","instances","x","and","y","and","returns","the","kernel","matrix",".","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","--","--","--","--","--","sigma","Bandwidth","used","for","the","kernel",".","Need","n't","be","specified","if","being","inferred","or","trained",".","Can","pass","multiple","values","to","eval","kernel","with","and","then","average",".","init_sigma_fn","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.keops.kernels.sigma_mean","`",",","meaning","that","it","should","take","in","the","lazy","tensors","`","x","`",",","`","y","`","and","`","dist","`","and","return","a","tensor","`","sigma","`",".","trainable","Whether","or","not","to","track","gradients","w.r.t",".","`","sigma","`","to","allow","it","to","be","trained","."]
code: def __init__(
      self,
      sigma: Optional[torch.Tensor] = None,
      init_sigma_fn: Optional[Callable] = None,
      trainable: bool = False,
  ) -> None:
      """
      Gaussian RBF kernel: k(x,y) = exp(-(1/(2*sigma^2)||x-y||^2). A forward pass takes
      a batch of instances x and y and returns the kernel matrix.
      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
      ----------
      sigma
          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
          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.keops.kernels.sigma_mean`,
          meaning that it should take in the lazy tensors `x`, `y` and `dist` and return a tensor `sigma`.
      trainable
          Whether or not to track gradients w.r.t. `sigma` to allow it to be trained.
      """
      super().__init__()
      init_sigma_fn = (
          sigma_mean if init_sigma_fn is None else init_sigma_fn
      )
      self.config = {
          "sigma": sigma,
          "trainable": trainable,
          "init_sigma_fn": init_sigma_fn,
      }
      if sigma is None:
          self.log_sigma = nn.Parameter(
              torch.empty(1), requires_grad=trainable
          )
          self.init_required = True
      else:
          sigma = sigma.reshape(-1)  # [Ns,]
          self.log_sigma = nn.Parameter(
              sigma.log(), requires_grad=trainable
          )
          self.init_required = False
      self.init_sigma_fn = init_sigma_fn
      self.trainable = trainable
  
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 GaussianRBF object from inherited base classes: nn with example: obj = GaussianRBF(sigma, init_sigma_fn, trainable)