lir.metrics package

class lir.metrics.MetricType(*args, **kwargs)[source]

Bases: Protocol

Type definition for metric calculations.

lir.metrics.auc(data: LLRData) → float[source]

Calculate the Area Under the Curve (AUC) of the ROC curve.

Parameters:

data (LLRData) – LLRs and their metadata, wrapped in an LLRData object.

Returns:

The area under the ROC curve (AUC score).

Return type:

float

lir.metrics.cllr(llr_data: LLRData, weights: tuple[float, float] = (1, 1)) → float[source]

Calculate a log likelihood ratio cost (C_llr) for a series of log likelihood ratios.

Nico Brümmer and Johan du Preez, Application-independent evaluation of speaker detection, In: Computer Speech and Language 20(2-3), 2006.

Parameters:
  • llr_data (LLRData) – LLRs and their metadata, wrapped in an LLRData object.

  • weights (tuple[float, float], optional) – The relative weights of the classes.

Returns:

CLLR, the log likelihood ratio cost.

Return type:

float

lir.metrics.cllr_cal(llr_data: LLRData, weights: tuple[float, float] = (1, 1)) → float[source]

Calculate the difference between the C_llr before and after isotonic calibration.

Parameters:
  • llr_data (LLRData) – LLRs and their metadata, wrapped in an LLRData object.

  • weights (tuple[float, float], optional) – The relative weights of the classes.

Returns:

CLLR_cal, the difference after isotonic calibration.

Return type:

float

lir.metrics.cllr_min(llr_data: LLRData, weights: tuple[float, float] = (1, 1)) → float[source]

Estimate the discriminative power from a collection of log likelihood ratios.

Parameters:
  • llr_data (LLRData) – LLRs and their metadata, wrapped in an LLRData object.

  • weights (tuple[float, float], optional) – The relative weights of the classes.

Returns:

CLLR_min, a measure of discrimination.

Return type:

float

lir.metrics.equal_error_rate(data: LLRData) → float[source]

Calculate the Equal Error Rate (EER) from the ROC curve.

The EER is the operating point where the True Positive Rate (TPR) equals the False Negative Rate (FNR).

Parameters:

data (LLRData) – LLRs and their metadata, wrapped in an LLRData object.

Returns:

The equal error rate.

Return type:

float

lir.metrics.llr_lower_bound(llrs: LLRData) → float | None[source]

Provide corresponding lower bound for provided LLR data.

When an LLRData object contains a lower bound, return it. If not, return None.

Parameters:

llrs (LLRData) – LLRs and their metadata, wrapped in an LLRData object.

Returns:

The LLR lower bound, or None.

Return type:

float | None

lir.metrics.llr_upper_bound(llrs: LLRData) → float | None[source]

Provide corresponding upper bound for provided LLR data.

When an LLRData object contains an upper bound, return it. If not, return None.

Parameters:

llrs (LLRData) – LLRs and their metadata, wrapped in an LLRData object.

Returns:

The LLR upper bound, or None.

Return type:

float | None

Submodules

lir.metrics.overestimation module

lir.metrics.overestimation.llr_overestimation(llrs: ndarray, y: ndarray, **kwargs: Any) → float[source]

Calculate the mean absolute value of the LLR-overestimation.

Parameters:
  • llrs (np.ndarray) – Array of log-likelihood ratios.

  • y (np.ndarray) – Array of labels (1 for H1 and 0 for H2).

  • **kwargs (Any) – Additional keyword arguments forwarded to calc_llr_overestimation.

Returns:

Mean absolute value of the overestimation grid, or np.nan when unavailable.

Return type:

float

lir.metrics.statistics module

lir.metrics.statistics.count(llr_data: LLRData) → float[source]

Count the number of instances or pairs of instances.

Parameters:

llr_data (LLRData) – LLRs and their metadata, wrapped in an LLRData object.

Returns:

The number of instances or pairs of instances.

Return type:

float

lir.metrics.statistics.count_h1(llr_data: LLRData) → float[source]

Count the number of instances or pairs of instances labeled as Hypothesis 1 (hypothesis label 1).

Parameters:

llr_data (LLRData) – LLRs and their metadata, wrapped in an LLRData object.

Returns:

The number of instances or pairs of instances.

Return type:

float

lir.metrics.statistics.count_h2(llr_data: LLRData) → float[source]

Count the number of instances or pairs of instances labeled as Hypothesis 2 (hypothesis label 0).

Parameters:

llr_data (LLRData) – LLRs and their metadata, wrapped in an LLRData object.

Returns:

The number of instances or pairs of instances.

Return type:

float

lir.metrics.statistics.count_sources(llr_data: LLRData) → float[source]

Count the number of distinct sources to which the instances (or pairs of instances) belong.

Parameters:

llr_data (LLRData) – LLRs and their metadata, wrapped in an LLRData object.

Returns:

The number of distinct sources, or np.nan when source identifiers are not available.

Return type:

float

lir.metrics.statistics.mean_llr_h1(llr_data: LLRData) → floating[Any][source]

Calculate the average LLR of instances (or instance pairs) labeled as Hypothesis 1 (hypothesis label 1).

Parameters:

llr_data (LLRData) – LLRs and their metadata, wrapped in an LLRData object.

Returns:

The average LLR.

Return type:

float

lir.metrics.statistics.mean_llr_h2(llr_data: LLRData) → floating[Any][source]

Calculate the average LLR of instances (or instance pairs) labeled as Hypothesis 2 (hypothesis label 0).

Parameters:

llr_data (LLRData) – LLRs and their metadata, wrapped in an LLRData object.

Returns:

The average LLR.

Return type:

float