code: def compute_loss(self, bipartite):
      pred_den = bipartite.dstdata["pred_den"]
      loss_den = self.loss_den(pred_den, bipartite.dstdata["density"])
  
      labels_conn = bipartite.edata["labels_conn"]
      mask_conn = bipartite.edata["mask_conn"]
  
      if self.balance:
          labels_conn = bipartite.edata["labels_conn"]
          neg_check = torch.logical_and(
              bipartite.edata["labels_conn"] == 0, mask_conn
          )
          num_neg = torch.sum(neg_check).item()
          neg_indices = torch.where(neg_check)[0]
          pos_check = torch.logical_and(
              bipartite.edata["labels_conn"] == 1, mask_conn
          )
          num_pos = torch.sum(pos_check).item()
          pos_indices = torch.where(pos_check)[0]
          if num_pos > num_neg:
              mask_conn[
                  pos_indices[
                      np.random.choice(
                          num_pos, num_pos - num_neg, replace=False
                      )
                  ]
              ] = 0
          elif num_pos < num_neg:
              mask_conn[
                  neg_indices[
                      np.random.choice(
                          num_neg, num_neg - num_pos, replace=False
                      )
                  ]
              ] = 0
  
      # In subgraph training, it may happen that all edges are masked in a batch
      if mask_conn.sum() > 0:
          loss_conn = self.loss_conn(
              bipartite.edata["pred_conn"][mask_conn],
              labels_conn[mask_conn],
          )
          loss = loss_den + loss_conn
          loss_den_val = loss_den.item()
          loss_conn_val = loss_conn.item()
      else:
          loss = loss_den
          loss_den_val = loss_den.item()
          loss_conn_val = 0
  
      return loss, loss_den_val, loss_conn_val
  
file_path: dgl/examples/pytorch/hilander/models/lander.py
imports: import dgl
  import dgl.function
  import numpy
  import torch
  import torch.nn
  import torch.nn.functional
  from .focal_loss import FocalLoss
  from .graphconv import GraphConv
label_desc: Use image node_id 5 for calling the LANDER obj's underlying member method code with example usage: obj.compute_loss(bipartite) and returns: loss,  loss_den_val,  loss_conn_val