class_docstr: Kernel function obtained from a distance function.
  
  Formal details (for real valued objects, mixed typed rows in analogy):
  Let :math:`d: \mathbb{R}^D \times \mathbb{R}^D\rightarrow \mathbb{R}`
  be the pairwise function in `dist`, when applied to `D`-vectors.
  If `dist_diag=None`, then `KernelFromDist(dist)` corresponds to the kernel function
  :math:`k(x, y) := d(x, x)^2 + d(y, y)^2 - 0.5 \cdot d(x, y)^2`.
  If `dist_diag` is provided,
  and corresponds to a function :math:`f:\mathbb{R}^D \rightarrow \mathbb{R}`,
  then `KernelFromDist(dist)` corresponds to the kernel function
  :math:`k(x, y) := f(x, x)^2 + f(y, y)^2 - 0.5 \cdot d(x, y)^2`.
  
  It should be noted that :math:`k` is, in general, not positive semi-definite.
  
  Parameters
  ----------
  dist : pairwise transformer of BasePairwiseTransformer scitype, or
      callable np.ndarray (n_samples, nd) x (n_samples, nd) -> (n_samples x n_samples)
  dist_diag : pairwise transformer of BasePairwiseTransformer scitype, or
      series-to-panel transformer of Basetransformer scitype, or
      callable np.ndarray (n_samples, nd) -> (n_samples, )
class_docstr_tok: ["Kernel","function","obtained","from","a","distance","function",".","Formal","details","(","for","real","valued","objects",",","mixed","typed","rows","in","analogy",")",":","Let",":","math",":","`","d",":","\\mathbb","{","R","}","^D","\\times","\\mathbb","{","R","}","^D\\rightarrow","\\mathbb","{","R","}","`","be","the","pairwise","function","in","`","dist","`",",","when","applied","to","`","D","`","-vectors",".","If","`","dist_diag=None","`",",","then","`","KernelFromDist","(","dist",")","`","corresponds","to","the","kernel","function",":","math",":","`","k","(","x",",","y",")",":","=","d","(","x",",","x",")","^2","+","d","(","y",",","y",")","^2","-","0.5","\\cdot","d","(","x",",","y",")","^2","`",".","If","`","dist_diag","`","is","provided",",","and","corresponds","to","a","function",":","math",":","`","f",":","\\mathbb","{","R","}","^D","\\rightarrow","\\mathbb","{","R","}","`",",","then","`","KernelFromDist","(","dist",")","`","corresponds","to","the","kernel","function",":","math",":","`","k","(","x",",","y",")",":","=","f","(","x",",","x",")","^2","+","f","(","y",",","y",")","^2","-","0.5","\\cdot","d","(","x",",","y",")","^2","`",".","It","should","be","noted","that",":","math",":","`","k","`","is",",","in","general",",","not","positive","semi-definite",".","Parameters","--","--","--","--","--","dist",":","pairwise","transformer","of","BasePairwiseTransformer","scitype",",","or","callable","np.ndarray","(","n_samples",",","nd",")","x","(","n_samples",",","nd",")","-",">","(","n_samples","x","n_samples",")","dist_diag",":","pairwise","transformer","of","BasePairwiseTransformer","scitype",",","or","series-to-panel","transformer","of","Basetransformer","scitype",",","or","callable","np.ndarray","(","n_samples",",","nd",")","-",">","(","n_samples",",",")"]
docstr: Compute distance/kernel matrix.
  
  private _transform containing core logic, called from public transform
  
  Parameters
  ----------
  X: sktime Panel data container
  X2: sktime Panel data container
  
  Returns
  -------
  distmat: np.array of shape [n, m]
      (i,j)-th entry contains distance/kernel between X.iloc[i] and X2.iloc[j]
docstr_tok: ["Compute","distance\/kernel","matrix",".","private","_transform","containing","core","logic",",","called","from","public","transform","Parameters","--","--","--","--","--","X",":","sktime","Panel","data","container","X2",":","sktime","Panel","data","container","Returns","--","--","--","-","distmat",":","np.array","of","shape","[","n",",","m","]","(","i",",","j",")","-th","entry","contains","distance\/kernel","between","X.iloc","[","i","]","and","X2.iloc","[","j","]"]
code: def _transform(self, X, X2=None):
      """Compute distance/kernel matrix.
  
      private _transform containing core logic, called from public transform
  
      Parameters
      ----------
      X: sktime Panel data container
      X2: sktime Panel data container
  
      Returns
      -------
      distmat: np.array of shape [n, m]
          (i,j)-th entry contains distance/kernel between X.iloc[i] and X2.iloc[j]
      """
      from sktime.transformations.base import BaseTransformer
  
      dist = self.dist
      dist_diag = self.dist_diag
      if dist_diag is None:
          dist_diag = dist
  
      if isinstance(dist_diag, BasePairwiseTransformerPanel):
          diagfun = dist_diag.transform_diag
      elif isinstance(dist_diag, BaseTransformer):
          diagfun = dist_diag.fit_transform
      else:
          diagfun = _trafo_diag(dist_diag)
  
      distmat = dist(X, X2) ** 2
  
      diag1 = diagfun(X)
      if X2 is None:
          diag2 = diag1
      else:
          diag2 = diagfun(X2)
  
      diag1 = np.array(diag1).flatten() ** 2
      diag2 = np.array(diag2).flatten() ** 2
  
      n, m = distmat.shape
  
      mat1 = np.tile(np.expand_dims(diag1, 1), m)
      mat2 = np.tile(np.expand_dims(diag2, 1), n)
      mat2 = mat2.transpose()
  
      kernmat = mat1 + mat2 - 0.5 * distmat
  
      return kernmat
  
file_path: sktime/sktime/dists_kernels/dist_to_kern.py
imports: import numpy
  from sktime.dists_kernels.base import BasePairwiseTransformerPanel
label_desc: Use image node_id 2 for calling the KernelFromDist obj's underlying member method code with example usage: obj._transform(X, X2) and returns: kernmat