-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Merge model classes #2276
Merge model classes #2276
Conversation
@property | ||
def parameters(self): | ||
""" | ||
A flattened array of all parameter values in all parameter sets |
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.
Add dot at the end of this line.
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.
Not to nitpick about dots, but as a preference I don't use them in places like this since it's not actually a proper sentence.
But if we've decided to make the first line of every docstring a "sentence" regardless I'm okay with it for consistency's sake.
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.
It's actually required for numpydoc I think - we tweaked it so it would use full sentences instead of just first line, so I think it stops at the first full stop for the summary table.
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.
Actually, it doesn't matter if there are no lines after, but I can't see it from here.
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.
That's fine--I don't mind updating it.
@embray Does this need a change log entry? |
I haven't decided for sure yet, but I might just remove |
<https://github.com/astropy/astropy/pull/2149/files#r10402422> that different classes of models had different mechanisms for storing their parameter values, creating a fair amount of unncessary complexity. This change attempts to smooth out some of the differences by merging the old ParametricModel class into the base Model class, so that all models more or less operate on the same basis. An added advantage to this is that it adds full support for parameter constraints on *all* models, which can be useful even outside the context of fitting. This standardizes on the way ParametricModel stored parameters, where all the parameter values are stored in a single flat array along with a simple _param_metrics data structure providing information how to extract individual parameter values from that array. As @nden points out this may not be the *best* way. In fact, it might be difficult to really make this work with parameters as Quantities. But this was the path of least resistance for the first iteration. For now I've kept around a class named ParametricModel and its subclasses ParametricModel1D and ParametricModel2D and the subclasses thereof--the only thing that really distinguishes them at the moment is the fact that they have the `fittable=True` flag. This does *not* fully resolve the issue addressed in astropy#2149, but it will make the implementation for astropy#2149 simpler. This also adds a few inefficiences, particularly in any models that have angular parameter values that need to be converted to radians for compuations. I have a separate branch running parallel to this one that will attempt to address that issue.
initial values are set: * Constraints are treated in two separate categories: 'parameter constraints' which are constraints on specific parameters, and 'model constraints' which are general constraints on the model (specifically the 'eqcons' and 'ineqcons' constraints). * All constraints are stored in the ._constraints dict. * Setting of initial values of constraints is simplified so that only Model._initialize_constraints is responsible for this (though it still queries the individual parameters for any default constraints they may have).
…int better describes the small distinction it has over other Model types. All models (or almost all anyway) have one or more adjustable parameters of some sort or another"
… and isn't even necessary for the current JointFitter implementation. One can see how it might be useful to store somewhere on the model a reference to what other model(s) its params have been fitted against. But for the time being if a user is setting up a JointFitter they already have that information. Could still be worth revisiting though.
@@ -249,7 +249,7 @@ def do_fit(self, model=None, fitter=None, power=1, min_datapoints=3): | |||
Returns | |||
------- | |||
a : array_like | |||
Fitted `~astropy.modeling.core.ParametricModel.parameters`. | |||
Fitted `~astropy.modeling.core.FittableModel.parameters`. |
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 think it should be
`~astropy.modeling.FittableModel.parameters`
i.e. without the .core
part.
I'm not sure, but this might be the reason for this cryptic Sphinx TypeError
:
https://travis-ci.org/astropy/astropy/jobs/22730168#L3045
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.
That's weird--why would it be that? What's there is the correct fully-qualified name of the class, and the ".core" was there previously as well. Nonetheless, that change did seem to fix it for me. Any idea why that is? The error message is hopelessly cryptic, even for me.
I think this travis-ci error in |
@embray Is this ready for review or work in progress? |
I thought the SAMP failures had stopped occurring, but they seem to have started again recently... |
IMHO this PR is basically ready soon as the issue with the docs build is sorted out. I have lots of other parallel work going that will depend on this PR but it will probably be easier to go ahead and submit those as new PRs. |
If there is any one open issue it's the handling of |
In the past year big |
…tead I have to drop the '.core' part. Huh?
Okay, going ahead with this now that Travis is happy. This might cause some other open PRs to require rebasing but I will work on helping to do that as need be. |
Ack. This really ought to be in the changelog. Although we have said that the modeling package will be in flux it is still worth mentioning. |
Add record of the changes in #2276
Add record of the changes in astropy#2276
Note: This PR builds on top of #2264 and #2269 which should be merged before this one. If either of them is not to be merged this PR's dependency on those other changes can be cleaved off, however.
As pointed out by @nden at https://github.com/astropy/astropy/pull/2149/files#r10402422 , different classes of models had different mechanisms for storing their parameter values, creating a fair amount of unncessary complexity.
This change attempts to smooth out some of the differences by merging the old
ParametricModel
class into the baseModel
class, so that all models more or less operate on the same basis. This simplifies the code a fair amount and will make it easier to maintain. An added advantage to this is that it adds full support for parameter constraints on all models, which can be useful even outside the context of fitting. I intend to build that functionality in on top of this PR.This standardizes on the way
ParametricModel
stored parameters, where all the parameter values are stored in a single flat array along with a simple_param_metrics
data structure providing information how to extract individual parameter values from that array. As @nden points out this may not be the best way. In fact, it might be difficult to really make this work with parameters as Quantities. But this was the path of least resistance for the first iteration. It will also now be much easier to change to a different storage method later, as the changes are only required in a couple places.For now I've kept around a class named
ParametricModel
and its subclassesParametricModel1D
andParametricModel2D
and the subclasses thereof--the only thing that really distinguishes them at the moment is the fact that they have thefittable=True
flag.This does not fully resolve the issue addressed in #2149, but it will make the implementation for #2149 simpler. This also adds a few inefficiences, particularly in any models that have angular parameter values that need to be converted to radians for compuations. I have a separate branch running parallel to this one that will attempt to address that issue.