-
Notifications
You must be signed in to change notification settings - Fork 76
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
CostSum support for cost functions accepting a parameter array #941
Comments
The cost functions that accept a parametric model like You can override def my_model(x, *args): ...
# use my model with 3 parameters
my_model._parameters = {x: None, a: None, b: None, c: None}
nll = ExtendedBinnedNLL(counts, bin_edges, my_model)
Minuit(nll, ...).migrad() # get results for 3 parameters
# use my model with 2 parameters
my_model._parameters = {x: None, a: None, b: None}
nll = ExtendedBinnedNLL(counts, bin_edges, my_model)
Minuit(nll, ...).migrad() # get results for 2 parameters Your solution works as well, but I don't think it is a good idea to add a public interface for this. I don't want normal users to set parameters manually, because this is supposed to be handled behind the scenes by iminuit. For experts like you who need this, there is the option to provide the special |
Adding a |
Thanks for the detailed explanation and for pointing me towards |
It took me a while, but a PR is in progress @lvarriano |
That's great, thanks so much! |
Hello - I would like to add a
NormalConstraint
to anExtendedBinnedNLL
for one or more parameters. As noted in the docs,CostSum
does not currently support cost functions that accept a parameter array. However, my model has tens of background components, each with a different strength parameter. I would like the ability to quickly adjust the number of components in the fit, which would be limited if I need to explicitly define each parameter in the model function.Using a model function that takes an array of parameters, if I set the
ExtendedBinnedNLL._parameters
to a dictionary of the parameters, then I can add aNormalConstraint
to it, and the fit seems to work perfectly. I attached a MWE. mwe.txtInstead of accessing the internal
_parameters
myself, would it be possible to add a method to theCost
class that looks like the following? This seems to work for my problem, but I have not done extensive testing.Alternatively, if it were possible to pass a
name
option to theExtendedBinnedNLL
class (and similar classes) as in theTemplate
class, this should also fix the issue and is probably more consistent with the existing structure. It is already possible to add aTemplate
to aNormalConstraint
with no problem thanks to this.The text was updated successfully, but these errors were encountered: