Exact confidence intervals for multinomial distributions via Neyman construction
Project description
grecov
Efficient Neyman construction for multinomial distributions with the Greedy Coverage algorithm.
Installation
For the IPOPT optimizer (recommended for best results):
pip install grecov[ipopt]
Development
Install in editable mode with test dependencies:
pip install -e ".[test]"
After modifying C++ code in src/ext/, rebuild with:
pip install -e .
Install pre-commit hooks to run ruff and clang-format on every commit:
pip install pre-commit
pre-commit install
Usage
from grecov import multinomial_ci
result = multinomial_ci(
counts=[10, 10, 20, 60],
values=[1, 2, 3, 4],
alpha=0.05,
)
print(f"95% CI: [{result['lower']:.4f}, {result['upper']:.4f}]")
R (via reticulate)
An R package is available in r-package/ that wraps grecov using
reticulate.
Installation
# Install reticulate if needed
install.packages("reticulate")
# Install the R package from the local directory
install.packages("r-package", repos = NULL, type = "source")
# Install the grecov Python package into reticulate's Python environment
grecov::install_grecov()
Usage
library(grecov)
result <- multinomial_ci(
counts = c(10, 10, 20, 60),
values = c(1, 2, 3, 4),
alpha = 0.05
)
cat(sprintf("95%% CI: [%.4f, %.4f]\n", result$lower, result$upper))
The low-level BFS function is also available:
bfs <- grecov_bfs(
p = c(0.1, 0.1, 0.2, 0.6),
v = c(1, 2, 3, 4),
s_obs = 330,
n = 100L
)
cat(sprintf("P(S <= 330) = %.6f\n", bfs$prob_left))
Options
All parameters from the Python API are available:
result <- multinomial_ci(
counts = c(10, 10, 20, 60),
values = c(1, 2, 3, 4),
alpha = 0.10,
method = "greedy",
verbose = 1L
)
Pyodide (browser / WebAssembly)
grecov compiles to WebAssembly and runs in the browser via Pyodide.
The C++ BFS extension compiles unchanged; cyipopt is not included (the scipy
trust-constr fallback is used automatically).
Using in a webpage
The pyodide wheel is attached to each GitHub Release. The following snippet automatically fetches the latest one:
<script src="https://cdn.jsdelivr.net/pyodide/v0.27.7/full/pyodide.js"></script>
<script type="module">
const pyodide = await loadPyodide();
await pyodide.loadPackage(["micropip", "numpy", "scipy"]);
// Find and install the latest pyodide wheel from GitHub Releases
const res = await fetch("https://api.github.com/repos/louisabraham/grecov/releases/latest");
const release = await res.json();
const wheel = release.assets.find(a => a.name.includes("pyodide"));
await pyodide.runPythonAsync(`
import micropip
await micropip.install("${wheel.browser_download_url}")
`);
pyodide.runPython(`
from grecov import multinomial_ci
result = multinomial_ci(
counts=[10, 10, 20, 60],
values=[1, 2, 3, 4],
alpha=0.05,
)
print(f"95% CI: [{result['lower']:.4f}, {result['upper']:.4f}]")
`);
</script>
Building the Pyodide wheel locally
pip install pyodide-build
pyodide xbuildenv install
pyodide build
This requires the matching Emscripten version (pyodide config get emscripten_version).
Install it via emsdk and source emsdk_env.sh
before running pyodide build. The wheel is written to dist/.
Performance
Pyodide/wasm performance is on par with native CPython (~1.0x). Run the comparison benchmark with:
python profiling/bench_pyodide.py
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file grecov-0.2.3-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.
File metadata
- Download URL: grecov-0.2.3-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
- Upload date:
- Size: 66.0 kB
- Tags: CPython 3.12, manylinux: glibc 2.24+ x86-64, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
37efc7f12d18431e42f8dc621d105cf72fffb7d98035037857815510c2673432
|
|
| MD5 |
247da50cfa43da4c1fa2e107d3b3c388
|
|
| BLAKE2b-256 |
de8df7f99eb30bf9f78b3ef9f5b488b693ee808632259656259b13e5a22e1788
|
Provenance
The following attestation bundles were made for grecov-0.2.3-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl:
Publisher:
build.yml on louisabraham/grecov
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
grecov-0.2.3-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl -
Subject digest:
37efc7f12d18431e42f8dc621d105cf72fffb7d98035037857815510c2673432 - Sigstore transparency entry: 1101888198
- Sigstore integration time:
-
Permalink:
louisabraham/grecov@2d0ca89f37070f66ba52054c2b5d36f55ad09606 -
Branch / Tag:
refs/heads/pyodide-wheels - Owner: https://github.com/louisabraham
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build.yml@2d0ca89f37070f66ba52054c2b5d36f55ad09606 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file grecov-0.2.3-cp312-cp312-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl.
File metadata
- Download URL: grecov-0.2.3-cp312-cp312-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl
- Upload date:
- Size: 63.4 kB
- Tags: CPython 3.12, manylinux: glibc 2.24+ ARM64, manylinux: glibc 2.28+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b6f5d20a46cd605623de45f99a6e95bffd3f82c203a0b128653e1966339690a7
|
|
| MD5 |
103d389a03bae587c090022bdbdd9c92
|
|
| BLAKE2b-256 |
92980dca4177a3b87bcb23eb3e925277dd86dc201bfb873fe1076cf1384453ef
|
Provenance
The following attestation bundles were made for grecov-0.2.3-cp312-cp312-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl:
Publisher:
build.yml on louisabraham/grecov
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
grecov-0.2.3-cp312-cp312-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl -
Subject digest:
b6f5d20a46cd605623de45f99a6e95bffd3f82c203a0b128653e1966339690a7 - Sigstore transparency entry: 1101888203
- Sigstore integration time:
-
Permalink:
louisabraham/grecov@2d0ca89f37070f66ba52054c2b5d36f55ad09606 -
Branch / Tag:
refs/heads/pyodide-wheels - Owner: https://github.com/louisabraham
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build.yml@2d0ca89f37070f66ba52054c2b5d36f55ad09606 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file grecov-0.2.3-cp312-cp312-macosx_11_0_arm64.whl.
File metadata
- Download URL: grecov-0.2.3-cp312-cp312-macosx_11_0_arm64.whl
- Upload date:
- Size: 67.8 kB
- Tags: CPython 3.12, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1d0e8c13ccd1d8c87f0f587382be3444bed743f22b76020bda34f560406eacc7
|
|
| MD5 |
e4110be2af52e487ab11257a8d34a2f0
|
|
| BLAKE2b-256 |
ab7dd32aea6f66d28b722016bd0ad02fb870b6918d5590d4085a3c872304dbc3
|
Provenance
The following attestation bundles were made for grecov-0.2.3-cp312-cp312-macosx_11_0_arm64.whl:
Publisher:
build.yml on louisabraham/grecov
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
grecov-0.2.3-cp312-cp312-macosx_11_0_arm64.whl -
Subject digest:
1d0e8c13ccd1d8c87f0f587382be3444bed743f22b76020bda34f560406eacc7 - Sigstore transparency entry: 1101888205
- Sigstore integration time:
-
Permalink:
louisabraham/grecov@2d0ca89f37070f66ba52054c2b5d36f55ad09606 -
Branch / Tag:
refs/heads/pyodide-wheels - Owner: https://github.com/louisabraham
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build.yml@2d0ca89f37070f66ba52054c2b5d36f55ad09606 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file grecov-0.2.3-cp312-cp312-macosx_10_13_x86_64.whl.
File metadata
- Download URL: grecov-0.2.3-cp312-cp312-macosx_10_13_x86_64.whl
- Upload date:
- Size: 76.6 kB
- Tags: CPython 3.12, macOS 10.13+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
47ceb1f0a0b99ae620528c492416add9f8e1fdbebe296b3f8beba152b71a10c0
|
|
| MD5 |
72ece65e7f5fc2b1e24490404a0fceff
|
|
| BLAKE2b-256 |
284b17055822587a984a1b8bc61da24d8dd5180dda554113f5450572a55afa0b
|
Provenance
The following attestation bundles were made for grecov-0.2.3-cp312-cp312-macosx_10_13_x86_64.whl:
Publisher:
build.yml on louisabraham/grecov
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
grecov-0.2.3-cp312-cp312-macosx_10_13_x86_64.whl -
Subject digest:
47ceb1f0a0b99ae620528c492416add9f8e1fdbebe296b3f8beba152b71a10c0 - Sigstore transparency entry: 1101888216
- Sigstore integration time:
-
Permalink:
louisabraham/grecov@2d0ca89f37070f66ba52054c2b5d36f55ad09606 -
Branch / Tag:
refs/heads/pyodide-wheels - Owner: https://github.com/louisabraham
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build.yml@2d0ca89f37070f66ba52054c2b5d36f55ad09606 -
Trigger Event:
workflow_dispatch
-
Statement type: