fitcdf 0.5.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. fitcdf-0.5.0/MANIFEST.in +22 -0
  2. fitcdf-0.5.0/PKG-INFO +540 -0
  3. fitcdf-0.5.0/README.md +503 -0
  4. fitcdf-0.5.0/pyproject.toml +92 -0
  5. fitcdf-0.5.0/setup.cfg +4 -0
  6. fitcdf-0.5.0/src/fitcdf/__init__.py +70 -0
  7. fitcdf-0.5.0/src/fitcdf/acceleration.py +250 -0
  8. fitcdf-0.5.0/src/fitcdf/analysis.py +172 -0
  9. fitcdf-0.5.0/src/fitcdf/comparison.py +1122 -0
  10. fitcdf-0.5.0/src/fitcdf/data.py +200 -0
  11. fitcdf-0.5.0/src/fitcdf/diagnostics.py +624 -0
  12. fitcdf-0.5.0/src/fitcdf/distributions/__init__.py +131 -0
  13. fitcdf-0.5.0/src/fitcdf/distributions/base.py +845 -0
  14. fitcdf-0.5.0/src/fitcdf/distributions/continuous.py +2359 -0
  15. fitcdf-0.5.0/src/fitcdf/distributions/discrete.py +727 -0
  16. fitcdf-0.5.0/src/fitcdf/distributions/poisson_binomial.py +695 -0
  17. fitcdf-0.5.0/src/fitcdf/distributions/truncated_weibull.py +433 -0
  18. fitcdf-0.5.0/src/fitcdf/estimators.py +1860 -0
  19. fitcdf-0.5.0/src/fitcdf/exclusive_plots.py +556 -0
  20. fitcdf-0.5.0/src/fitcdf/fit_validation.py +253 -0
  21. fitcdf-0.5.0/src/fitcdf/inference.py +118 -0
  22. fitcdf-0.5.0/src/fitcdf/model_selection.py +223 -0
  23. fitcdf-0.5.0/src/fitcdf/observability.py +67 -0
  24. fitcdf-0.5.0/src/fitcdf/plotting.py +544 -0
  25. fitcdf-0.5.0/src/fitcdf/py.typed +0 -0
  26. fitcdf-0.5.0/src/fitcdf/ranking.py +52 -0
  27. fitcdf-0.5.0/src/fitcdf/reports.py +1773 -0
  28. fitcdf-0.5.0/src/fitcdf/semantics.py +585 -0
  29. fitcdf-0.5.0/src/fitcdf/uncertainty.py +65 -0
  30. fitcdf-0.5.0/src/fitcdf.egg-info/PKG-INFO +540 -0
  31. fitcdf-0.5.0/src/fitcdf.egg-info/SOURCES.txt +32 -0
  32. fitcdf-0.5.0/src/fitcdf.egg-info/dependency_links.txt +1 -0
  33. fitcdf-0.5.0/src/fitcdf.egg-info/requires.txt +19 -0
  34. fitcdf-0.5.0/src/fitcdf.egg-info/top_level.txt +1 -0
