cds2.guided_fit
Guided scientific fitting adds a user-controlled workflow on top of the low-level optimization API.
The workflow:
- inspects one or more CSV datasets and reports missing values;
- runs small pilot fits and repeated cross-validation before recommending one model;
- explains the recommendation with speed, expected fit behaviour and complexity;
- leaves final model selection to the user;
- includes measurement uncertainty when a
sigmacolumn is supplied; - detects suspicious residual outliers, quantifies their estimated RMSE effect and asks before excluding them;
- fits the selected model, calculates parameter uncertainty and 95% confidence intervals;
- checks held-out performance with repeated 5-fold cross-validation;
- cross-checks the fitted result with an independent numerical method;
- produces Matplotlib fit and residual PNG/PDF figures, a reproducibility manifest and an optional PDF/HTML/Markdown report; long PDF reports paginate automatically instead of truncating results;
- labels the overall result
reliable,cautionorunreliable; - recommends a different model when the selected fit is weak;
- recommends dataset-specific models when a single common model is materially weaker;
- compares manifest reruns with the saved analysis and warns when runtime versions, inputs, confidence intervals, fit parameters, RMSE or the reliability label change materially.
CLI
Interactive use:
cds2 guided-fit experiment.csv --x time --y response --sigma uncertainty
The CLI asks for decisions only when needed: missing-data handling, model selection, outlier exclusion and report format.
Non-interactive/reproducible use:
cds2 guided-fit experiment.csv \
--x time \
--y response \
--sigma uncertainty \
--model linear \
--missing interpolate \
--outliers keep \
--report pdf \
--seed 0 \
--output-dir results
Multiple datasets can be supplied to search for a common model:
cds2 guided-fit run-a.csv run-b.csv --x time --y response
Repeat an analysis from its saved manifest:
cds2 guided-fit-rerun results/guided_fit_manifest.json
The manifest stores the selected model, policies, seed, data hashes, input source metadata and NumPy/SciPy/pandas/Matplotlib/Python versions. Reruns compare those saved results with the new calculation and surface material instability instead of silently replacing the prior result.
What a drift warning looks like
When the runtime environment or numerical result has moved, the CLI makes that visible instead of silently treating the rerun as equivalent:
warning rerun differs materially from the saved analysis
detail runtime version changed: scipy <saved-version> -> <current-version>
detail confidence intervals changed materially for experiment: <relative-change>
The placeholders above are replaced by the versions and measured relative change from the actual rerun. A version drift is reported even when the numerical fit still happens to agree; confidence-interval drift is checked independently from RMSE and parameter drift.
API
Guided, user-controlled scientific model fitting.
The workflow recommends one model, but never silently chooses user-facing decisions such as model selection, missing-data treatment or outlier removal.
rerun_manifest(path, *, allow_outside_run_dir=False, trusted_roots=None)
Repeat a guided fit from a saved manifest.
By default every source_path recorded in the manifest must resolve
inside the manifest's own directory (the run directory) or the current
working directory, so a foreign manifest cannot make the tool read
arbitrary files. Pass allow_outside_run_dir=True to opt out of the
confinement, or trusted_roots to extend the whitelist explicitly
(the manifest directory itself is always trusted).
Source code in src/cds2/guided_fit.py
869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 | |