code: def gaussian_kernel(
      source, target, kernel_mul=2.0, kernel_num=5, fix_sigma=None
  ):
      """
      Code from XLearn: computes the full kernel matrix, which is less than optimal since we don't use all of it
      with the linear MMD estimate.
  
      Examples:
          See DANTrainer and JANTrainer in kale.pipeline.domain_adapter
      """
      n_samples = int(source.size()[0]) + int(target.size()[0])
      total = torch.cat([source, target], dim=0)
      total0 = total.unsqueeze(0).expand(
          int(total.size(0)), int(total.size(0)), int(total.size(1))
      )
      total1 = total.unsqueeze(1).expand(
          int(total.size(0)), int(total.size(0)), int(total.size(1))
      )
      l2_distance = ((total0 - total1) ** 2).sum(2)
      if fix_sigma:
          bandwidth = fix_sigma
      else:
          bandwidth = torch.sum(l2_distance.data) / (
              n_samples**2 - n_samples
          )
      bandwidth /= kernel_mul ** (kernel_num // 2)
      bandwidth_list = [
          bandwidth * (kernel_mul**i) for i in range(kernel_num)
      ]
      kernel_val = [
          torch.exp(-l2_distance / bandwidth_temp)
          for bandwidth_temp in bandwidth_list
      ]
      return sum(kernel_val)
  
file_path: pykale/kale/predict/losses.py
imports: import torch
  import torch.nn
  from torch.autograd import grad
  from torch.nn import functional
label_desc: Use image node_id 7 for calling a global function with example usage: gaussian_kernel(source, target, kernel_mul, kernel_num, fix_sigma) and returns: sum