Repository navigation
Conversation
Describe how the model is fitted in `BaseHist.plot_pull` and `BaseHist.plot_ratio`: `scipy.optimize.curve_fit` weighted by the histogram's bin uncertainties, or an iminuit Poisson likelihood when `likelihood=True`. Also document where the initial values come from (the model's keyword defaults, or estimated from the histogram for the built-in "gauss" models), the `fit_fmt` label, that the fitted parameters are not returned, the prefixed keyword arguments, and the errors raised. Closes scikit-hep#207
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What was wrong
BaseHist.plot_pull(andplot_ratiowith a model) documentedfuncandax_dictonly, so a reader could not tell what happens behind the fit that the pull subplot is built from: which fitter runs, where the initial parameter values come from, how fit results can be read, or which keyword arguments are accepted. This is what #207 asks for, and its example (``h.plot_pull(pdf, ...)` with no further explanation) is still the only one.What this changes
Documentation only, in
src/hist/basehist.py:plot_pullnow documents the**kwargsgroups (eb_*,fp_*,ub_*,bar_*,pp_*,rp_*), thelikelihoodandfit_fmtoptions, the return value of the two artists tuples, and theTypeError/ValueErrorcases.Notessection covers:scipy.optimize.curve_fitweighted bysqrt(histogram.variances())as absolute uncertainties, with bins of zero uncertainty left out, or a Poisson likelihood minimised withiminuit.Minuit(seeded from the least-squares fit, covariance fromMinuit.hesse) forlikelihood=True;lambda x, a=1.0, b=2.0: ...starts ata=1.0, b=2.0),1for the parameters of a string expression, and height/mean/width estimated from the histogram for the built-in"gauss"/"gaus"/"normal"models;fit_fmtand a directcurve_fitgiven as the two ways to obtain them;(value - model) / uncertainty, with non-finite pulls drawn as zero.fit_fmtlabelling the parameter values.plot_ratiogets the matching**kwargs/Returns/Notestext, since it shares_plot_ratiolikeand the same fit.No code, tests, or behaviour change:
git diff --statis1 file changed, 91 insertions(+).Testing
Every claim in the new text was checked by running the code behind it:
The documented example runs as a doctest:
no output, i.e. no failures.
Initial values confirmed by wrapping
hist.plot._curve_fit_wrapperand printing thep0it builds:[350.0, 0.0, 1.0]fordef model(x, constant=350.0, mean=0.0, sigma=1.0), and[1, 1, 1]for"a * np.exp(-((x - b) ** 2) / (2 * c**2))".likelihood=Trueruns throughiminuit.Minuit;fit_fmtproduces the parameter label on the legend (constant = 78.5 $\pm$ 3.16, ...);plot_ratiowith a model also works, as does therp_uncertainty_type="efficiency"/rp_ylimpair named in the text.The documented errors were reproduced: 2D input raises
TypeError, an unknown keyword raisesValueError: {'nope'}' not needed, and anax_dictwithoutpull_axraisesValueError: All axes should be all given or none at all.Test suites:
(the 8 skips are missing optional
awkward,pandas, andgraphed_histogramin this environment)Lint and type checks on the changed file:
pylint histreports only the pre-existingscipy.special.gammalnfalse positive insrc/hist/plot.py, andmypyreports the same 4 errors with and without this change (missingpandasstubs, numpy 2.5 instead of the pinned<2.3), so neither is caused by this PR.A full Sphinx build was not run: this machine has neither
pandocnor Graphvizdot, whichdocs/contributing.mdlists as documentation requirements.Closes #207
AI was used to write this code.