class_docstr: Applies utterance-level speaker permutation
  
  Computes the maxium possible value of the given utility function
  over the permutations of the speakers.
  
  Args:
      utility_func (function):
          Function that computes the utility (opposite of loss) with signature of
          (extimate: torch.Tensor, reference: torch.Tensor) -> torch.Tensor
          where input Tensors are shape of [batch, speakers, frame] and
          the output Tensor is shape of [batch, speakers].
  
  References:
      - Multi-talker Speech Separation with Utterance-level Permutation Invariant Training of
        Deep Recurrent Neural Networks
        Morten Kolbæk, Dong Yu, Zheng-Hua Tan and Jesper Jensen
        https://arxiv.org/abs/1703.06284
docstr: Compute utterance-level PIT Loss
  
  Args:
      estimate (torch.Tensor): Estimated source signals.
          Shape: [bacth, speakers, time frame]
      reference (torch.Tensor): Reference (original) source signals.
          Shape: [batch, speakers, time frame]
      mask (torch.Tensor or None, optional): Binary mask to indicate padded value (0) or valid value (1).
          Shape: [batch, 1, time frame]
      epsilon (float, optional): constant value used to stabilize division.
  
  Returns:
      torch.Tensor: Maximum criterion over the speaker permutation.
          Shape: [batch, ]
docstr_tok: ["Compute","utterance-level","PIT","Loss","Args",":","estimate","(","torch.Tensor",")",":","Estimated","source","signals",".","Shape",":","[","bacth",",","speakers",",","time","frame","]","reference","(","torch.Tensor",")",":","Reference","(","original",")","source","signals",".","Shape",":","[","batch",",","speakers",",","time","frame","]","mask","(","torch.Tensor","or","None",",","optional",")",":","Binary","mask","to","indicate","padded","value","(","0",")","or","valid","value","(","1",")",".","Shape",":","[","batch",",","1",",","time","frame","]","epsilon","(","float",",","optional",")",":","constant","value","used","to","stabilize","division",".","Returns",":","torch.Tensor",":","Maximum","criterion","over","the","speaker","permutation",".","Shape",":","[","batch",",","]"]
code: def forward(
      self,
      estimate: torch.Tensor,
      reference: torch.Tensor,
      mask: Optional[torch.Tensor] = None,
      epsilon: float = 1e-8,
  ) -> torch.Tensor:
      """Compute utterance-level PIT Loss
  
      Args:
          estimate (torch.Tensor): Estimated source signals.
              Shape: [bacth, speakers, time frame]
          reference (torch.Tensor): Reference (original) source signals.
              Shape: [batch, speakers, time frame]
          mask (torch.Tensor or None, optional): Binary mask to indicate padded value (0) or valid value (1).
              Shape: [batch, 1, time frame]
          epsilon (float, optional): constant value used to stabilize division.
  
      Returns:
          torch.Tensor: Maximum criterion over the speaker permutation.
              Shape: [batch, ]
      """
      assert estimate.shape == reference.shape
  
      batch_size, num_speakers = reference.shape[:2]
      num_permute = math.factorial(num_speakers)
  
      util_mat = torch.zeros(
          batch_size,
          num_permute,
          dtype=estimate.dtype,
          device=estimate.device,
      )
      for i, idx in enumerate(permutations(range(num_speakers))):
          util = self.utility_func(
              estimate, reference[:, idx, :], mask=mask, epsilon=epsilon
          )
          util_mat[:, i] = util.mean(
              dim=1
          )  # take the average over speaker dimension
      return util_mat.max(dim=1).values
  
file_path: audio/examples/source_separation/utils/metrics.py
imports: import math
  from itertools import permutations
  from typing import Optional
  import torch
label_desc: Use image node_id 2 for calling the PIT obj's underlying member method code with example usage: obj.forward(estimate, reference, mask, epsilon) and returns: util_mat