class_docstr: Normalized Maximum Eigengap based Spectral Clustering (NME-SC)
  uses Eigengap analysis to get an estimated p-value for
  affinity binarization and an estimated number of speakers.
  
  p_value (also referred to as p_neighbors) is for taking
  top p number of affinity values and convert those to 1 while
  convert the rest of values to 0.
  
  p_value can be also tuned on a development set without performing
  NME-analysis. Fixing p_value brings about significantly faster clustering
  speed, but the performance is limited to the development set.
  
  References:
      Tae Jin Park et al., Auto-Tuning Spectral Clustering for Speaker Diarization
      Using Normalized Maximum Eigengap, IEEE Signal Processing Letters 27 (2019),
      https://arxiv.org/abs/2003.02405
  
  Args:
      Please refer to def __init__().
  
  Methods:
      NMEanalysis():
          Performs NME-analysis to estimate p_value and the number of speakers
      subsampleAffinityMat(nme_mat_size):
          Subsamples the number of speakers to reduce the computational load
      getPvalueList():
          Generates a list containing p-values that need to be examined.
      getEigRatio(p_neighbors):
          Calculates g_p, which is a ratio between p_neighbors and the maximum eigengap
      getLamdaGaplist(lambdas):
          Calculates lambda gap values from an array contains lambda values
      estimateNumofSpeakers(affinity_mat):
          Estimates the number of speakers using lambda gap list
class_docstr_tok: ["Normalized","Maximum","Eigengap","based","Spectral","Clustering","(","NME-SC",")","uses","Eigengap","analysis","to","get","an","estimated","p-value","for","affinity","binarization","and","an","estimated","number","of","speakers",".","p_value","(","also","referred","to","as","p_neighbors",")","is","for","taking","top","p","number","of","affinity","values","and","convert","those","to","1","while","convert","the","rest","of","values","to","0.","p_value","can","be","also","tuned","on","a","development","set","without","performing","NME-analysis",".","Fixing","p_value","brings","about","significantly","faster","clustering","speed",",","but","the","performance","is","limited","to","the","development","set",".","References",":","Tae","Jin","Park","et","al.",",","Auto-Tuning","Spectral","Clustering","for","Speaker","Diarization","Using","Normalized","Maximum","Eigengap",",","IEEE","Signal","Processing","Letters","27","(","2019",")",",","https",":","\/\/arxiv.org\/abs\/2003.02405","Args",":","Please","refer","to","def","__init__","(",")",".","Methods",":","NMEanalysis","(",")",":","Performs","NME-analysis","to","estimate","p_value","and","the","number","of","speakers","subsampleAffinityMat","(","nme_mat_size",")",":","Subsamples","the","number","of","speakers","to","reduce","the","computational","load","getPvalueList","(",")",":","Generates","a","list","containing","p-values","that","need","to","be","examined",".","getEigRatio","(","p_neighbors",")",":","Calculates","g_p",",","which","is","a","ratio","between","p_neighbors","and","the","maximum","eigengap","getLamdaGaplist","(","lambdas",")",":","Calculates","lambda","gap","values","from","an","array","contains","lambda","values","estimateNumofSpeakers","(","affinity_mat",")",":","Estimates","the","number","of","speakers","using","lambda","gap","list"]
docstr: Args:
      mat (Tensor):
          Cosine similarity matrix calculated from the provided speaker embeddings.
      max_num_speakers (int):
          Maximum number of speakers for estimating number of speakers.
          Shows stable performance under 20.
      max_rp_threshold (float):
          Limits the range of parameter search.
          Clustering performance can vary depending on this range.
          Default is 0.25.
      sparse_search (bool):
          To increase the speed of parameter estimation, sparse_search=True
          limits the number of p_values we search.
      sparse_search_volume (int):
          Number of p_values we search during NME analysis.
          Default is 30. The lower the value, the faster NME-analysis becomes.
          However, a value lower than 20 might cause a poor parameter estimation.
      nme_mat_size (int):
          Targeted size of matrix for NME analysis.
      use_subsampling_for_nme (bool):
          Use subsampling to reduce the calculational complexity.
          Default is True.
      fixed_thres (float or None):
          A fixed threshold which can be used instead of estimating the
          threshold with NME analysis. If fixed_thres is float,
          it skips the NME analysis part.
      maj_vote_spk_count (bool):
          If True, take a majority vote on all p-values in the given range to estimate the number of speakers.
          The majority voting may contribute to surpress overcounting of the speakers and improve speaker
          counting accuracy.
      parallelism (bool):
          If True, turn on parallelism based on torch.jit.script library.
      cuda (bool):
          Use cuda for Eigen decomposition if cuda=True.
      device (torch.device):
          Torch device variable
