docstr: 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
      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.pytorch.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.pytorch.kernels.sigma_median`.
  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","[","Nx",",","features","]","and","y","[","Ny",",","features","]","and","returns","the","kernel","matrix","[","Nx",",","Ny","]",".","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.pytorch.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.pytorch.kernels.sigma_median","`",".","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 [Nx, features] and y [Ny, features] and returns the kernel
      matrix [Nx, Ny].
  
      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.pytorch.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.pytorch.kernels.sigma_median`.
      trainable
          Whether or not to track gradients w.r.t. `sigma` to allow it to be trained.
      """
      super().__init__()
      init_sigma_fn = (
          sigma_median 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: import numpy
  import torch
  from torch import nn
  from .None import distance
  from typing import Optional, Union, Callable
  from alibi_detect.utils.frameworks import Framework
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)