Skip to content
This repository has been archived by the owner on May 21, 2024. It is now read-only.

Error while trying to access draw or show methods #126

Open
tosaric opened this issue Mar 22, 2022 · 2 comments
Open

Error while trying to access draw or show methods #126

tosaric opened this issue Mar 22, 2022 · 2 comments

Comments

@tosaric
Copy link

tosaric commented Mar 22, 2022

I tried to access draw or show methods just like from the tutorial, but I get an error.
Here is minimal reproducible example:

from probfit import gaussian, UnbinnedLH
from iminuit import Minuit
unbinned_likelihood = UnbinnedLH(gaussian, xdata.values)
minuit = Minuit(unbinned_likelihood, mean=0, sigma=5)
unbinned_likelihood.draw(minuit)

And this is the errror I am getting:

AttributeError Traceback (most recent call last)
/var/folders/gj/xpkrsnhd2zl8gs7vsxy72bs40000gn/T/ipykernel_41791/1198878356.py in
1 minuit = Minuit(unbinned_likelihood, mean=0, sigma=5)
----> 2 unbinned_likelihood.draw(minuit)

probfit/costfunc.pyx in probfit.costfunc.UnbinnedLH.draw()

/opt/miniconda3/envs/astrometry/lib/python3.9/site-packages/probfit/plotting.py in draw_ulh(self, minuit, bins, ax, bound, parmloc, nfbins, print_par, grid, args, errors, parts, show_errbars, no_plot)
94 ax = plt.gca() if ax is None and not no_plot else ax
95
---> 96 arg, error = get_args_and_errors(self, minuit, args, errors)
97
98 n, e = np.histogram(self.data, bins=bins, range=bound, weights=self.weights)

/opt/miniconda3/envs/astrometry/lib/python3.9/site-packages/probfit/plotting.py in get_args_and_errors(self, minuit, args, errors)
40 ret_error = None
41 if minuit is not None: # case 1
---> 42 ret_arg = minuit.args
_ 43 ret_error = minuit.errors

44 return ret_arg, ret_error

AttributeError: 'Minuit' object has no attribute 'args'

@nrad
Copy link

nrad commented Jul 24, 2022

Also, just came across this issue. It looks like this is because probfit requires an older version of iminuit (1.5.4). So downgrading the iminuit version should solve this, but then you might end up missing some of the more recent features of iminuit.

The workaround is to pass minuit.values and minuit.errors to the draw function instead of minuit, i.e
unbinned_likelihood.draw(args=minuit.values, errors=minuit.errors)

@jonas-eschle
Copy link

jonas-eschle commented Sep 16, 2022

Hi @nrad , thanks for reporting this! However, probfit is not actively maintained anymore and won't get updates. As you seem to do unbinned likelihood fits, the recommendation would be to either use iminuit, which offers minimization capabilities and a few cost functions or zfit, which allows additionally to minimization (using iminuit) and cost functions - similarly to probfit - building your model with out-of-the-box components.

If any of the probfit functionality is missing, please let us know!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants