code: def compute_confusion_matrix_metric(
      metric_name: str, confusion_matrix: torch.Tensor
  ) -> torch.Tensor:
      """
      This function is used to compute confusion matrix related metric.
  
      Args:
          metric_name: [``"sensitivity"``, ``"specificity"``, ``"precision"``, ``"negative predictive value"``,
              ``"miss rate"``, ``"fall out"``, ``"false discovery rate"``, ``"false omission rate"``,
              ``"prevalence threshold"``, ``"threat score"``, ``"accuracy"``, ``"balanced accuracy"``,
              ``"f1 score"``, ``"matthews correlation coefficient"``, ``"fowlkes mallows index"``,
              ``"informedness"``, ``"markedness"``]
              Some of the metrics have multiple aliases (as shown in the wikipedia page aforementioned),
              and you can also input those names instead.
          confusion_matrix: Please see the doc string of the function ``get_confusion_matrix`` for more details.
  
      Raises:
          ValueError: when the size of the last dimension of confusion_matrix is not 4.
          NotImplementedError: when specify a not implemented metric_name.
  
      """
  
      metric = check_confusion_matrix_metric_name(metric_name)
  
      input_dim = confusion_matrix.ndimension()
      if input_dim == 1:
          confusion_matrix = confusion_matrix.unsqueeze(dim=0)
      if confusion_matrix.shape[-1] != 4:
          raise ValueError(
              "the size of the last dimension of confusion_matrix should be 4."
          )
  
      tp = confusion_matrix[..., 0]
      fp = confusion_matrix[..., 1]
      tn = confusion_matrix[..., 2]
      fn = confusion_matrix[..., 3]
      p = tp + fn
      n = fp + tn
      # calculate metric
      numerator: torch.Tensor
      denominator: torch.Tensor | float
      nan_tensor = torch.tensor(
          float("nan"), device=confusion_matrix.device
      )
      if metric == "tpr":
          numerator, denominator = tp, p
      elif metric == "tnr":
          numerator, denominator = tn, n
      elif metric == "ppv":
          numerator, denominator = tp, (tp + fp)
      elif metric == "npv":
          numerator, denominator = tn, (tn + fn)
      elif metric == "fnr":
          numerator, denominator = fn, p
      elif metric == "fpr":
          numerator, denominator = fp, n
      elif metric == "fdr":
          numerator, denominator = fp, (fp + tp)
      elif metric == "for":
          numerator, denominator = fn, (fn + tn)
      elif metric == "pt":
          tpr = torch.where(p > 0, tp / p, nan_tensor)
          tnr = torch.where(n > 0, tn / n, nan_tensor)
          numerator = torch.sqrt(tpr * (1.0 - tnr)) + tnr - 1.0
          denominator = tpr + tnr - 1.0
      elif metric == "ts":
          numerator, denominator = tp, (tp + fn + fp)
      elif metric == "acc":
          numerator, denominator = (tp + tn), (p + n)
      elif metric == "ba":
          tpr = torch.where(p > 0, tp / p, nan_tensor)
          tnr = torch.where(n > 0, tn / n, nan_tensor)
          numerator, denominator = (tpr + tnr), 2.0
      elif metric == "f1":
          numerator, denominator = tp * 2.0, (tp * 2.0 + fn + fp)
      elif metric == "mcc":
          numerator = tp * tn - fp * fn
          denominator = torch.sqrt(
              (tp + fp) * (tp + fn) * (tn + fp) * (tn + fn)
          )
      elif metric == "fm":
          tpr = torch.where(p > 0, tp / p, nan_tensor)
          ppv = torch.where((tp + fp) > 0, tp / (tp + fp), nan_tensor)
          numerator = torch.sqrt(ppv * tpr)
          denominator = 1.0
      elif metric == "bm":
          tpr = torch.where(p > 0, tp / p, nan_tensor)
          tnr = torch.where(n > 0, tn / n, nan_tensor)
          numerator = tpr + tnr - 1.0
          denominator = 1.0
      elif metric == "mk":
          ppv = torch.where((tp + fp) > 0, tp / (tp + fp), nan_tensor)
          npv = torch.where((tn + fn) > 0, tn / (tn + fn), nan_tensor)
          numerator = ppv + npv - 1.0
          denominator = 1.0
      else:
          raise NotImplementedError("the metric is not implemented.")
  
      if isinstance(denominator, torch.Tensor):
          return torch.where(
              denominator != 0, numerator / denominator, nan_tensor
          )
      return numerator / denominator
  
file_path: MONAI/monai/metrics/confusion_matrix.py
imports: from __future__ import annotations
  import warnings
  from collections.abc import Sequence
  import torch
  from monai.metrics.utils import do_metric_reduction, ignore_background
  from monai.utils import MetricReduction, ensure_tuple
  from .metric import CumulativeIterationMetric
label_desc: Use image node_id 2 for calling a global function with example usage: compute_confusion_matrix_metric(metric_name, confusion_matrix) and returns: unknown, torch