Skip to main content

L-moments based uncertainty quantification from scarce samples including extremes

Project description

L-moments UQ — Python port

A Python port of the L-UQ MATLAB toolbox one directory up: distribution-independent uncertainty quantification from scarce samples, including data with extremes, using L-moments. Same method, same 9 supported distribution families, plus an interactive Streamlit UI.

Validation. Every parameter-estimation formula and distribution-parameterization/sign convention is validated against known scipy.stats ground truth — see tests/test_lmoments.py (30 tests). In addition, this port and the MATLAB implementation have been verified equivalent: on fixed reference samples, MATLAB's lmom, Parameter_estimation, and CDF_l reproduce this package's L-moments, parameter vectors, and fitted CDF values to within 1e-8 (run tests/octave_verify.m under GNU Octave, or the MATLAB suite tests/test_uq_matlab.m — both pass, the latter under MATLAB R2026a). On the same samples the package agrees with R's lmom to machine precision wherever the closed forms coincide.

Install

cd python
python3 -m venv .venv && source .venv/bin/activate
pip install -e ".[ui,dev]"

Run the tests

pytest tests/ -v

Run the illustrative example

python demo_example.py --no-show   # saves demo_example_output.png

Run the interactive UI

streamlit run app.py

Lets you paste in a sample (or generate a synthetic scarce+extreme one), see its L-moments and the ranked distribution-family match, pick a family to fit, and view the PDF/CDF fit against the sample compared with a conventional-moment (MLE) fit of the same family, plus Jensen-Shannon divergence numbers quantifying the difference.

API

from lmoments import identify_dist, parameter_estimation, pdf_l, cdf_l, random_l, js_div

result = identify_dist(x)              # {'best', 'ranking', 'L_sample'}
params = parameter_estimation(x, result['best'], *result['L_sample'])
pdf_vals = pdf_l(xgrid, result['best'], params)

Differences from the MATLAB version

  • identify_dist returns the full ranked distance to all 9 candidate families (result['ranking']), not just the single closest match — a strict addition, useful for the UI's ranking table.
  • parameter_identify(x, k) genuinely fits the top-k candidates; the MATLAB version's K argument silently breaks for K>1 because Identify_dist.m never actually returns more than one candidate.
  • The Gamma distribution's location shift is applied consistently in both pdf_l and cdf_l in both implementations (MATLAB's CDF_l.m historically omitted it; fixed as of the SoftwareX/JSS submission preparation).
  • kl_div(p, q) returns inf when p has mass in a bin where q has none (the mathematically correct value); MATLAB's KLDiv.m drops such bins and can return a finite — even negative — divergence there. This cannot affect js_div, whose mixture term is positive wherever p is, and js_div was verified to machine precision against scipy.spatial.distance.jensenshannon (see the divergence tests).
  • weibul is supported in parameter_estimation/pdf_l/cdf_l/random_l for completeness, but — matching the MATLAB version — is not one of the families identify_dist will pick automatically.

Known limitations (inherited from the method/toolbox)

  • Weibull is not offered for automatic identification (see above).
  • Gumbel is the k=0 special case of the GEV curve, and Uniform is the k=1 boundary case of the GP curve, on the L-moment ratio diagram; for samples near those special cases, identify_dist can pick either the special-case family or its generalizing family. This is a property of the diagram itself, not a bug (see tests/test_lmoments.py for how this is handled in testing).

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lmoments_uq-1.0.1.tar.gz (17.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

lmoments_uq-1.0.1-py3-none-any.whl (12.0 kB view details)

Uploaded Python 3

File details

Details for the file lmoments_uq-1.0.1.tar.gz.

File metadata

  • Download URL: lmoments_uq-1.0.1.tar.gz
  • Upload date:
  • Size: 17.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.5

File hashes

Hashes for lmoments_uq-1.0.1.tar.gz
Algorithm Hash digest
SHA256 c38df8bb9c36e113bf1ae1e396ec4344b7f6482266b554e172790d626e046bbc
MD5 edfc20ed8edaed46765698c47d6546e7
BLAKE2b-256 25c6366cf093924f51cc7a6e601100ae23b0af48809614d94bade91aeab09f40

See more details on using hashes here.

File details

Details for the file lmoments_uq-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: lmoments_uq-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 12.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.5

File hashes

Hashes for lmoments_uq-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 fa5999f8e2ba4ce861b5f23a63ca2d82b329e6209f8c2fe378f97c7be885baa7
MD5 775d712d014ca124a4115cb6a1bd7564
BLAKE2b-256 c85f44dfd7e3e838580b3cab84eb17962591c3941041519c346dc03bf2c0acb8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page