Multi-Null Non-Parametric (MN²) Jensen–Shannon Distance (JSd) Hypothesis Test (MN-squared test)
mn-squared implements a multi-null non-parametric (MN²) Jensen–Shannon distance (JSd) based hypothesis
test for multinomial data. Given multiple candidate null distributions ($\mathbf{p}_{\ell}$) and observed
histograms ($\mathbf{h}$), it computes p-values using an exact or Monte-Carlo CDF backend and returns decisions that
control per-null significance levels and the overall family-wise error rate (FWER).
Status: Stable (v1.0) — public API is stable.
Installation
pip install mn-squared
Python ≥ 3.10, NumPy ≥ 1.24.
Quickstart
from mn_squared import MNSquaredTest
test = MNSquaredTest(evidence_size=100, prob_dim=3, cdf_method="mc_multinomial", mc_samples=50_000, seed=1234)
test.add_nulls([0.5, 0.3, 0.2], target_alpha=0.05)
test.add_nulls([0.4, 0.4, 0.2], target_alpha=0.01)
histograms = [[55, 22, 23], [40, 39, 21], [0, 3, 97]]
p_vals = test.infer_p_values(histograms)
decisions = test.infer_decisions(histograms)
print("p-values:", p_vals)
print("decisions:", decisions)
Concepts
- JSd statistic: divergence between empirical histogram ($\mathbf{h}/n$) and a reference ($\mathbf{p}$).
- Multi-null setting: several candidate vectors$. A query, $\mathbf{h}$, is either assigned to the “least-rejected” null or rejects all
- Backends:
exact: enumerate histograms in $\Delta'_{k,n}$ to compute the empirical CDF (ECDF); complexity $O(n^{k-1})$ for fixed $k$.mc_multinomial: draw $\mathbf{H}\sim \text{Multinomial}(n, \mathbf{p})$; ECDF converges by strong law of large numbers (SLLN).mc_normal: CLT proxy with $\mathcal{N}(n\mathbf{p}, n(\mathrm{diag}(\mathbf{p})-\mathbf{p}\mathbf{p}^\top))$.
- Error control: per-null $\alpha$; overall family-wise error rate (FWER); worst-case ($\beta$) at a query $\mathbf{q}$.
Public API
from mn_squared import MNSquaredTest, available_cdf_backends
Advanced imports:
mn_squared.cdf_backends # ExactCDFBackend, NormalMCCDFBackend, MultinomialMCCDFBackend
mn_squared.null_structures # IndexedHypotheses, NullHypothesis
Performance & numerics
- Exact backend is intended for small-to-moderate ((n,k)) due to combinatorial growth.
- Monte-Carlo backends scale well and are recommended for larger regimes.
- Validations use a small floating tolerance for simplex / integer-like checks.
- MC results are deterministic under a fixed
seed.
Project layout
mn_squared/
cdf_backends/ # CDF backends (exact, MC multinomial, MC normal)
null_structures/ # NullHypothesis & IndexedHypotheses containers
_validators.py # Shared validation helpers (implemented)
core.py # MNSquaredTest orchestrator (stub)
tests/ # Unit + property tests and backend contract tests
docs/ # Documentation (Sphinx)
experiments/ # Optional: benchmarking / comparison scripts (if present)
Versioning & license
- Versioning: SemVer.
- License: Apache-2.0.
Citation
There is an associated preprint describing the methodology being written up. In the meantime, if you use this project in research, please cite:
@software{mn_squared,
title = {mn-squared: Multi-Null Non-Parametric Jensen–Shannon Distance Hypothesis Test in Python},
author = {ALGES},
year = {2026},
url = {https://github.com/alges/mn-squared}
}
Metadata
Release files for mn-squared 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| mn_squared-1.0.0.tar.gz | 37.2 kB | With provenance | Details for mn_squared-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| mn_squared-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for mn_squared-1.0.0-py3-none-any.whl |
Total release size: 75.1 kB
Release files / mn_squared-1.0.0.tar.gz
| Download URL | mn_squared-1.0.0.tar.gz |
|---|---|
| Size | 37.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2b869b7d8415aba6cd14235b4d2d2ad84a4078521b46072a20b0670227127ce0
|
|
BLAKE2b-256 checksum How to use checksums |
8d5bdba3230d2f3af07d97efcfd927da20b408d1cf68fe3524d07a32bdc1f815
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
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 Jan 22, 2026.
Transparency logRelease files / mn_squared-1.0.0-py3-none-any.whl
| Download URL | mn_squared-1.0.0-py3-none-any.whl |
|---|---|
| Size | 37.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ed5941a499f22d42042a4e42a113d429712c95cbd6800e0f5721d842205a2cda
|
|
BLAKE2b-256 checksum How to use checksums |
8563cecb445ff89d960c222f366f0d2d79803b954a01c60ac0fc243f5ed7dd7e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
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 Jan 22, 2026.
Transparency logSecurity for mn-squared 1.0.0
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
All 2 files in this release have been uploaded with provenance metadata.
Attestation for mn_squared-1.0.0.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 Jan 22, 2026.
Transparency logA 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.