-
Notifications
You must be signed in to change notification settings - Fork 279
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
Fix problems with arguments that are neither fit parameters nor independent variables #926
Conversation
Checking only against independent variables fails in the case of arguments that are neither fit parameters nore independent variables.
Additional keyword arguments used during fitting are only known to the former.
@schtandard I think that arguments of a Model function are either parameters or independent variables. We generally prefer a process of agreeing on what an issue is and maybe even a description of a solution to that issue before a PR. Some cases are easy to identify as bugs, sometimes experienced developers see a problem and know how to fix it (but sometimes I get this wrong ;)). I am having a hard time understanding what the actual problem is that you keep misidentifying as something else. Basically, we have not identified an Issue to be solved. It's possible that "ensure that independent variables can be left unspecified in |
I prefer that, too. I did not get the feeling that I was getting the issue across, though. I decided to just take a look at the code and when I discovered that the problem seemed to be isolated to two lines of code, I thought that maybe a PR would help communicate the issue. This doesn't seem to have been a total success, but I haven't given up hope just yet.
Ok, then this is surely a big part of the confusion. From my point of view, your documentation and the module behavior disagree. Let's look at the example from your post. def func(x, a=3, b=5, scale=None):
output = a +x*b
if scale is not None: output *= scale
return output
mod = Model(func) If we ask the model what its independent variables and parameters are print("independent variables:", mod.independent_vars)
print("parameters:", mod.param_names) we get
Apparently, the model thinks that
This is both in direct contradiction to your statement "You have repeatedly said that all independent variables must always be specified but that is simply untrue." and contains a reference to function arguments that are "otherwise part of the model" (i.e. not as a parameter or an independent variable). And then there is
This is where Does this help clarify things? |
@schtandard Well, I guess I think we should probably make sure that function arguments can only be Parameters or independent variables. Admittedly, the concept of "independent variable" has evolved here from "first argument, must be 1D ndarry" (as I think is still true in scipy So, I think we shoud assert that independent variables with a default value in the function signature should not be required in I think that such a fix would probably address most of the issues you have faced. |
That sounds like a good idea, though I cannot tell how many things would need changing for it. You probably have a much better overview than me there. Some comments:
|
@schtandard I believe this is now better (if not 100% fixed) with the merging of #941 |
Description
Model function arguments that are neither fit parameters nor independent variables were handled incorrect in two places.
Model.fit()
and thus a misleading spurious warning was issued.ModelResult.plot_fit()
, causingModelResult.plot()
to produce contradictory plots.This PR remedies both issues and fixes #917 (moved to #920).
Type of Changes
Tested on
Verification
Have you
(No API changes.)
(I get several warnings and three skipped tests, though.)
(Except for issues that also appeared when building on
master
, as described in Documentation does not build #924.)(No tests were affected by the change.)
(I did not add anything to
doc/whatsnew.rst
yet. I had a look at the file history and other PRs and it seems to be done in batch, separate from the PRs. I will add an entry if you ask me to.)(Same as for test, I don't think any example was affected and I did not add a new one.)