code: def __init__(
      self,
      mat: torch.Tensor,
      max_num_speakers: int = 10,
      max_rp_threshold: float = 0.15,
      sparse_search: bool = True,
      sparse_search_volume: int = 30,
      nme_mat_size: int = 512,
      use_subsampling_for_nme: bool = True,
      fixed_thres: float = -1.0,
      maj_vote_spk_count: bool = False,
      parallelism: bool = True,
      cuda: bool = False,
      device: torch.device = torch.device("cpu"),
  ):
      """
      Args:
          mat (Tensor):
              Cosine similarity matrix calculated from the provided speaker embeddings.
          max_num_speakers (int):
              Maximum number of speakers for estimating number of speakers.
              Shows stable performance under 20.
          max_rp_threshold (float):
              Limits the range of parameter search.
              Clustering performance can vary depending on this range.
              Default is 0.25.
          sparse_search (bool):
              To increase the speed of parameter estimation, sparse_search=True
              limits the number of p_values we search.
          sparse_search_volume (int):
              Number of p_values we search during NME analysis.
              Default is 30. The lower the value, the faster NME-analysis becomes.
              However, a value lower than 20 might cause a poor parameter estimation.
          nme_mat_size (int):
              Targeted size of matrix for NME analysis.
          use_subsampling_for_nme (bool):
              Use subsampling to reduce the calculational complexity.
              Default is True.
          fixed_thres (float or None):
              A fixed threshold which can be used instead of estimating the
              threshold with NME analysis. If fixed_thres is float,
              it skips the NME analysis part.
          maj_vote_spk_count (bool):
              If True, take a majority vote on all p-values in the given range to estimate the number of speakers.
              The majority voting may contribute to surpress overcounting of the speakers and improve speaker
              counting accuracy.
          parallelism (bool):
              If True, turn on parallelism based on torch.jit.script library.
          cuda (bool):
              Use cuda for Eigen decomposition if cuda=True.
          device (torch.device):
              Torch device variable
      """
      self.max_num_speakers: int = max_num_speakers
      self.max_rp_threshold: float = max_rp_threshold
      self.use_subsampling_for_nme: bool = use_subsampling_for_nme
      self.nme_mat_size: int = nme_mat_size
      self.sparse_search: bool = sparse_search
      self.sparse_search_volume: int = sparse_search_volume
      self.min_p_value = torch.tensor(2)
      self.fixed_thres: float = fixed_thres
      self.eps = 1e-10
      self.max_N = torch.tensor(0)
      self.mat: torch.Tensor = mat
      self.p_value_list: torch.Tensor = self.min_p_value.unsqueeze(0)
      self.cuda: bool = cuda
      self.device: torch.device = device
      self.maj_vote_spk_count: bool = maj_vote_spk_count
      self.parallelism: bool = parallelism
  
imports: from typing import Dict, List, Tuple
  import torch
  from torch.linalg import eigh, eigvalsh
label_desc: Use image node_id 1 to create a new NMESC object  with example: obj = NMESC(mat, max_num_speakers, max_rp_threshold, sparse_search, sparse_search_volume, nme_mat_size, use_subsampling_for_nme, fixed_thres, maj_vote_spk_count, parallelism, cuda, device)