L-moments based uncertainty quantification from scarce samples including extremes
Project description
L-moments UQ — Python port
A Python port of the MATLAB UQ 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.
No MATLAB installation was available while writing this port, so it was
not validated by diffing against MATLAB output. Instead, every
parameter-estimation formula and distribution-parameterization/sign
convention was validated by generating large synthetic samples from known
scipy.stats parameters and checking that this code recovers them — see
tests/test_lmoments.py (26 tests, all passing).
If you have MATLAB available, cross-checking a few outputs against the
original .m files would be a good next step.
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_distreturns 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-kcandidates; the MATLAB version'sKargument silently breaks forK>1becauseIdentify_dist.mnever actually returns more than one candidate.- The Gamma distribution's location shift is applied consistently in both
pdf_landcdf_lin both implementations (MATLAB'sCDF_l.mhistorically omitted it; fixed as of the SoftwareX/JSS submission preparation). kl_div(p, q)returnsinfwhenphas mass in a bin whereqhas none (the mathematically correct value); MATLAB'sKLDiv.mdrops such bins and can return a finite — even negative — divergence there. This cannot affectjs_div, whose mixture term is positive whereverpis, andjs_divwas verified to machine precision againstscipy.spatial.distance.jensenshannon(see the divergence tests).weibulis supported inparameter_estimation/pdf_l/cdf_l/random_lfor completeness, but — matching the MATLAB version — is not one of the familiesidentify_distwill 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_distcan pick either the special-case family or its generalizing family. This is a property of the diagram itself, not a bug (seetests/test_lmoments.pyfor how this is handled in testing).
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
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 lmoments_uq-1.0.0.tar.gz.
File metadata
- Download URL: lmoments_uq-1.0.0.tar.gz
- Upload date:
- Size: 17.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a061a11728da47802222ca56043f8ed63a93c521a14aa22488e38a4b50f234d2
|
|
| MD5 |
ee5ff694da9ab16804408da34772e0c7
|
|
| BLAKE2b-256 |
ee55364aac20399bc42aaae3ec03a6bde848e603eeb0d63f2f074de05af0ddd5
|
File details
Details for the file lmoments_uq-1.0.0-py3-none-any.whl.
File metadata
- Download URL: lmoments_uq-1.0.0-py3-none-any.whl
- Upload date:
- Size: 11.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
17a709e58a05e0750d1fb81839eee32e6f7beb923f67649f8af1d7fac052ee29
|
|
| MD5 |
8f7c10e9297ea0530a18692c8657e58b
|
|
| BLAKE2b-256 |
1ad02c757c463215664210b3612f67c54677575db073798e730b2092c9bb767a
|