Skip to content

Latest commit

 

History

107 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ToFUL — Tool for Uncertainty Learning

Streamlit App Python 3.9+ License: MIT Documentation Status

An interactive web application and Python computation engine for computing statistical moments of probability distributions.

$$\mu_r(a) = E\left[(X - a)^r\right]$$

Compute raw moments, central moments, variance, skewness, kurtosis, and more for both discrete and continuous random variables — with rigorous numerical methods, convergence acceleration, and real-time validation.

🚀 Try it now — no installation needed
📖 Read the documentation


Features

Feature Details
Discrete RVs Finite and infinite support, with 5-method convergence cascade
Continuous RVs Domain-aware quadrature: Gauss-Laguerre, Gauss-Hermite, tanh-sinh
Exact results SymPy symbolic integration for distributions without conditionals
High precision mpmath arbitrary-precision mode above 12 decimal places
Parallel computation All moment orders computed concurrently via ThreadPoolExecutor
Smart input Auto-corrects ^, `
Live validation PMF sum and PDF integral checked before any moment is computed
5 result tabs Moments · Statistics · Distribution plot · Table (CSV) · Convergence

Quick Start

Online (recommended)

Visit toful1.streamlit.app — no installation needed.

Local installation

git clone https://github.com/pranava-ba/ToFUL.git
cd ToFUL
pip install -r requirements.txt
streamlit run app.py

All three files — app.py, core.py, and toful_parser.py — must be in the same directory.

Verify the installation

python -c "
import core, toful_parser, numpy as np

x, _, _ = core.parse_range_input('0,1,2,3,...')
vr = core.validate_drv_probabilities(
    '0.3*(0.7**x) if x>=0 else 0', x[:200], True
)
print('Valid:', vr.is_valid, '| Sum:', round(vr.integral_or_sum, 6))
"
# Valid: True | Sum: 1.0

Usage Examples

Discrete — Geometric Distribution

Field Value
Variable type Discrete (DRV)
Range 0,1,2,3,...
PMF 0.3 * (0.7 ** x) if x >= 0 else 0
Moment reference Origin (a = 0)
Max order 4

Expected output:

Moment Value Method
μ₁ 2.333333 term-magnitude
μ₂ 13.222222 term-magnitude
μ₃ 111.222222 term-magnitude
μ₄ 1247.296296 term-magnitude

Continuous — Exponential Distribution

Field Value
Variable type Continuous (CRV)
Lower bound 0
Upper bound inf
PDF 2 * exp(-2*x) if x >= 0 else 0

Expected output:

Moment Value Method
μ₁ 0.500000 gauss-laguerre+quad
μ₂ 0.500000 gauss-laguerre+quad
μ₃ 0.750000 gauss-laguerre+quad
μ₄ 1.500000 gauss-laguerre+quad

Continuous — Normal Distribution (exact)

Field Value
PDF exp(-(x**2)/2) / sqrt(2*pi)
Bounds -inf to inf

Expected output:

Moment Value Method
μ₁ 0.000000 sympy-exact
μ₂ 1.000000 sympy-exact
μ₃ 0.000000 sympy-exact
μ₄ 3.000000 sympy-exact

Input Syntax

The expression field accepts natural mathematical notation. Common auto-corrections applied by the parser:

You type Interpreted as
0.3 * 0.7^x 0.3 * 0.7**x
e^(-2*x) exp(-2*x)
2x 2*x
|x| abs(x)
ln(x) log(x)
√(x) sqrt(x)
x ≤ 1 x <= 1
λ lam

See the Input Syntax Guide for the complete reference.


Project Structure

ToFUL/
├── app.py              Streamlit frontend (UI, layout, plots)
├── core.py             Computation engine (moments, validation, convergence)
├── toful_parser.py     Input normalisation pipeline (two-pass)
├── requirements.txt    Runtime dependencies
└── docs/               Sphinx documentation source
    ├── conf.py
    ├── index.rst
    ├── getting-started/
    ├── user-guide/
    ├── examples/
    ├── theory/
    ├── api-reference/
    └── troubleshooting/

Numerical Methods

Discrete series convergence cascade

  1. Term magnitude — last 10 terms all below tolerance
  2. Wynn ε-algorithm — recursive epsilon-table extrapolation
  3. Aitken Δ² — three-point partial-sum extrapolation
  4. Cohen-Villegas-Zagier — optimal for alternating series
  5. Geometric ratio bound — tail estimate from asymptotic ratio

Continuous integration

Domain Method
[0, ∞) Gauss-Laguerre quadrature (64 nodes) + quad cross-check
(-∞, ∞) Gauss-Hermite quadrature (64 nodes) + quad cross-check
Finite [a, b] SciPy adaptive Gauss-Kronrod
Any, precision > 12dp mpmath tanh-sinh (arbitrary precision)
No conditionals SymPy symbolic integration (exact)

Dependencies

Package Purpose
streamlit Web UI framework
numpy Array operations, vectorised evaluation
scipy Adaptive quadrature, Gauss nodes, special functions
sympy Symbolic integration (optional but recommended)
mpmath Arbitrary-precision arithmetic (optional)
plotly Interactive distribution and moment plots
pandas Results table and CSV export

Documentation

Full documentation is hosted on ReadTheDocs: toful-rtd.readthedocs.io

To build locally:

cd docs
pip install sphinx sphinx-rtd-theme
make html
# open docs/_build/html/index.html

Contributing

Contributions are welcome. See CONTRIBUTING for the development setup, code style guide, and pull request process.

When reporting a numerical bug, include the exact Range and PMF/PDF strings, the moment order, and the analytical expected value.


License

MIT License — see LICENSE for details.


Built with Streamlit · NumPy · SciPy · SymPy · mpmath · Plotly

About

Tool for Uncertainty — parses statistical moments from text and LLM output.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages