code: def calculate_minDCF(
      y_label, y_score, p_target=0.01, c_miss=1, c_fa=1
  ):
      # https://github.com/kaldi-asr/kaldi/blob/master/egs/sre08/v1/sid/compute_min_dcf.py
      from sklearn.metrics import det_curve
  
      fpr, fnr, thresholds = det_curve(y_label, y_score, pos_label=1)
      min_c_det = float("inf")
      min_c_det_threshold = thresholds[0]
      for i in range(0, len(fpr)):
          # See Equation (2).  it is a weighted sum of false negative
          # and false positive errors.
          c_det = c_miss * fnr[i] * p_target + c_fa * fpr[i] * (
              1 - p_target
          )
          if c_det < min_c_det:
              min_c_det = c_det
              min_c_det_threshold = thresholds[i]
      # See Equations (3) and (4).  Now we normalize the cost.
      c_def = min(c_miss * p_target, c_fa * (1 - p_target))
      min_dcf = min_c_det / c_def
      return min_dcf, min_c_det_threshold
  
file_path: fairseq/examples/wav2vec/xlsr/scripts/eval_speaker_clf_task.py
imports: import numpy
  import sklearn
  from sklearn.metrics.pairwise import cosine_similarity
  from sklearn.preprocessing import StandardScaler
  from tqdm import tqdm
  import ipdb
  import logging
  import argparse
  from scipy.special import softmax
label_desc: Use image node_id 2 for calling a global function with example usage: calculate_minDCF(y_label, y_score, p_target, c_miss, c_fa) and returns: min_dcf,  min_c_det_threshold