code: def mmd2(x: tf.Tensor, y: tf.Tensor, kernel: Callable) -> float:
      """
      Compute MMD^2 between 2 samples.
  
      Parameters
      ----------
      x
          Batch of instances of shape [Nx, features].
      y
          Batch of instances of shape [Ny, features].
      kernel
          Kernel function.
  
      Returns
      -------
      MMD^2 between the samples x and y.
      """
      n, m = x.shape[0], y.shape[0]
      c_xx, c_yy = 1 / (n * (n - 1)), 1 / (m * (m - 1))
      k_xx, k_yy, k_xy = kernel(x, x), kernel(y, y), kernel(x, y)
      return (
          c_xx * (tf.reduce_sum(k_xx) - tf.linalg.trace(k_xx))
          + c_yy * (tf.reduce_sum(k_yy) - tf.linalg.trace(k_yy))
          - 2.0 * tf.reduce_mean(k_xy)
      )
  
file_path: alibi-detect/alibi_detect/utils/tensorflow/distance.py
imports: import logging
  import numpy
  import tensorflow
  from typing import Callable, Tuple, List, Optional, Union
label_desc: Use image node_id 4 for calling a global function with example usage: mmd2(x, y, kernel) and returns: unknown