probfit
probfit copied to clipboard
Error while trying to access draw or show methods
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
/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'
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)
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!