code: def compute_micro_f1(
      logits: Tensor, y: Tensor, mask: Optional[Tensor] = None
  ) -> float:
      if mask is not None:
          logits, y = logits[mask], y[mask]
  
      if y.dim() == 1:
          return int(logits.argmax(dim=-1).eq(y).sum()) / y.size(0)
      else:
          y_pred = logits > 0
          y_true = y > 0.5
  
          tp = int((y_true & y_pred).sum())
          fp = int((~y_true & y_pred).sum())
          fn = int((y_true & ~y_pred).sum())
  
          try:
              precision = tp / (tp + fp)
              recall = tp / (tp + fn)
              return 2 * (precision * recall) / (precision + recall)
          except ZeroDivisionError:
              return 0.0
  
file_path: DIG/dig/lsgraph/method/GraphFMOB/utils.py
imports: from typing import Optional, Tuple
  import torch
  from torch import Tensor
  import torch.nn.functional
  from torch_sparse import SparseTensor
label_desc: Use image node_id 1 for calling a global function with example usage: compute_micro_f1(logits, y, mask) and returns: unknown, unknown, int