code: def _moment_k(
      x: torch.Tensor, domain_labels: torch.Tensor, k_order=2
  ):
      """Compute the k-th moment distance
  
      Args:
          x (torch.Tensor): input data, shape (n_samples, n_features)
          domain_labels (torch.Tensor): labels indicating which domain the instance is from, shape (n_samples,)
          k_order (int, optional): moment order. Defaults to 2.
  
      Returns:
          torch.Tensor: the k-th moment distance
  
      The code is based on:
          https://github.com/KaiyangZhou/Dassl.pytorch/blob/master/dassl/engine/da/m3sda.py#L153
          https://github.com/VisionLearningGroup/VisionLearningGroup.github.io/blob/master/M3SDA/code_MSDA_digit/metric/msda.py#L6
      """
      unique_domain_ = torch.unique(domain_labels)
      n_unique_domain_ = len(unique_domain_)
      x_k_order = []
      for domain_label_ in unique_domain_:
          domain_idx = torch.where(domain_labels == domain_label_)[0]
          x_mean = x[domain_idx].mean(0)
          if k_order == 1:
              x_k_order.append(x_mean)
          else:
              x_k_order.append(
                  ((x[domain_idx] - x_mean) ** k_order).mean(0)
              )
      moment_sum = 0
      n_pair = 0
      for i in range(n_unique_domain_):
          for j in range(i + 1, n_unique_domain_):
              moment_sum += euclidean(x_k_order[i], x_k_order[j])
              n_pair += 1
      return moment_sum / n_pair
  
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 11 for calling a global function with example usage: _moment_k(x, domain_labels, k_order) and returns: unknown