MMD(source_feat, target_feat, sampling_num=1000, times=5)

Calculate MMD with random sampling for large-scale datasets.

Parameters:
  • source_feat (Tensor) –

    Source domain features in shape of (n_source, feature_dim)

  • target_feat (Tensor) –

    Target domain features in shape of (n_target, feature_dim)

  • sampling_num (int, default: 1000 ) –

    Number of samples per iteration. Default: 1000

  • times (int, default: 5 ) –

    Number of sampling iterations. Default: 5

Returns:
  • Tensor

    Averaged MMD loss value across sampling iterations

Notes

Processing Steps:

  • Generate random sample indices
  • Sample features from both domains
  • Calculate MMD for each sample
  • Average across iterations

Features:

  • Random sampling
  • Multiple iterations
  • Memory efficient
  • Scalable computation
get_MMD(source_feat, target_feat, kernel_mul=2.0, kernel_num=5, fix_sigma=None)

Calculate Maximum Mean Discrepancy (MMD) between source and target features.

Parameters:
  • source_feat (Tensor) –

    Source domain features in shape of (n_source, feature_dim)

  • target_feat (Tensor) –

    Target domain features in shape of (n_target, feature_dim)

  • kernel_mul (float, default: 2.0 ) –

    Multiplication factor for kernel bandwidth. Default: 2.0

  • kernel_num (int, default: 5 ) –

    Number of kernels to use. Default: 5

  • fix_sigma (float, default: None ) –

    Fixed bandwidth value. If None, computed from data. Default: None

Returns:
  • Tensor

    MMD loss value between source and target domains

Notes

Processing Steps:

  • Compute Gaussian kernel matrix
  • Extract within-domain kernels (XX, YY)
  • Extract cross-domain kernels (XY, YX)
  • Calculate MMD loss

Features:

  • Batch-wise computation
  • Multiple kernel integration
  • Unbiased estimation
guassian_kernel(source, target, kernel_mul=2.0, kernel_num=5, fix_sigma=None)

Calculate Gaussian kernel matrix between source and target features.

Parameters:
  • source (Tensor) –

    Source domain features in shape of (n_source, feature_dim)

  • target (Tensor) –

    Target domain features in shape of (n_target, feature_dim)

  • kernel_mul (float, default: 2.0 ) –

    Multiplication factor for kernel bandwidth. Default: 2.0

  • kernel_num (int, default: 5 ) –

    Number of kernels to use. Default: 5

  • fix_sigma (float, default: None ) –

    Fixed bandwidth value. If None, computed from data. Default: None

Returns:
  • Tensor

    Combined kernel matrix from multiple bandwidths

Notes

Processing Steps:

  • Combine source and target features
  • Compute pairwise L2 distances
  • Calculate kernel bandwidth
  • Generate multiple kernels
  • Sum kernel matrices

Features:

  • Multiple kernel computation
  • Adaptive bandwidth
  • Efficient matrix operations