Skip to main content

PyPI Python Docs License

lf2i: Likelihood-Free Frequentist-Bayes Inference

Getting Started

What is LF2I?

lf2i is a Python package for likelihood-free inference; that is, inference on the parameters $\boldsymbol{\theta}$ of a statistical model $F_{\boldsymbol{\theta}}$ in a setting where the likelihood $\mathcal{L}(\boldsymbol{\theta}; \mathcal{D}):=p(\mathcal{D}|\boldsymbol{\theta})$ cannot be evaluated but is implicitly encoded by a high-fidelity simulator for $F_{\boldsymbol{\theta}}$. In other words, one can simulate data in batches of size $n$, $\mathcal{D}=(X_1, \dots, X_n)$, for any given $\boldsymbol{\theta}$ in the parameter space.

What does LF2I do?

lf2i constructs confidence regions for internal parameters with correct coverage across the whole parameter space, that is, sets $\mathcal{R}(\mathcal{D})$ satisfying $\mathbb{P}({\boldsymbol{\theta}} \in \mathcal{R}(\mathcal{D})) = 1 - \alpha\text{ } \text{ }\forall\theta\in\Theta$, where $(1 − \alpha) \in (0, 1)$ is a prespecified confidence level.
Coverage is guaranteed regardless of

  1. the prior distribution over the parameters of interest;
  2. the true value of the parameters of interest: the coverage guarantee holds point-wise over the parameter space (i.e., not only on average); and
  3. the size of the observed sample: the coverage guarantee holds even for finite sample sizes, including for the case of one observation, i.e. $n=1$.

Structure of LF2I

lf2i is based on the equivalence of confidence sets and hypothesis tests. It leverages supervised machine learning methods to efficiently execute the Neyman construction of confidence sets. The framework has three separate modules for estimating

  1. test statistics (such as ACORE, BFF, Waldo, etc...);
  2. critical values for a level $\alpha$ test; and
  3. empirical coverage

across the entire parameter space. See the figure below for a schematic diagram.

drawing

While 1. and 2. are used to construct the confidence sets, 3. is an independent diagnostic tool that can be used to check whether a given parameter region (such as, lf2i confidence sets, posterior credible regions, prediction sets, etc …) has the right conditional coverage. Because lf2i is modular, users can construct valid confidence sets using any test statistic of their choice.

Usage

lf2i offers a simple interface that allows you to get started quickly. The entry point is the LF2I class in the lf2i.inference module, which contains classes to wrap the different functionalities. The method inference merges steps 1. and 2. to return confidence sets with correct coverage. The method diagnostics performs step 3. as an independent check of empirical coverage of the constructed parameter regions.

from lf2i.inference import LF2I

inference = LF2I(test_statistic=..., prior=...)
confidence_sets = inference.inference(...) # Steps 1 and 2
diagnostics = inference.diagnostics(...) # Step 3

Check the website for the full documentation.

Install

The package available on PyPI at this link. It can be installed using pip:

pip install lf2i

The diagnostics module leverages smoothing splines implemented in R, which is assumed to be installed along with the mgcv package.

Feedback and Contributions

We strongly encourage users to leave feedback and report bugs either by using the Issues tab, or by contacting us directly. The current maintainer(s) can be reached here.

If you want to contribute, feel free to open an issue and/or a pull request.

References

LF2I is based on the following research articles:
- Confidence sets and hypothesis testing in a likelihood-free inference setting (ICML 2020)
- Simulation-Based Inference with Waldo: Confidence Regions by Leveraging Prediction Algorithms and Posterior Estimators for Inverse Problems (AISTATS 2023)
- Likelihood-free frequentist inference: bridging classical statistics and machine learning for reliable simulator-based inference (Electron. J. Statist., 2025)
- Trustworthy scientific inference with generative models (Mach. Learn.: Sci. Technol., 2026)

Metadata

Release files for lf2i 0.4.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 lf2i 0.4.2
File Size Uploaded Provenance Actions
lf2i-0.4.2.tar.gz 92.6 kB With provenance Details for lf2i-0.4.2.tar.gz

Built distribution (wheel)

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

Total release size: 203.1 kB

Release files / lf2i-0.4.2.tar.gz

Download URL lf2i-0.4.2.tar.gz
Size 92.6 kB
Tags Source
SHA-256 checksum
How to use checksums
200edb0e63895aab7eb906179370200a5618c59ebb968354545f202e444da78c
BLAKE2b-256 checksum
How to use checksums
7f65fab768b580489147caa104e32f816d0639279cc7d15c919b79ae34960ad5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 1, 2026.

Transparency log

Release files / lf2i-0.4.2-py3-none-any.whl

Download URL lf2i-0.4.2-py3-none-any.whl
Size 110.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
43335685ea25c92ffb6d42ea57c9a57f2bbc60f2300050067c27e103ccfa29a3
BLAKE2b-256 checksum
How to use checksums
e4aed2ec19dfdea7bf37be537239e241575d0b631db381d9ac936b05f5d642ec
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 1, 2026.

Transparency log

Security for lf2i 0.4.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for lf2i-0.4.2.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 1, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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