@@ -0,0 +1,22 @@
1
+ include pyproject.toml
2
+ include README.md
3
+ recursive-include src/fitcdf *.py
4
+ include src/fitcdf/py.typed
5
+
6
+ prune src/distribution_lab
7
+ prune dataset
8
+ prune scripts
9
+ prune tests
10
+ prune tests_fitcdf
11
+ prune specs
12
+ prune docs
13
+ prune research
14
+ prune examples
15
+ prune .specify
16
+ prune .github
17
+ prune .quality
18
+ prune logs
19
+ prune resultados
20
+ exclude .editorconfig
21
+ exclude .gitignore
22
+ global-exclude __pycache__ *.py[cod] *.dat *.xls *.xlsx *.zip *.pdf
fitcdf-0.5.0/PKG-INFO ADDED
@@ -0,0 +1,540 @@
1
+ Metadata-Version: 2.4
2
+ Name: fitcdf
3
+ Version: 0.5.0
4
+ Summary: Standalone Python library for domain-agnostic tabular analysis and probability distribution fitting
5
+ Author: fitcdf Contributors
6
+ Keywords: statistics,probability-distributions,goodness-of-fit,cdf,pdf,aic,bic,kolmogorov-smirnov
7
+ Classifier: Development Status :: 4 - Beta
8
+ Classifier: Intended Audience :: Science/Research
9
+ Classifier: Intended Audience :: Developers
10
+ Classifier: Operating System :: OS Independent
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Programming Language :: Python :: 3 :: Only
13
+ Classifier: Programming Language :: Python :: 3.11
14
+ Classifier: Programming Language :: Python :: 3.12
15
+ Classifier: Programming Language :: Python :: 3.13
16
+ Classifier: Topic :: Scientific/Engineering :: Mathematics
17
+ Classifier: Typing :: Typed
18
+ Requires-Python: >=3.11
19
+ Description-Content-Type: text/markdown
20
+ Requires-Dist: numpy<3,>=1.26.4
21
+ Requires-Dist: scipy==1.17.0
22
+ Requires-Dist: matplotlib<4,>=3.9
23
+ Requires-Dist: threadpoolctl<4,>=3.5
24
+ Provides-Extra: qualidade
25
+ Requires-Dist: pytest==9.2.0; extra == "qualidade"
26
+ Requires-Dist: coverage[toml]==7.17.0; extra == "qualidade"
27
+ Requires-Dist: ruff==0.17.3; extra == "qualidade"
28
+ Requires-Dist: mypy==2.4.0; extra == "qualidade"
29
+ Requires-Dist: build==1.6.1; extra == "qualidade"
30
+ Requires-Dist: twine==7.0.0; extra == "qualidade"
31
+ Requires-Dist: bandit==1.9.4; extra == "qualidade"
32
+ Requires-Dist: pip-audit==2.10.1; extra == "qualidade"
33
+ Provides-Extra: gpu
34
+ Requires-Dist: cupy-cuda12x<14,>=13.6; extra == "gpu"
35
+ Requires-Dist: nvidia-cuda-runtime-cu12<13,>=12.9; extra == "gpu"
36
+ Requires-Dist: nvidia-cuda-nvrtc-cu12<13,>=12.9; extra == "gpu"
37
+
38
+ # fitcdf
39
+
40
+ [![Version](https://img.shields.io/badge/version-0.5.0-0072B2.svg)](pyproject.toml)
41
+ [![Python](https://img.shields.io/badge/python-3.11%20%7C%203.12%20%7C%203.13-0072B2.svg)](pyproject.toml)
42
+ [![Catalog](https://img.shields.io/badge/catalog-56%20distributions-009E73.svg)](#supported-families-56-distributions)
43
+ [![Typing](https://img.shields.io/badge/typing-PEP%20561%20typed-56B4E9.svg)](src/fitcdf/py.typed)
44
+
45
+ **Python library for domain-agnostic tabular analysis and univariate probability distribution fitting.**
46
+
47
+ `fitcdf` fits continuous and discrete probability distributions to tabular columns or in-memory numeric samples, computes goodness-of-fit diagnostics, ranks candidates separately by data nature (`continuous` vs. `discrete`) and estimation method, and persists Markdown reports, JSON payloads, CSV tables, and high-resolution PNG diagnostic figures. Every distribution, estimator, diagnostic, and ranking rule is implemented directly in `fitcdf`'s self-contained statistical core.
48
+
49
+ ---
50
+
51
+ ## Contents
52
+
53
+ - [Installation](#installation)
54
+ - [Quickstart & Python API](#quickstart--python-api)
55
+ - [Generated Outputs Reference](#generated-outputs-reference)
56
+ - [Case Study 1: NIST Simulated Weibull (`RANDWEIB.DAT`)](#case-study-1-nist-simulated-weibull-randweibdat)
57
+ - [Case Study 2: NIST Simulated Lognormal (`LGN2.DAT`)](#case-study-2-nist-simulated-lognormal-lgn2dat)
58
+ - [Supported Families (56 Distributions)](#supported-families-56-distributions)
59
+ - [Estimation Methods & Diagnostics](#estimation-methods--diagnostics)
60
+ - [Scientific References](#scientific-references)
61
+
62
+ ---
63
+
64
+ ## Installation
65
+
66
+ Requires **Python 3.11+** with lightweight scientific dependencies (`numpy`, `scipy`, `matplotlib`, and `threadpoolctl`).
67
+
68
+ ```bash
69
+ pip install fitcdf
70
+ ```
71
+
72
+ Verify the installation:
73
+
74
+ ```bash
75
+ python -c "import fitcdf; print(fitcdf.__version__, fitcdf.catalog_snapshot()['total_families'])"
76
+ ```
77
+
78
+ ---
79
+
80
+ ## Quickstart & Python API
81
+
82
+ `fitcdf` works directly on your own CSV files, directories of CSV files, or in-memory numeric arrays:
83
+
84
+ - **Input path:** pass either a direct CSV path (`"path/to/data.csv"`) or a directory path (`"path/to/folder"`) with optional `file_name="data.csv"` when the folder contains multiple CSV files.
85
+ - **Target columns:** declare the numeric columns to evaluate explicitly via `columns=["col_a", "col_b"]`. Column names never trigger domain-specific assumptions, and missing or non-finite rows are never silently dropped.
86
+ - **Output directory:** pass `results_dir="path/to/output"` to choose where artifacts are saved. When `results_dir` is omitted (and `save_artifacts=True`, the default), `fitcdf` automatically creates `<cwd>/fit_results_<dataset_name>/` and writes each run into a unique timestamped subfolder so previous runs are never overwritten.
87
+ - **Parallelism:** protect script entry points with `if __name__ == "__main__":` whenever setting `workers > 1`.
88
+
89
+ ```python
90
+ from pathlib import Path
91
+ from fitcdf import (
92
+ analyze_dataset,
93
+ catalog_snapshot,
94
+ compare_distributions,
95
+ plot_distributions,
96
+ )
97
+
98
+
99
+ def main() -> None:
100
+ # 1. Inspect the 56-family distribution catalog
101
+ snapshot = catalog_snapshot()
102
+ print(
103
+ f"Catalog {snapshot['catalog_version']}: "
104
+ f"{snapshot['total_families']} families "
105
+ f"({snapshot['continuous_count']} continuous, {snapshot['discrete_count']} discrete)"
106
+ )
107
+
108
+ # 2. Analyze a CSV file or folder without results_dir
109
+ # Outputs are written automatically to ./fit_results_<dataset_name>/
110
+ default_report = analyze_dataset(
111
+ "path/to/measurements.csv", # or a folder path with file_name="measurements.csv"
112
+ columns=["duration_ms"],
113
+ families=["weibull_min", "lognorm", "gamma", "norm"],
114
+ data_type="continuous",
115
+ method="mle",
116
+ criterion="aic",
117
+ seed=20261028,
118
+ workers=1,
119
+ )
120
+ winner = default_report["columns"]["duration_ms"]["comparison"]["rankings"][0]["fits"][0]
121
+ print(f"Rank-1 model: {winner['family']} | AIC={winner['aic']:.4f}")
122
+ print(f"Saved under : {default_report['artifacts']['directory']}")
123
+
124
+ # 3. Analyze with a custom results_dir
125
+ custom_report = analyze_dataset(
126
+ "path/to/folder",
127
+ file_name="measurements.csv",
128
+ columns=["duration_ms"],
129
+ results_dir=Path("my_fit_outputs"),
130
+ families=["weibull_min", "lognorm", "gamma", "norm"],
131
+ data_type="continuous",
132
+ method="mle",
133
+ criterion="aic",
134
+ workers=1,
135
+ )
136
+ print(f"Custom output: {custom_report['artifacts']['directory']}")
137
+
138
+ # 4. Fit an in-memory sample and render selective comparison plots
139
+ sample_values = [0.42, 0.78, 1.15, 1.64, 2.09, 2.88, 3.74, 5.19, 6.41, 8.07]
140
+ comparison = compare_distributions(
141
+ sample_values,
142
+ families=["lognorm", "gamma", "norm"],
143
+ data_type="continuous",
144
+ method="mle",
145
+ criterion="aic",
146
+ workers=1,
147
+ )
148
+ plot_output = plot_distributions(
149
+ sample_values,
150
+ "in_memory_sample",
151
+ comparison,
152
+ comparison["attempts"],
153
+ results_dir=Path("my_fit_outputs"),
154
+ image_format="png",
155
+ )
156
+ print(f"Selective plots written to: {plot_output['directory']}")
157
+
158
+
159
+ if __name__ == "__main__":
160
+ main()
161
+ ```
162
+
163
+ For a complete runnable script that generates a documented `Normal(loc=10.0, scale=2.5)` demo sample when no input path is supplied—or analyzes your own CSV when `--input` and `--column` are passed—see [examples/use_library.py](examples/use_library.py).
164
+
165
+ ### Public API Overview
166
+
167
+ | Function | Purpose | Primary Arguments | Return Value |
168
+ | :--- | :--- | :--- | :--- |
169
+ | `analyze_dataset` | End-to-end CSV loading, fitting, ranking, and artifact persistence | `path`, `columns`, `file_name`, `results_dir`, `families`, `data_type`, `method`, `criterion` | Structured report dict and persisted output paths |
170
+ | `compare_distributions` | In-memory univariate fitting, diagnostics, and ranking | `observations`, `families`, `data_type`, `method`, `criterion`, `workers`, `gof_replicates` | Comparison dict (`attempts`, `rankings`, `configuration`) |
171
+ | `plot_distributions` | Selective multi-family PDF/PMF, CDF, and combined panel rendering | `observations`, `feature_name`, `comparison_or_type`, `attempts_or_families`, `results_dir` | Dict of paths (`pdf`, `cdf`, `pdf_cdf`, `parameters.md`, `plot.json`) |
172
+ | `catalog_snapshot` / `list_available_families` / `get_distribution` | Inspect catalog metadata, parameter semantics, and frozen evaluators | Optional `data_type` or family `identifier` | Catalog metadata dict, family specs, or distribution instance |
173
+ | `estimate_parameters` / `evaluate_model_adequacy` / `predict_quantiles` / `resample_parameter_uncertainty` | Direct closed-form inference, Kolmogorov distance, quantiles, and percentile bootstrap | `observations`, `family`, `criterion`, `probabilities`, `repetitions`, `seed` | `InferenceResult`, adequacy dict, quantile map, and 95% intervals |
174
+
175
+ ---
176
+
177
+ ## Generated Outputs Reference
178
+
179
+ Every call to `analyze_dataset(..., save_artifacts=True)` writes a self-contained, non-overwriting run directory:
180
+
181
+ ```text
182
+ fit_results_<dataset_name>/ # Default <cwd> destination (or custom results_dir)
183
+ └── 20261130T124530-a1b2c3d4e5f6/ # Unique UTC timestamp + run identifier
184
+ ├── manifest.json # Run-level metadata, input profile, and feature paths
185
+ └── <column_name>-<hash>/ # Isolated folder per analyzed column
186
+ ├── report.md # Technical Markdown report with rankings and plot links
187
+ ├── result.json # Machine-readable JSON payload with parameter metadata
188
+ ├── results.csv # Semicolon-delimited table across all fitted candidates
189
+ ├── density.png # Histogram / empirical PMF vs. top fitted curves + rug
190
+ ├── cumulative.png # Empirical CDF + 95% DKW band + KS marker + residual panel
191
+ ├── quantiles.png # Classical Q-Q plot and detrended Q-Q (worm) plot
192
+ ├── probabilities.png # Classical P-P plot (with DKW guide) and detrended P-P plot
193
+ ├── survival.png # Log-scale empirical vs. theoretical survival curve S(x)
194
+ ├── criteria.png # Criterion score (AIC/AICc/BIC) vs. KS and CvM distances
195
+ ├── series.png # Observation-order trajectory, moving average, and boxplot
196
+ ├── pdf.png # Standalone comparative PDF / PMF panel
197
+ ├── cdf.png # Standalone comparative CDF and residual panel
198
+ └── models/ # Isolated folders for the winner and close alternatives
199
+ └── <method>/ # mle, moments, quantiles, distance, or spacings
200
+ └── <data_type>/ # continuous or discrete
201
+ └── 01_<winner_family>/ # Rank-prefixed model directory
202
+ ├── pdf.png # Individual PDF / PMF plot for this model alone
203
+ ├── cdf.png # Individual CDF + max KS marker for this model alone
204
+ └── report.md # Parameter estimates, bounds, meanings, and selection record
205
+ ```
206
+
207
+ - **`manifest.json`**: Top-level index mapping each analyzed column to its output directory and recording dataset profiling details.
208
+ - **`report.md`**: Human-readable summary containing sample statistics, ranked candidates, parameter interpretations, and links to all diagnostic plots.
209
+ - **`result.json`**: Structured payload suitable for downstream pipelines, containing fitted parameters, bounds, convergence statuses, and goodness-of-fit diagnostics.
210
+ - **`results.csv`**: Semicolon-delimited (`;`) flat table with one row per candidate attempt, including criterion scores, $\Delta$, Akaike weights, log-likelihood, parameter counts, KS, CvM, AD, $\chi^2$, optimizer evaluations, and duration.
211
+ - **9 Feature-Level Diagnostic Plots**: Full-width comparative visuals (`density.png`, `cumulative.png`, `quantiles.png`, `probabilities.png`, `survival.png`, `criteria.png`, `series.png`, `pdf.png`, `cdf.png`) rendered at publication resolution with the colorblind-safe Okabe–Ito palette.
212
+ - **Individual Model Plots (`models/<method>/<data_type>/`)**: Dedicated single-model `pdf.png`, `cdf.png`, and `report.md` files for the rank-1 winner and any qualifying close alternatives.
213
+
214
+ ---
215
+
216
+ ## Case Study 1: NIST Simulated Weibull (`RANDWEIB.DAT`)
217
+
218
+ This example fits 10 continuous distributions via Maximum Likelihood Estimation (`mle`) to the public NIST/SEMATECH simulated Weibull sample (`RANDWEIB.DAT`, column `valor`, `n = 500`, generated from `Weibull(c = 2, loc = 0, scale = 1)`).
219
+
220
+ ### Runnable Code
221
+
222
+ ```python
223
+ from fitcdf import analyze_dataset
224
+
225
+ report = analyze_dataset(
226
+ "dataset/nist_weibull_simulada/dados.csv", # Replace with your own CSV path
227
+ columns=["valor"],
228
+ data_type="continuous",
229
+ families=[
230
+ "weibull_min",
231
+ "weibull_2p_left_trunc",
232
+ "gamma",
233
+ "lognorm",
234
+ "norm",
235
+ "expon",
236
+ "fatiguelife",
237
+ "burr12",
238
+ "fisk",
239
+ "rayleigh",
240
+ ],
241
+ method="mle",
242
+ criterion="aic",
243
+ seed=20261028,
244
+ workers=1,
245
+ )
246
+ ```
247
+
248
+ ### Sample Summary & Observed Ranking
249
+
250
+ | Column | `n` | Mean | Median | Std. Dev. | Min | Q1 | Q3 | Max |
251
+ | :--- | :---: | :---: | :---: | :---: | :---: | :---: | :---: | :---: |
252
+ | **`valor`** | `500` | `0.8991` | `0.8423` | `0.4487` | `0.005674` | `0.5749` | `1.1996` | `2.3209` |
253
+
254
+ | Rank | Family | AIC | $\Delta\text{AIC}$ | Akaike Weight | BIC | KS ($D$) | CvM ($W^2$) | Free Params | Estimated Parameters |
255
+ | :---: | :--- | :---: | :---: | :---: | :---: | :---: | :---: | :---: | :--- |
256
+ | **1** | **`rayleigh`** | **584.76** | **0.00** | **40.5%** | **588.97** | 0.0311 | 0.0874 | 1 | `loc=0.0`, `scale=0.7104` |
257
+ | 2 | `weibull_min` | 585.03 | 0.27 | 35.4% | 593.45 | **0.0234** | **0.0301** | 2 | `c=2.0962`, `loc=0.0`, `scale=1.0138` |
258
+ | 3 | `weibull_2p_left_trunc` | 587.01 | 2.25 | 13.2% | 599.65 | 0.0234 | 0.0301 | 3 | `c=2.0959`, `trunc_left=0.005674`, `scale=1.0138` |
259
+ | 4 | `burr12` | 587.38 | 2.62 | 10.9% | 600.02 | 0.0242 | 0.0321 | 3 | `c=2.1075`, `d=100.0`, `scale=8.9848` |
260
+ | 5 | `gamma` | 613.51 | 28.76 | <0.1% | 621.94 | 0.0514 | 0.3076 | 2 | `a=3.2757`, `loc=0.0`, `scale=0.2745` |
261
+ | 6 | `norm` | 620.45 | 35.69 | <0.1% | 628.87 | 0.0586 | 0.3543 | 2 | `loc=0.8991`, `scale=0.4482` |
262
+ | 7 | `fisk` | 662.01 | 77.26 | <0.1% | 670.44 | 0.0597 | 0.3809 | 2 | `c=2.9506`, `loc=0.0`, `scale=0.8146` |
263
+ | 8 | `lognorm` | 717.57 | 132.81 | <0.1% | 726.00 | 0.0810 | 1.2233 | 2 | `s=0.6449`, `loc=0.0`, `scale=0.7659` |
264
+ | 9 | `expon` | 895.60 | 310.84 | <0.1% | 899.81 | 0.2303 | 10.0066 | 1 | `loc=0.0`, `scale=0.8991` |
265
+ | 10 | `fatiguelife` | 907.96 | 323.21 | <0.1% | 916.39 | 0.1844 | 5.9224 | 2 | `c=0.8203`, `loc=0.0`, `scale=0.6598` |
266
+
267
+ > [!NOTE]
268
+ > **Why `rayleigh` and `weibull_min` tie closely:** The Rayleigh distribution is the exact $c = 2$ special case of the 2-parameter Weibull law with scale $\sigma = \lambda / \sqrt{2} \approx 0.7071$. Because `rayleigh` spends 1 free parameter instead of 2, it achieves the lowest AIC (`584.76`, closed-form MLE, `0` optimizer evaluations), while `weibull_min` recovers `c = 2.0962` and `scale = 1.0138` within $\Delta\text{AIC} = 0.27$ and achieves the lowest empirical KS (`0.0234`) and CvM (`0.0301`) distances. Together they hold `75.9%` of the candidate-set Akaike weight.
269
+
270
+ #### Rank-1 Parameter Summary (`models/mle/continuous/01_rayleigh/report.md`)
271
+
272
+ | Parameter | Estimate | Status | Search Bounds | Statistical Meaning |
273
+ | :--- | :---: | :---: | :---: | :--- |
274
+ | `loc` | `0` | fixed | `[0; 0]` | Lower support endpoint of the Rayleigh distribution. |
275
+ | `scale` | `0.7103543` | free | `[2.3151936e-06; 232.0868]` | Mode displacement above `loc`; positive dispersion parameter. |
276
+
277
+ #### Real `results.csv` Excerpt (Top 4 Rows)
278
+
279
+ ```csv
280
+ rank;distribution_name;family;data_type;method;status;eligible;criterion;score;delta;akaike_weight;log_likelihood;parameter_count;aic;aicc;bic;ks;cvm;ad;chi2;evaluations;duration_seconds;parameters;reason
281
+ 1;Rayleigh;rayleigh;continuous;mle;fitted;True;aic;584.7570277186096;0.0;0.4049762751371152;-291.3785138593048;1;584.7570277186096;584.7650598471237;588.9716358170318;0.031109701822733538;0.08743169138912257;0.5313783421218545;6.559999999999915;0;0.0021931009978288785;loc=0.0, scale=0.7103542983076149;Exact closed-form maximum likelihood solution.
282
+ 2;Weibull Minimum;weibull_min;continuous;mle;fitted;True;aic;585.0251501227347;0.2681224041250516;0.35416655024832133;-290.51257506136733;2;585.0251501227347;585.04929499195;593.4543663195791;0.02340824250555862;0.030112355367573698;0.19779221722586726;7.920000000000018;405;0.04097736600670032;c=2.0961920780987904, loc=0.0, scale=1.0138095496123853;Numerical convergence confirmed by the optimizer.
283
+ 3;2-Parameter Left-Truncated Weibull;weibull_2p_left_trunc;continuous;mle;fitted;True;aic;587.0061115081867;2.249083789577071;0.1315367908341654;-290.50305575409334;3;587.0061115081867;587.0544986049608;599.6499358034532;0.02343063532686529;0.030122325421878135;1.5577151409848398;7.920000000000035;669;0.04609012899163645;c=2.095911618449196, trunc_left=0.005674428, loc=0.0, scale=1.013773666148315;Numerical convergence confirmed by the optimizer.
284
+ 4;Burr Type XII;burr12;continuous;mle;fitted;True;aic;587.3761232986986;2.619095580089038;0.10932014587429213;-290.6880616493493;3;587.3761232986986;587.4245103954728;600.0199475939652;0.02415898959163154;0.03213892841615452;0.21297891374877054;7.919999999999765;1458;0.14107553799112793;c=2.107455896579404, d=100.0, loc=0.0, scale=8.984801503325652;Numerical convergence confirmed by the optimizer.
285
+ ```
286
+
287
+ ### Diagnostic Figures — NIST Simulated Weibull
288
+
289
+ #### Comparative Density (`density.png`)
290
+
291
+ ![NIST Weibull Comparative Density](docs/case_studies/nist_weibull/density.png)
292
+
293
+ *Freedman–Diaconis histogram and marginal rug overlaid with the top five fitted densities; the Weibull/Rayleigh cluster matches both the mode near `0.7` and the right-skewed decay, while `gamma` shifts the peak too far left.*
294
+
295
+ #### Empirical CDF & Residual Deviation (`cumulative.png`)
296
+
297
+ ![NIST Weibull Cumulative Distribution](docs/case_studies/nist_weibull/cumulative.png)
298
+
299
+ *Empirical step CDF with its 95% Dvoretzky–Kiefer–Wolfowitz (DKW) simultaneous band, maximum KS distance callout (`D_KS = 0.0234` for `weibull_min`), and bottom residual panel $F_n(x) - \hat{F}(x)$ staying well inside the confidence limits.*
300
+
301
+ #### Quantile-Quantile & Detrended Worm Plot (`quantiles.png`)
302
+
303
+ ![NIST Weibull Q-Q Diagnostics](docs/case_studies/nist_weibull/quantiles.png)
304
+
305
+ *Classical Q-Q plot (left) and detrended Q-Q residual plot (right) confirming close agreement in original units across the lower and upper tails for the top four models.*
306
+
307
+ #### Probability-Probability & Detrended P-P Plot (`probabilities.png`)
308
+
309
+ ![NIST Weibull P-P Diagnostics](docs/case_studies/nist_weibull/probabilities.png)
310
+
311
+ *Classical P-P plot with the 95% DKW band (left) and detrended P-P residuals (right), highlighting central probability-mass agreement and exposing the S-shaped misfit of `gamma`.*
312
+
313
+ #### Log-Scale Survival Function (`survival.png`)
314
+
315
+ ![NIST Weibull Survival Function](docs/case_studies/nist_weibull/survival.png)
316
+
317
+ *Log-scale empirical survival curve $S(x) = 1 - F(x)$ with upper-tail reference percentiles ($P_{90}, P_{95}, P_{99}$) separating Weibull-like tail decay from heavier-tailed alternatives.*
318
+
319
+ #### Information Criteria & Empirical Discrepancies (`criteria.png`)
320
+
321
+ ![NIST Weibull Selection Criteria](docs/case_studies/nist_weibull/criteria.png)
322
+
323
+ *Side-by-side comparison of AIC scores, Akaike weights, and empirical KS / Cramér–von Mises distances showing the crisp gap between the top four models ($\text{AIC} \in [584.8, 587.4]$) and the remaining six candidates ($\text{AIC} \ge 613.5$).*
324
+
325
+ #### Observation-Order Trajectory & Marginal Dispersion (`series.png`)
326
+
327
+ ![NIST Weibull Observation Series](docs/case_studies/nist_weibull/series.png)
328
+
329
+ *Row-order trajectory with $\pm 1\text{ SD}$ band, moving average, and marginal boxplot verifying stability and absence of structural drift across all 500 observations.*
330
+
331
+ #### Standalone Comparative PDF (`pdf.png`)
332
+
333
+ ![NIST Weibull Standalone PDF](docs/case_studies/nist_weibull/pdf.png)
334
+
335
+ *Standalone comparative PDF panel formatted for direct inclusion in reports and slides.*
336
+
337
+ #### Standalone Comparative CDF (`cdf.png`)
338
+
339
+ ![NIST Weibull Standalone CDF](docs/case_studies/nist_weibull/cdf.png)
340
+
341
+ *Standalone comparative CDF and residual deviation panel isolating the top candidates.*
342
+
343
+ #### Rank-1 Model PDF (`models/mle/continuous/01_rayleigh/pdf.png`)
344
+
345
+ ![NIST Weibull Rank-1 Model PDF](docs/case_studies/nist_weibull/model_winner_pdf.png)
346
+
347
+ *Dedicated single-model density plot for the rank-1 AIC winner (`rayleigh`) without competing curves.*
348
+
349
+ #### Rank-1 Model CDF (`models/mle/continuous/01_rayleigh/cdf.png`)
350
+
351
+ ![NIST Weibull Rank-1 Model CDF](docs/case_studies/nist_weibull/model_winner_cdf.png)
352
+
353
+ *Dedicated single-model CDF plot for `rayleigh` pinning its maximum Kolmogorov–Smirnov discrepancy coordinate (`D_KS = 0.0311`).*
354
+
355
+ ---
356
+
357
+ ## Case Study 2: NIST Simulated Lognormal (`LGN2.DAT`)
358
+
359
+ This example fits 10 continuous distributions via Maximum Likelihood Estimation (`mle`) to the public NIST/Dataplot simulated lognormal sample (`LGN2.DAT`, Olsson 2005, column `valor`, `n = 40`, generated from `Lognormal(s = 1, loc = 0, scale = exp(5) ≈ 148.413)`).
360
+
361
+ ### Runnable Code
362
+
363
+ ```python
364
+ from fitcdf import analyze_dataset
365
+
366
+ report = analyze_dataset(
367
+ "dataset/nist_lognormal/dados.csv", # Replace with your own CSV path
368
+ columns=["valor"],
369
+ data_type="continuous",
370
+ families=[
371
+ "lognorm",
372
+ "gamma",
373
+ "weibull_min",
374
+ "weibull_2p_left_trunc",
375
+ "invgauss",
376
+ "fisk",
377
+ "burr12",
378
+ "norm",
379
+ "expon",
380
+ "fatiguelife",
381
+ ],
382
+ method="mle",
383
+ criterion="aic",
384
+ seed=20261028,
385
+ workers=1,
386
+ )
387
+ ```
388
+
389
+ ### Sample Summary & Observed Ranking
390
+
391
+ | Column | `n` | Mean | Median | Std. Dev. | Min | Q1 | Q3 | Max |
392
+ | :--- | :---: | :---: | :---: | :---: | :---: | :---: | :---: | :---: |
393
+ | **`valor`** | `40` | `274.96` | `177.35` | `310.34` | `23.80` | `79.93` | `338.05` | `1568.30` |
394
+
395
+ | Rank | Family | AIC | $\Delta\text{AIC}$ | Akaike Weight | BIC | KS ($D$) | CvM ($W^2$) | Free Params | Estimated Parameters |
396
+ | :---: | :--- | :---: | :---: | :---: | :---: | :---: | :---: | :---: | :--- |
397
+ | **1** | **`invgauss`** | **525.59** | **0.00** | **28.2%** | **528.97** | 0.0858 | 0.0193 | 2 | `mu=1.5478`, `loc=0.0`, `scale=177.6427` |
398
+ | 2 | `fatiguelife` | 525.67 | 0.08 | 27.0% | 529.05 | 0.0610 | 0.0219 | 2 | `c=1.0920`, `loc=0.0`, `scale=173.2223` |
399
+ | 3 | `weibull_2p_left_trunc` | 526.10 | 0.51 | 21.8% | 531.17 | **0.0579** | **0.0162** | 3 | `c=0.7807`, `trunc_left=23.8`, `scale=198.1872` |
400
+ | 4 | `lognorm` | 527.03 | 1.44 | 13.7% | 530.41 | 0.0677 | 0.0246 | 2 | `s=0.9917`, `loc=0.0`, `scale=168.5438` |
401
+ | 5 | `fisk` | 529.19 | 3.61 | 4.6% | 532.57 | 0.0781 | 0.0316 | 2 | `c=1.7133`, `loc=0.0`, `scale=165.8174` |
402
+ | 6 | `burr12` | 531.19 | 5.60 | 1.7% | 536.26 | 0.0805 | 0.0319 | 3 | `c=1.7456`, `d=0.9490`, `scale=158.1327` |
403
+ | 7 | `expon` | 531.33 | 5.74 | 1.6% | 533.02 | 0.1053 | 0.0733 | 1 | `loc=0.0`, `scale=274.9625` |
404
+ | 8 | `gamma` | 532.80 | 7.21 | 0.8% | 536.18 | 0.1124 | 0.1017 | 2 | `a=1.1599`, `loc=0.0`, `scale=237.0655` |
405
+ | 9 | `weibull_min` | 533.28 | 7.69 | 0.6% | 536.65 | 0.1031 | 0.0812 | 2 | `c=1.0274`, `loc=0.0`, `scale=278.4518` |
406
+ | 10 | `norm` | 575.52 | 49.93 | <0.1% | 578.89 | 0.2189 | 0.5933 | 2 | `loc=274.9625`, `scale=306.4389` |
407
+
408
+ > [!NOTE]
409
+ > **Interpreting finite-sample competition (`n = 40`):** In a 40-point right-skewed sample, several positively skewed laws produce nearly indistinguishable likelihoods: `invgauss`, `fatiguelife`, `weibull_2p_left_trunc`, and `lognorm` all lie within $\Delta\text{AIC} \le 1.44$ and jointly account for `90.7%` of the Akaike weight. `lognorm` recovers the documented generator accurately via closed-form MLE (`s = 0.9917` vs. `1.0`, `scale = 168.54` vs. `148.41`, `KS = 0.0677`), while symmetric `norm` is decisively rejected ($\Delta\text{AIC} = 49.93$, $\text{KS} = 0.2189$). Information-criterion rankings measure relative support among competing candidates rather than proving a single true law.
410
+
411
+ #### Rank-1 Parameter Summary (`models/mle/continuous/01_invgauss/report.md`)
412
+
413
+ | Parameter | Estimate | Status | Search Bounds | Statistical Meaning |
414
+ | :--- | :---: | :---: | :---: | :--- |
415
+ | `mu` | `1.5478401` | free | `[0.0001; 6273.2]` | Standardized mean-to-shape ratio of the Inverse Gaussian (Wald) distribution. |
416
+ | `loc` | `0` | fixed | `[0; 0]` | Lower support endpoint of the Inverse Gaussian distribution. |
417
+ | `scale` | `177.6427` | free | `[0.0015445; 156830]` | Positive scale factor of the Inverse Gaussian distribution. |
418
+
419
+ #### Real `results.csv` Excerpt (Top 4 Rows)
420
+
421
+ ```csv
422
+ rank;distribution_name;family;data_type;method;status;eligible;criterion;score;delta;akaike_weight;log_likelihood;parameter_count;aic;aicc;bic;ks;cvm;ad;chi2;evaluations;duration_seconds;parameters;reason
423
+ 1;Inverse Gaussian;invgauss;continuous;mle;fitted;True;aic;525.587579571478;0.0;0.281615132825007;-260.793789785739;2;525.587579571478;525.9119038958024;528.9653384797059;0.0857928449905816;0.019325336877722508;0.12980804659098055;1.0999999999999972;649;0.04872052698920015;mu=1.5478401294347972, loc=0.0, scale=177.64269747856298;Numerical convergence confirmed by the optimizer.
424
+ 2;Birnbaum-Saunders;fatiguelife;continuous;mle;fitted;True;aic;525.6712394777719;0.08365990629386033;0.2700781626548883;-260.83561973888595;2;525.6712394777719;525.9955638020963;529.0489983859998;0.061028145087960506;0.021900516414203125;0.1485640466166629;0.6999999999999961;637;0.049209962991881184;c=1.0919892124173214, loc=0.0, scale=173.2222846123733;Numerical convergence confirmed by the optimizer.
425
+ 3;2-Parameter Left-Truncated Weibull;weibull_2p_left_trunc;continuous;mle;fitted;True;aic;526.0990082435392;0.511428672061129;0.21807237989157402;-260.0495041217696;3;526.0990082435392;526.7656749102058;531.165646605881;0.057903963432267884;0.016208052157442896;17.264997779385723;0.39999999999999925;1407;0.074415669994778;c=0.7807077710381518, trunc_left=23.8, loc=0.0, scale=198.18722777915838;Numerical convergence confirmed by the optimizer.
426
+ 4;Log-Normal;lognorm;continuous;mle;fitted;True;aic;527.0274462333102;1.439866661832184;0.13708594030444526;-261.5137231166551;2;527.0274462333102;527.3517705576346;530.4052051415381;0.06768268971202862;0.024570591241194983;0.17380927349144315;1.5999999999999992;0;0.002779629998258315;s=0.99174327413845, loc=0.0, scale=168.5437813704128;Exact closed-form maximum likelihood solution.
427
+ ```
428
+
429
+ ### Diagnostic Figures — NIST Simulated Lognormal
430
+
431
+ #### Comparative Density (`density.png`)
432
+
433
+ ![NIST Lognormal Comparative Density](docs/case_studies/nist_lognormal/density.png)
434
+
435
+ *Right-skewed empirical histogram (`skewness = 2.34`, `excess kurtosis = 6.14`) overlaid with the top five skewed candidates, capturing both the sharp lower concentration and the long right tail up to `1568.3`.*
436
+
437
+ #### Empirical CDF & Residual Deviation (`cumulative.png`)
438
+
439
+ ![NIST Lognormal Cumulative Distribution](docs/case_studies/nist_lognormal/cumulative.png)
440
+
441
+ *Step ECDF with its wider small-sample 95% DKW confidence band ($\pm 0.215$), showing all top five skewed models staying close to the zero-residual line (`D_KS = 0.0579` for `weibull_2p_left_trunc`, `0.0677` for `lognorm`).*
442
+
443
+ #### Quantile-Quantile & Detrended Worm Plot (`quantiles.png`)
444
+
445
+ ![NIST Lognormal Q-Q Diagnostics](docs/case_studies/nist_lognormal/quantiles.png)
446
+
447
+ *Classical and detrended Q-Q panels revealing how `invgauss`, `fatiguelife`, `weibull_2p_left_trunc`, and `lognorm` track the upper-tail order statistics above `800`.*
448
+
449
+ #### Probability-Probability & Detrended P-P Plot (`probabilities.png`)
450
+
451
+ ![NIST Lognormal P-P Diagnostics](docs/case_studies/nist_lognormal/probabilities.png)
452
+
453
+ *Classical and detrended P-P panels confirming tight calibration across the full cumulative probability range `[0, 1]` inside the 95% DKW envelope.*
454
+
455
+ #### Log-Scale Survival Function (`survival.png`)
456
+
457
+ ![NIST Lognormal Survival Function](docs/case_studies/nist_lognormal/survival.png)
458
+
459
+ *Log-scale survival trajectories highlighting upper-tail behavior past $P_{90}$, $P_{95}$, and $P_{99}$, where `lognorm`, `invgauss`, and `fatiguelife` closely bound the extreme observations.*
460
+
461
+ #### Information Criteria & Empirical Discrepancies (`criteria.png`)
462
+
463
+ ![NIST Lognormal Selection Criteria](docs/case_studies/nist_lognormal/criteria.png)
464
+
465
+ *Criteria summary quantifying the near-tie among the top four skewed laws ($\Delta\text{AIC} \le 1.44$) and the sharp separation from symmetric `norm` ($\Delta\text{AIC} = 49.93$).*
466
+
467
+ #### Observation-Order Trajectory & Marginal Dispersion (`series.png`)
468
+
469
+ ![NIST Lognormal Observation Series](docs/case_studies/nist_lognormal/series.png)
470
+
471
+ *Row-order trajectory and marginal boxplot displaying the right-skewed upper outliers without systematic index drift across the 40 observations.*
472
+
473
+ #### Standalone Comparative PDF (`pdf.png`)
474
+
475
+ ![NIST Lognormal Standalone PDF](docs/case_studies/nist_lognormal/pdf.png)
476
+
477
+ *Standalone comparative PDF panel summarizing the five highest-ranked skewed candidates.*
478
+
479
+ #### Standalone Comparative CDF (`cdf.png`)
480
+
481
+ ![NIST Lognormal Standalone CDF](docs/case_studies/nist_lognormal/cdf.png)
482
+
483
+ *Standalone comparative CDF and residual deviation panel for the Lognormal case study.*
484
+
485
+ #### Rank-1 Model PDF (`models/mle/continuous/01_invgauss/pdf.png`)
486
+
487
+ ![NIST Lognormal Rank-1 Model PDF](docs/case_studies/nist_lognormal/model_winner_pdf.png)
488
+
489
+ *Dedicated single-model density plot for the rank-1 AIC candidate (`invgauss`) showing its fit across the heavy right tail.*
490
+
491
+ #### Rank-1 Model CDF (`models/mle/continuous/01_invgauss/cdf.png`)
492
+
493
+ ![NIST Lognormal Rank-1 Model CDF](docs/case_studies/nist_lognormal/model_winner_cdf.png)
494
+
495
+ *Dedicated single-model CDF plot for `invgauss` highlighting its maximum Kolmogorov–Smirnov discrepancy (`D_KS = 0.0858`).*
496
+
497
+ ---
498
+
499
+ ## Supported Families (56 Distributions)
500
+
501
+ `fitcdf` ships a versioned catalog of **56 univariate distributions** (`44` continuous and `12` discrete), organized by mathematical support and data nature:
502
+
503
+ | Category | Count | Families |
504
+ | :--- | :---: | :--- |
505
+ | **Standard Continuous** | 40 | `anglit`, `beta`, `burr12`, `cauchy`, `chi2`, `cosine`, `crystalball`, `erlang`, `expon`, `exponnorm`, `f`, `fatiguelife`, `fisk`, `gamma`, `genextreme`, `gennorm`, `genpareto`, `gompertz`, `gumbel_l`, `gumbel_r`, `halfcauchy`, `halfnorm`, `invgamma`, `invgauss`, `laplace`, `logistic`, `lognorm`, `lomax`, `maxwell`, `nakagami`, `norm`, `pareto`, `rayleigh`, `skewnorm`, `t`, `triang`, `tukeylambda`, `uniform`, `weibull_max`, `weibull_min` |
506
+ | **Truncated Weibull** | 4 | `weibull_2p_left_trunc`, `weibull_2p_right_trunc`, `weibull_3p_left_trunc`, `weibull_3p_right_trunc` |
507
+ | **Standard Discrete** | 11 | `bernoulli`, `betabinom`, `binom`, `geom`, `hypergeom`, `logser`, `nbinom`, `planck`, `poisson`, `randint`, `zipf` |
508
+ | **Poisson-Binomial** | 1 | `poisson_binomial` (evaluated when trial probabilities or trial counts are supplied explicitly) |
509
+
510
+ ---
511
+
512
+ ## Estimation Methods & Diagnostics
513
+
514
+ ### Five Estimation Methods
515
+
516
+ | Method | Identifier | Description |
517
+ | :--- | :--- | :--- |
518
+ | **Maximum Likelihood** | `mle` | Closed-form analytic MLE where available; bounded multi-start numerical log-likelihood maximization and discrete integer profile/coordinate ascent otherwise. |
519
+ | **Method of Moments** | `moments` | Matches theoretical moments (mean, variance, skewness, kurtosis) to empirical sample moments. |
520
+ | **Quantile Matching** | `quantiles` | Minimizes squared discrepancies between empirical and theoretical quantiles across symmetric probability grids. |
521
+ | **Minimum Distance** | `distance` | Minimizes empirical-to-theoretical CDF distance (Cramér–von Mises / Kolmogorov objectives). |
522
+ | **Maximum Product of Spacings** | `spacings` | Maximizes the geometric mean of CDF spacings between ordered continuous observations (Cheng & Amin). |
523
+
524
+ ### Goodness-of-Fit & Uncertainty Diagnostics
525
+
526
+ - **Information Criteria & Relative Support:** `AIC`, `AICc`, `BIC`, $\Delta_i$, and relative Akaike weights $w_i$ computed strictly within compatible data-nature and estimation-method groups.
527
+ - **Empirical Distribution Discrepancies:** Kolmogorov–Smirnov ($D$), Cramér–von Mises ($W^2$), Anderson–Darling ($A^2$), and binned Pearson Chi-Square ($\chi^2$).
528
+ - **Simultaneous Confidence Envelope:** 95% Dvoretzky–Kiefer–Wolfowitz (DKW) band on ECDF and P-P diagnostic plots.
529
+ - **Bootstrap Calibration & Uncertainty:** Optional parametric goodness-of-fit bootstrap replicates (`gof_replicates`) and nonparametric percentile bootstrap intervals via `resample_parameter_uncertainty`.
530
+
531
+ ---
532
+
533
+ ## Scientific References
534
+
535
+ The probability definitions, parameterizations, estimation procedures, and diagnostic conventions in `fitcdf` are grounded in:
536
+
537
+ - **Balakrishnan, N., & Nevzorov, V. B. (2003).** *A Primer on Statistical Distributions.* Wiley-Interscience.
538
+ - **Thomopoulos, N. T. (2017).** *Statistical Distributions: Applications and Parameter Estimates.* Springer International Publishing.
539
+ - **NIST/SEMATECH (2012).** *e-Handbook of Statistical Methods.* National Institute of Standards and Technology (source of the `RANDWEIB.DAT` and `LGN2.DAT` benchmark samples).
540
+ - Additional bibliographic references on information criteria, goodness-of-fit diagnostics, and model selection are cataloged in [docs/references.md](docs/references.md).