class_docstr: Graph Convolutional Network
class_docstr_tok: ["Graph","Convolutional","Network"]
code: def calculate_cor_loss(self, tensors):
      def CosineSimilarity(tensor_1, tensor_2):
          # tensor_1, tensor_2: [channel]
          normalized_tensor_1 = F.normalize(tensor_1, dim=0)
          normalized_tensor_2 = F.normalize(tensor_2, dim=0)
          return (normalized_tensor_1 * normalized_tensor_2).sum(
              dim=0
          ) ** 2  # no negative
  
      def DistanceCorrelation(tensor_1, tensor_2):
          # tensor_1, tensor_2: [channel]
          # ref: https://en.wikipedia.org/wiki/Distance_correlation
          channel = tensor_1.shape[0]
          zeros = torch.zeros(channel, channel).to(tensor_1.device)
          zero = torch.zeros(1).to(tensor_1.device)
          tensor_1, tensor_2 = tensor_1.unsqueeze(
              -1
          ), tensor_2.unsqueeze(-1)
          """cul distance matrix"""
          a_, b_ = (
              torch.matmul(tensor_1, tensor_1.t()) * 2,
              torch.matmul(tensor_2, tensor_2.t()) * 2,
          )  # [channel, channel]
          tensor_1_square, tensor_2_square = (
              tensor_1**2,
              tensor_2**2,
          )
          a, b = torch.sqrt(
              torch.max(
                  tensor_1_square - a_ + tensor_1_square.t(), zeros
              )
              + 1e-8
          ), torch.sqrt(
              torch.max(
                  tensor_2_square - b_ + tensor_2_square.t(), zeros
              )
              + 1e-8
          )  # [channel, channel]
          """cul distance correlation"""
          A = (
              a
              - a.mean(dim=0, keepdim=True)
              - a.mean(dim=1, keepdim=True)
              + a.mean()
          )
          B = (
              b
              - b.mean(dim=0, keepdim=True)
              - b.mean(dim=1, keepdim=True)
              + b.mean()
          )
          dcov_AB = torch.sqrt(
              torch.max((A * B).sum() / channel**2, zero) + 1e-8
          )
          dcov_AA = torch.sqrt(
              torch.max((A * A).sum() / channel**2, zero) + 1e-8
          )
          dcov_BB = torch.sqrt(
              torch.max((B * B).sum() / channel**2, zero) + 1e-8
          )
          return dcov_AB / torch.sqrt(dcov_AA * dcov_BB + 1e-8)
  
      def MutualInformation(tensors):
          # tensors: [n_factors, dimension]
          # normalized_tensors: [n_factors, dimension]
          normalized_tensors = F.normalize(tensors, dim=1)
          scores = torch.mm(normalized_tensors, normalized_tensors.t())
          scores = torch.exp(scores / self.temperature)
          cor_loss = -torch.sum(
              torch.log(scores.diag() / scores.sum(1))
          )
          return cor_loss
  
      """cul similarity for each latent factor weight pairs"""
      if self.ind == "mi":
          return MutualInformation(tensors)
      elif self.ind == "distance":
          cor_loss = 0.0
          for i in range(self.n_factors):
              for j in range(i + 1, self.n_factors):
                  cor_loss += DistanceCorrelation(
                      tensors[i], tensors[j]
                  )
      elif self.ind == "cosine":
          cor_loss = 0.0
          for i in range(self.n_factors):
              for j in range(i + 1, self.n_factors):
                  cor_loss += CosineSimilarity(tensors[i], tensors[j])
      else:
          raise NotImplementedError(
              f"The independence loss type [{self.ind}] has not been supported."
          )
      return cor_loss
  
imports: import numpy
  import torch
  import torch.nn
  import torch.nn.functional
  import scipy.sparse
  from recbole.model.abstract_recommender import KnowledgeRecommender
  from recbole.model.init import xavier_uniform_initialization
  from recbole.model.layers import SparseDropout
  from recbole.model.loss import BPRLoss, EmbLoss
  from recbole.utils import InputType
label_desc: Use image node_id 4 for calling the GraphConv obj's underlying member method code with example usage: obj.calculate_cor_loss(tensors) and returns: cor_loss, unknown, unknown, cor_loss, MutualInformation