code: def _sigma_median_diag(
      x: torch.Tensor, y: torch.Tensor, dist: torch.Tensor
  ) -> torch.Tensor:
      """
      Private version of the bandwidth estimation function :py:func:`~alibi_detect.utils.pytorch.kernels.sigma_median`,
      with the +n (and -1) term excluded to account for the diagonal of the kernel matrix.
  
      Parameters
      ----------
      x
          Tensor of instances with dimension [Nx, features].
      y
          Tensor of instances with dimension [Ny, features].
      dist
          Tensor with dimensions [Nx, Ny], containing the pairwise distances between `x` and `y`.
  
      Returns
      -------
      The computed bandwidth, `sigma`.
      """
      n_median = np.prod(dist.shape) // 2
      sigma = (
          0.5
          * dist.flatten()
          .sort()
          .values[int(n_median)]
          .unsqueeze(dim=-1)
      ) ** 0.5
      return sigma
  
file_path: alibi-detect/alibi_detect/cd/pytorch/context_aware.py
imports: import logging
  import numpy
  import torch
  from typing import Callable, Dict, Optional, Tuple, Union
  from alibi_detect.cd.base import BaseContextMMDDrift
  from alibi_detect.utils.pytorch import get_device
  from alibi_detect.utils.pytorch.kernels import GaussianRBF
  from alibi_detect.utils.warnings import deprecated_alias
  from alibi_detect.utils.frameworks import Framework
  from alibi_detect.cd._domain_clf import _SVCDomainClf
  from alibi_detect.utils._types import TorchDeviceType
  from tqdm import tqdm
label_desc: Use image node_id 1 for calling a global function with example usage: _sigma_median_diag(x, y, dist) and returns: sigma