docstr: We do not sample negative examples explicitly.
  Instead, given a positive pair, similar to (Chen et al., 2017), we treat the other 2(N − 1) augmented examples within a minibatch as negative examples.
docstr_tok: ["We","do","not","sample","negative","examples","explicitly",".","Instead",",","given","a","positive","pair",",","similar","to","(","Chen","et","al.",",","2017",")",",","we","treat","the","other","2","(","N","\u2212","1",")","augmented","examples","within","a","minibatch","as","negative","examples","."]
code: def decompose(self, z_i, z_j, origin_z, batch_size):
      """
      We do not sample negative examples explicitly.
      Instead, given a positive pair, similar to (Chen et al., 2017), we treat the other 2(N − 1) augmented examples within a minibatch as negative examples.
      """
      N = 2 * batch_size
  
      z = torch.cat((z_i, z_j), dim=0)
  
      # pairwise l2 distace
      sim = torch.cdist(z, z, p=2)
  
      sim_i_j = torch.diag(sim, batch_size)
      sim_j_i = torch.diag(sim, -batch_size)
  
      positive_samples = torch.cat((sim_i_j, sim_j_i), dim=0).reshape(
          N, 1
      )
      alignment = positive_samples.mean()
  
      # pairwise l2 distace
      sim = torch.cdist(origin_z, origin_z, p=2)
      mask = torch.ones((batch_size, batch_size), dtype=bool)
      mask = mask.fill_diagonal_(0)
      negative_samples = sim[mask].reshape(batch_size, -1)
      uniformity = torch.log(torch.exp(-2 * negative_samples).mean())
  
      return alignment, uniformity
  
imports: import random
  import numpy
  import torch
  from torch import nn
  import torch.nn.functional
  import math
  import torch.nn.functional
  from recbole.model.abstract_recommender import SequentialRecommender
  from recbole.model.loss import BPRLoss
  from recbole.data.interaction import Interaction
label_desc: Use image node_id 13 for calling the FEARec obj's underlying member method code with example usage: obj.decompose(z_i, z_j, origin_z, batch_size) and returns: alignment,  uniformity