-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
possible solution to lmfit-pml issue? #277
Comments
I wrote that code a while back and don't remember all the details. I think The log likelihood function in becquerel/becquerel/core/fitting.py Line 805 in 8f26ec3
log[f(x, theta)] in the wikipedia article) is an abbreviated form though, and needs an additional -sum_i log(k!) factor (see https://statlect.com/fundamentals-of-statistics/Poisson-distribution-maximum-likelihood) to be a proper log likelihood. I am not sure if that affects the fisher information though, I think it shouldn't as that factor disappears during the differentiation process.
Your observation is interesting, because I remember that I think we can enable this method with the suggestions you posted above and maybe add a warning about to what extend the respective uncertainties can be trusted. As a general note, Jayson implemented |
That would be my guess. It looks like It probably would be easiest to resolve this issue if someone can make a minimum working example (MWE) that demonstrates this, like fitting a constant model to a few simulated data points. |
I used the code in issue #251 which can be used as a MWE. Something like:
|
Thanks @arunpersaud @cosama as we discussed at the meeting today, there is an easy fix here, to include the factor of 2 in the Another fix could be to use the deviance residuals. Not sure if this will work properly, but it would involve modifying this line diff = model - scipy.special.xlogy(data, model) to diff = np.sign(data - model) * np.sqrt(2 * (scipy.special.xlogy(data, data / model) - data + model)) where the |
This is in regards to the fitting problem described in #251, but since it doesn't relate to minuit a new issue is probably the best place to post this.
Also just as a note, I don't really understand the details of this issue, so not sure if the comment here actually applies or if this is just a random coincidence that makes things look as if they work ;)
I noticed that when I install numdifftools (an optional dependency for lmfit), I do get error estimates for lmfit-pml after changing
calc_covar=True
around line 660 in core/fitting.py.
The errors are too big though (I get 1000 +- 1100).
To get something reasonable, I had to change
scale_covar=False,
and also add a factor of 2 to
diff = (model - scipy.special.xlogy(data, model))*2
here.
I'm especially not sure about the factor of 2, but I think for Gaussians
there is a factor of two between the likelihood and chi-squared... so
perhaps there is something similar here?
This gives:
A = 1001.4240078859714 +- 31.671526225310576
For the example from the github issue #251. This seems to match the expected value quite well!
Perhaps it is worthwhile to make numdifftools an explicit dependency for becquerel. If the other changes makes sense to you, perhaps one could use this to fix lmfit-pml.
The text was updated successfully, but these errors were encountered: