Skip to main content

Confidence Intervals for Error Rates in :jigsaw: Matching Tasks

Paper Apache-2.0

This repository hosts the cimat (Confidence Intervals for MAtching Tasks) package, designed to create confidence intervals for performance metrics in 1:1 matching tasks like face and speaker verification.

With cimat, you can generate confidence intervals ($C_{\alpha}$) with a confidence level of $1-\alpha$ for metrics ($\theta^*$) such as:

  • False Positive Rate (FPR, aka FMR or FAR) and False Negative Rate (FNR, aka FNMR or FRR) estimates
  • ROC coordinate estimates such as FNR@FPR (aka FNMR@FMR or FRR@FAR)

such that $\mathbb{P}(\theta^*\in C_{\alpha})\geq 1-\alpha$. Check out our paper for a description of the methods.

:rocket: Getting started

In order to intall the cimat package, run

pip install cimat

or

pip install git+https://github.com/awslabs/cis-matching-tasks.git

for the latest version of the package.

Test your setup using this example that derives confidence intervals for FNMR and FMR obtained by binarizing the similarity scores at a given threshold:

import json
from cimat import MTData, UncertaintyEstimator

# Load embeddings from JSON file into a dictionary structure
df = json.load(open('data/embeddings.json', 'r'))  # Example structure: dictionary[id][image] = embedding
mt = MTData(df)
mt.generate_similarity_scores()  # Generate cosine similarity scores between images

# Set a threshold for determining matches versus non-matches
threshold = 0.9
# Instantiate the class to estimate error rates using similarity scores
# Example structure: dictionary[id1][id2] = [score between image from id1 and id2]
uq = UncertaintyEstimator(scores=mt.similarity_scores) 
# Compute False Non-Match Rate (FNMR, aka FNR) and False Match Rate (FMR, aka FPR) based on the threshold
fnr, fpr, _ = uq.compute_binerror_metrics(threshold)
fnr, fpr

## Calculate 95% Confidence Intervals (CI) for FNMR and FMR using Wilson's method
# with a plug-in estimator of the variance
var_fnr, var_fpr = uq.compute_variance(threshold=threshold, estimator="plugin")
ci_fnr, ci_fpr = uq.get_binerror_ci(threshold=threshold, var_fnr=var_fnr, var_fpr=var_fpr, alpha=0.05)
ci_fnr, ci_fpr

# with a double-or-nothing bootstrap estimator of the variance
uq.run_bootstrap(B=1000)  # runs the bootstrap
var_fnr_boot, var_fpr_boot = uq.compute_variance(threshold=threshold, estimator="boot")
ci_fnr_boot, ci_fpr_boot = uq.get_binerror_ci(threshold=threshold, var_fnr=var_fnr_boot, var_fpr=var_fpr_boot, alpha=0.05)
ci_fnr_boot, ci_fpr_boot

To generate the intervals without bothering about variance estimation, use

uq.get_binerror_ci(threshold = threshold, alpha = 0.05)

Under the hood, this function computes the variance with the plug-in estimator.

To obtain pointwise confidence intervals for the ROC with the double-or-nothing bootstrap, use

ci_tpr_at_fnr, ci_auc = uq.get_roc_ci(target_fpr=[0.01, 0.1], alpha = 0.05)
ci_tpr_at_fnr, ci_auc

See the code in examples/morph.ipynb for a more detailed example on how to use the package. In case of large datasets, the computations of the uncertainty may be burdensome. Luckily, the computational speed of the functions in this package can be substantially improved. Contact me if you are interested in this.

We have moved all the code related to the experiments in the paper to another branch named paper.

:books: Citation

To cite our paper/code/package, use

@article{fogliato2023confidence,
  title={Confidence Intervals for Error Rates in Matching Tasks: Critical Statistical Analysis and Recommendations},
  author={Fogliato, Riccardo and Patil, Pratik and Perona, Pietro},
  journal={arXiv preprint arXiv:2306.01198},
  year={2023}
}

Security

See CONTRIBUTING for more information.

License

This project is licensed under the Apache-2.0 License.

Release files for cimat 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cimat 0.1.2
File Size Uploaded
cimat-0.1.2.tar.gz 9.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for cimat 0.1.2
File Interpreter ABI Platform
cimat-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 19.1 kB

Release files / cimat-0.1.2.tar.gz

Download URL cimat-0.1.2.tar.gz
Size 9.0 kB
Tags Source
SHA-256 checksum
How to use checksums
394362c7125933da13ae1e314173e9c989c5ba7fe3d42bb7e4f26f56739e2340
BLAKE2b-256 checksum
How to use checksums
845d937c2ec3072c2e029b2d7899b7d9d53770133b24622930a54c5ca2ac6365
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.2 CPython/3.12.0 Linux/5.10.186-179.751.amzn2.x86_64

Release files / cimat-0.1.2-py3-none-any.whl

Download URL cimat-0.1.2-py3-none-any.whl
Size 10.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
22e3b4cddaca022179f948ea1a26fe7a2efb280559b3e9afbc2da6c231a2fdeb
BLAKE2b-256 checksum
How to use checksums
9bf9cba9096bf57f3de1a77d781dbcf47155d28fdb79a0cb2f2b4bd412f45c65
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.2 CPython/3.12.0 Linux/5.10.186-179.751.amzn2.x86_64

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page