-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
support arrays as parameters #2149
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
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
a6447a4
support arrays as parameters
nden 493cd9b
remove Parameter.shape
nden 0e13c6f
fix docs and polynomials
nden 1efb22d
Correct parameter tests
nden 3140697
Do not allow 'optional' parameters. Rename MatrixRotation2D to Rotate…
nden File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This seems fine; though now that parameter initial values are passed all the way to the
Modelbase class, I wonder if it shouldn't also handle setting those initial values a laParametricModel._initialize_parameters. That would allow eliminating slight oddities like those in in the projection models where you have, for example,Now that initial parameter values are checked by the base class, the repetition of this kind of boilerplate suggests that setting the parameters should be handled in
Model.__init__as well. The only difference betweenModel._initialize_parametersandParametricModel._initialize_parametersis that the latter would also initialize the._parametersarray.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.
Though building further on that point, I wonder if then all models could have a
._parametersarray. This would, I think, simplify the implementation ofParametera bit and reduce the difference betweenParametricModeland any other type of model. I think the only thing that should really distinguishParametricModelis its support for fit constraints.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.
I am increasingly uncomfortable with the fact that depending on the base class models treat parameters in a different way. This makes the code hard to maintain and hard to understand because one needs to understand both ways. To illustrate what I mean:
for a
ParametricModelfor a model which subclasses directly
ModelNon-fittable models own their parameters, while fittable models own
._parameters.Treating parameters in a uniform way would be much preferable but I don't think we should make all models have
._parametersand behave like fittable models do now.Another reason why implementing
Parameteras a descriptor and defining model parameters as class variables is not good is that in this wayParametercan have only attributes which are the same for all instances. This makes it harder to haveParameter.valueorParameter.unitor any other attribute unless it applies to all instances. Essentially these have to be set on the model as is now done withvalue.I think a better way would be to have a regular
Parameterobject which holds its value and any other attributes specified when the class is initialized. And have aParameterDescriptorto access them.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 first part--"depending on the base class models treat parameters in a different way"--I agree with. The second part I'm not so sure. I don't know what you mean by a "ParameterDescriptor".
Parameteris already a descriptor and I don't see the point in throwing on more classes. Maybe one thing that would improve flexibility and simply the code is provide an internally used interface whereby individual model types can inform parameter instances bound to a model how to access the actual parameter values stored on the model. IIRC I already did that by havingParameterinstances usinggetattron the model they are bound to, but I don't remember exactly. I'd have to check the code. But I still feel like making theParameterinstances themselves store the value is asking for trouble. I still see theParameterinterface as merely an API convenience, and not something that should be intrinsic to the data models that individualModeltypes use to store their parameters.In other words, I feel like a
Modelshould be responsible for handling its own data. Not some other extra class.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.
@embray I was suggesting renaming the current
Parameterclass toParameterDescriptor(or something else) and having a regularParameterclass which stores the value and other information if needed. This newparameterclass can subclassQuantity. Why is it a bad idea to store the value of a parameter inParameterinstances owned by the model? I see it as equivalent to storing quantities with the option of adding more attributes if needed.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.
If we were to make
Parametera special subclass ofQuantity(I'm not really sure how I feel about that--Parameter really serves a different purpose as being purely information about a model--how, for example, is a constraint relevant to a stand-alone "Parameter" instance except in the context of fitting a model?)But even if we did that one part of the design of the
Parameterclass is that it can be used as a descriptor or as a concrete object. That way when defining a model, the author doesn't have to write:they only have to remember one interface:
I don't think it makes the interface that much more complicated, because the
__new__forParameter(or maybe it's the__init__--I forget) quickly determines whether this is a "concrete" parameter instance or descriptor for a parameter.