-
Notifications
You must be signed in to change notification settings - Fork 194
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
Add modeling and fitting tutorial notebook #2764
Conversation
Codecov Report
@@ Coverage Diff @@
## master #2764 +/- ##
==========================================
- Coverage 92.17% 92.17% -0.01%
==========================================
Files 142 142
Lines 16158 16157 -1
==========================================
- Hits 14894 14893 -1
Misses 1264 1264
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot @QRemy. A few general comments first:
-
I think we should write a general modeling / fitting notebook. For this we already have an unfilled notebook (https://docs.gammapy.org/0.16/notebooks/modeling.html). Please move over the content (or just rename...)
-
This general fitting notebook should include how to work with
Fit
class in general:- Show how use different fitting backends
- Show how to access the covariance information
- Show how to compute likelihood profiles
- Show how to compute confidence contours
-
The used dataset does not really matter and can remain the same as you have used now.
-
In general I would simplify the shown content for the contours:
- Just use one sigma value
- Normally there shouldn't be any outliers, the outlier filtering is somehow distracting from the actual content, if possible remove
- Here is a somewhat simpler version of the contour interpolation, seems easier to understand then the cumulative distance approach
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot @QRemy! I have one minor comment:
The amount of code could be reduced a little bit by using e.g. itertools like so:
from itertools import combinations
for par_1, par_2 in combinations(["alpha", "beta", "amplitude"], r=2):
contour = fit.minos_contours(par_1, par_2)
As I already mentioned in the dev call this morning, I think it's always a good idea to show users some functionality of the Python standard library.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @QRemy . This looks very nice.
As we discussed, at some point some of the contour plotting functions should go in the API itself.
There is one thing that puzzles me. The best beta value is 0.26 but the 1 sigma contours does not seem to include it. Is there a problem, or did I miss something?
Also you might use alpha instead of gamma for the index to be consistent with the parameter naming scheme.
The difference in beta seems to comes from the np.log(10) factor here: This is copied from the validation code, was it something introduced to match the parametrization of the joint Crab paper ? |
Ah yes indeed. The joint crab paper used a log10 expression to match the sherpa model which is expressed in log10 hence the factor. This should be removed here. |
- add a tutorial notebook showing how to perform the computation of confidence contours for parameters after a fit as suggested in gammapy#2682 Show the loading of datasets, the model creation (LogParabola), the Fit itself, the call to minos_contours, and then plot the result. The implementation largely re-used the code from the joint-crab validation: https://github.com/gammapy/gammapy-benchmarks/blob/master/validation/joint-crab/make.py - add extra functionality to plot multiple contours levels - add outliers filter for aberrant contour points given by Minuit - change the interpolation scheme
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @QRemy, looks good to me now.
Show the loading of datasets, the model creation (LogParabola), the Fit itself, the call to minos_contours, and then plot the result.
The implementation largely re-use the code from the joint-crab validation:
https://github.com/gammapy/gammapy-benchmarks/blob/master/validation/joint-crab/make.py