lbl-anp / becquerel

Becquerel is a Python package for analyzing nuclear spectroscopic measurements.
Other
43 stars 16 forks source link

Inconsistent interface for fixing fit parameters #320

Open micahfolsom opened 2 years ago

micahfolsom commented 2 years ago

In writing the test for , I needed to fit some of the troublesome fit parameters, and found that there's no consistent way to fix fit parameters. lmfit and minuit have different interfaces, and it'd be nice if we provided a central way that handled both. For lmfit, this would mean passing the vary= arg, and for minuit, this is setting fixed=.

Here's what I had to do in the test (tests/fitting_test.py):

525     fitter = bq.Fitter(model, **data)
526     # "fix" params for lmfit
527     fitter.params["ltail_cutoff"].min = 0.99
528     fitter.params["ltail_cutoff"].value = 1.0
529     fitter.params["ltail_cutoff"].max = 1.01
530     fitter.params["rtail_cutoff"].min = 0.99
531     fitter.params["rtail_cutoff"].value = 1.0
532     fitter.params["rtail_cutoff"].max = 1.01
533
534     # "fix" params for minuit
535     limits = {
536         "ltail_cutoff": (0.99, 1.01),
537         "rtail_cutoff": (0.99, 1.01),
538     }
539     fitter.fit(method, guess=params, limits=limits)