Skip to content

Commit

Permalink
Check for inaccurate EER values
Browse files Browse the repository at this point in the history
  • Loading branch information
vjoki committed Jan 31, 2021
1 parent cded1b0 commit 3f0ce01
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions snn/librispeech/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from typing import cast, Tuple, List
from typing import cast, Tuple, List, Dict, Optional
import warnings
import torch
import matplotlib.pyplot as plt
from pytorch_lightning.metrics.functional import roc
Expand All @@ -19,7 +20,8 @@ def minDCF(fpr: torch.Tensor, fnr: torch.Tensor, thresholds: torch.Tensor,


def equal_error_rate(fpr: torch.Tensor, fnr: torch.Tensor,
thresholds: torch.Tensor) -> Tuple[torch.Tensor, torch.Tensor, torch.Tensor]:
thresholds: torch.Tensor,
warn_threshold: float = 0.1) -> Tuple[torch.Tensor, torch.Tensor, torch.Tensor]:
# Index of the nearest intersection point.
idx = torch.argmin(torch.abs(fnr - fpr))

Expand All @@ -31,6 +33,10 @@ def equal_error_rate(fpr: torch.Tensor, fnr: torch.Tensor,
eer = 0.5 * (fpr[idx] + fnr[idx])
eer_threshold = thresholds[idx]

# Since we're averaging the EER, warn if the difference between FNR and FPR is too large.
if torch.abs(fpr[idx] - fnr[idx]) > warn_threshold:
warnings.warn('Inaccurate EER ({}), real EER is somewhere between or near [{}, {}].'.format(eer, fpr[idx], fnr[idx]))

# https://yangcha.github.io/EER-ROC/
# https://stackoverflow.com/questions/28339746/equal-error-rate-in-python
# Unfortunately this seems to fail frequently, incorrectly returning 0.0 and nan.
Expand Down

0 comments on commit 3f0ce01

Please sign in to comment.