code: def sigma_median(
      x: tf.Tensor, y: tf.Tensor, dist: tf.Tensor
  ) -> tf.Tensor:
      """
      Bandwidth estimation using the median heuristic :cite:t:`Gretton2012`.
  
      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 = min(x.shape[0], y.shape[0])
      n = (
          n
          if tf.reduce_all(x[:n] == y[:n]) and x.shape == y.shape
          else 0
      )
      n_median = n + (tf.math.reduce_prod(dist.shape) - n) // 2 - 1
      sigma = tf.expand_dims(
          (0.5 * tf.sort(tf.reshape(dist, (-1,)))[n_median]) ** 0.5,
          axis=0,
      )
      return sigma
  
imports: import tensorflow
  import numpy
  from .None import distance
  from typing import Optional, Union, Callable
  from scipy.special import logit
  from alibi_detect.utils.frameworks import Framework
label_desc: Use image node_id 1 for calling a global function with example usage: sigma_median(x, y, dist) and returns: sigma