-
Notifications
You must be signed in to change notification settings - Fork 1
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
Shape parameters #58
Shape parameters #58
Conversation
Pull Request Test Coverage Report for Build 5673114176
💛 - Coveralls |
I now updated the exmple to look for the config in Edit: I re-introduced the folder now as I think there should be no incentive for anyone to add their templates and configs in alea directly. If there are strong opinions against that we can discuss and revert this 😊 |
alea/models/__init__.py
Outdated
@@ -1,5 +1,5 @@ | |||
from . import gaussian_model | |||
from .gaussian_model import * | |||
from ..examples import gaussian_model |
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.
[pep8] reported by reviewdog 🐶
D104 Missing docstring in public package
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.
At the moment, the changes makes it so that fits change if all parameters are set:
from alea.examples import gaussian_model
simple_model = gaussian_model.GaussianModel()
simple_model.data = simple_model.generate_data(mu=0, sigma=2)
bf, ret = simple_model.fit(sigma=2, mu=2)
bf, ret
Fails with
----> 1 m = Minuit(MinuitWrap(cost, simple_model.parameters),mu=0, sigma=0)
File ~/opt/miniconda3/envs/myenv/lib/python3.8/site-packages/iminuit/minuit.py:625, in Minuit.__init__(***failed resolving arguments***)
617 self._strategy = MnStrategy(1)
618 self._fcn = FCN(
619 fcn,
620 getattr(fcn, "grad", grad),
621 array_call,
622 getattr(fcn, "errordef", 1.0),
623 )
--> 625 self._init_state = _make_init_state(self._pos2var, start, kwds)
626 self._values = mutil.ValueView(self)
627 self._errors = mutil.ErrorView(self)
File ~/opt/miniconda3/envs/myenv/lib/python3.8/site-packages/iminuit/minuit.py:2470, in _make_init_state(pos2var, args, kwds)
2468 for kw in kwds:
2469 if kw not in pos2var:
-> 2470 raise RuntimeError(
2471 f"{kw} is not one of the parameters [{' '.join(pos2var)}]"
2472 )
2473 nargs = len(kwds)
2475 if len(pos2var) != nargs:
RuntimeError: mu is not one of the parameters []
We'll have to short-circuit this possibility somehow
Ah @kdund I think this is an iminuit version problem. I developed with an environment, which contained python 3.9 and iminuit 2.22 and then I got a lot of warnings so I updated the implementation. Now however it only works with iminuit >= 2.21, I also updated the requirements.txt accordingly. |
@@ -10,15 +10,18 @@ def get_analysis_space(analysis_space: dict) -> list: | |||
|
|||
for element in analysis_space: | |||
for key, value in element.items(): | |||
if value.startswith("np."): | |||
if isinstance(value, str) and value.startswith("np."): |
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.
Do you have an example for usage of this?
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.
The example config file has the analysis space defined in the following way:
analysis_space:
- "cs1": 'np.arange(0, 102, 2)'
- "cs2": 'np.geomspace(100, 100000, 51)'
This will be evaluated accordingly and saves a lot of space compared to the implementation in binference. However, I also re-enabled the binference-like definition, which can be useful when dealing with irregular binnings. To test this you could replace the definition of cs1 with the following:
- "cs1": "0. 2. 4. 6. 8. 10. 12. 14. 16. 18. 20. 22. 24. 26. 28.
30. 32. 34. 36. 38. 40. 42. 44. 46. 48. 50. 52. 54. 56.
58. 60. 62. 64. 66. 68. 70. 72. 74. 76. 78. 80. 82. 84.
86. 88. 90. 92. 94. 96. 98. 100."
and it should do exactly the same thing.
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.
Also, the example I posted in slack features both implementations (irregular binning in R).
@dachengx is now reviewdog 2.0 😄 But doesn't harm to be reminded to write readable code. I'll make those changes once the rest is fixed and the tests are running. |
Thanks a lot, @dachengx for fixing the wildcard issue -- very nice and clean solution! 😊 I now also implemented some of the formatting suggestions. Do you have any other suggestions regarding the code and have you tried running it? Also, @kdund did changing the iminuit version solve the issue and are you happy with the implementation of the |
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 @hammannr . Looks good to me. I agree that we put the code-style cleaning in another PR.
@@ -140,6 +141,8 @@ def get_template_folder_list(likelihood_config): | |||
template_folder_list = [likelihood_config["template_folder"]] | |||
elif isinstance(likelihood_config["template_folder"], list): | |||
template_folder_list = likelihood_config["template_folder"] | |||
elif likelihood_config["template_folder"] is None: |
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.
Great that you find this case!
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.
The fitting works for me w/ updated iminuit, thanks, @hammannr!
Slicing and stuff we can look at later.
Pull Request Test Coverage Report for Build 5666611708Warning: This coverage report may be inaccurate.This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.
Details
💛 - Coveralls |
This adds shape parameter support for the blueice extended model (closes #33). Also, some bugs are fixed.
Some of the things I modified:
ll.rate_parameters
are missing the_rate_multiplier
suffix so I updated the parameter overriding and filtering accordingly.errordef
was so far not correctly assigned, which caused trouble with the correct error estimation. I also made the minuit object a member of the class, so we can dostatistical_model.minuit_object.minos()
after the fit to very efficiently compute the (asymmetric) uncertainties of all fit parameters!You can try it using the following code: