-
-
Notifications
You must be signed in to change notification settings - Fork 17
added new model parameter API. #9
base: master
Are you sure you want to change the base?
added new model parameter API. #9
Conversation
Yes, this declarative approach to defining model classes looks very similar to what I already started in #1086. That didn't include descriptors like |
@iguananaut I think it would be good to make a combined effort to deal with this. Currently, we have efforts scattered across astropy/astropy#1203, astropy/astropy#1086, astropy/astropy#980 as far as I can tell. It doesn't necessarily have to be here on this PR, but I think an API PR would be great. If you think this PR is a good start feel free to commit to it. |
Well. I think 980 doesn't represent any particular substantive work--it just says "this is unideal". 1086 is my effort to simply and streamline things; though I really need to update and rebase it. 1203 is a separate effort to improve some of the issues brought up in 980 but for the most part doesn't overlap with it functionality-wise. |
@iguananaut is there anything I can do to help? should I close this PR here? |
To the contrary, I think maybe we should post a link to this on the mailinglist or something to get a little more attention. In my PR I sort of just went straight forward and DID what I had in mind, but that led to a very complicated diff and made it more difficult to go back and explain the issue (the comments in the PR got further confused by a mostly unrelated discussion about computational efficiency). It would be nice to have more discussion about this API approach and its merits. |
@iguananaut: Well we should make sure that this is inline with your PR. What ideas are in your PR that are not on this API PR? |
The main thing I emphasized in my PR that is not in your notes here is that I wanted to avoid duplication of data, and to store all pertinent data related to a model in one place. The problem with the current design is that there are at least two copies of all the parameter values: There are copies of the values stored in the My current approach stored the parameter values as attributes on the Model object and the So what I really need to do is the opposite of what I currently have: make the This post specifically discussed parameter values, but the same principle applies to things like constraints. |
@iguananaut I think what you're discussing here are more technical problems that are not that related to the actual API (still very important). So if you don't have anything to add, I will get something out to astropy-dev suggesting a similar API to this PR and linking to your implementation PR (highlighting the mentioned problem). |
You're right--I realized that while I was out to lunch. All that stuff I just wrote is more implementation detail than API-related (though it can affect the API in some places, it's mostly a separate issue). Otherwise, I really like your suggestion here, and it's basically the same thing I had in mind. |
|
||
mylittlepoly = Poly1DModel() | ||
mylittlepoly.c_0 = 10. | ||
mylittlepoly.fixed |
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.
What does it mean to have a whole model that is fixed
? Should it be mylittlepoly.c_0.fixed=True
?
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 would be my guess as to what was meant. Though the current ParametricModel
class does I think have a "fixed" attribute (or maybe it's "_fixed") that just returns a dict mapping each parameter to whether or not it's fixed.
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 wanted to show that fixed
is a property of a parameter (like currently in the Model
class). You know what I mean @keflavich?
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 admit I'm still a little lost. What should I see if I do print mylittlepoly.fixed
? Is it as @iguananaut says:
{'c_0': False, 'c_1': False, ...}
or just False
, or
{'c':[False,False,False,False,False]}
, or
something else?
[edit: the API suggests False
on line 51, but I thing @iguananaut's suggestion probably makes more sense]
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's wrong I should have written mylittlepoly.c_0.fixed
- sorry for the confusion. I think mylittlepoly.fixed shouldn't print anything it should throw an AttributeError
because you can't "fix" a model, just individual parameters of a model.
I like the general idea, and have no specific objections to what's shown here, but I think the examples could be fleshed out a little more. |
|
||
class Poly1DModel(modeling.Model): | ||
|
||
c = ParameterSet(5, syntax='_%s', unit=None, equivalency=None, fixed=False, tied=False, bounds=()) |
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 rather than "syntax" I might call this something like "format"...maybe?
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.
suffix_format
, perhaps?
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 not clear to me what ParameterSet
is. In the current framework the term is used for defining simultaneously the same kind of model with different parameters. For example p = Poly1DModel(degree=2, param_dim=2)
will create a Poly1DModel
with two parameter sets (effectively 2 models) which can be evaluated and fit simultaneously. The comment above states that ParameterSet
is used for model with multiple parameters . Did you mean parameters which are not scalars? If so why is a separate class needed?
@keflavich Can you specify some examples that you want to see. @nden: I changed from |
@wkerzendorf The short answer is efficiency. |
I am still not sure what
|
@nden I agree with you that a I think that what he's trying to go for with |
So the That brings me to the next point: There are two very different concepts we are addressing with parameter "dimensions" (I'm going to be using the word Modelclass for all models that use the same parameters and the same evaluation function, e.g. y=mx+b is a Modelclass, y=5*x+10 is a Model). The first concept is the one that Nadia describes - sometimes there's a need to fit the same Modelclass to a large collection of data. I feel that there should be a The second concept is that a parameter might be intrinsically multidimensional (e.g. a rotation matrix, polynomial coefficients, lookup table, ..) but still is one Model. When we mix these we run the danger of having inconsistent models: What should happen if I give a n-dimensional input? Does it evaluate all the inputs with all the |
@iguananaut @nden: I want to push this a little bit. What needs doing to get a version of this API implemented (I think this a more a question for @iguananaut). What's up with the PR that already exists? |
So, I need to do some work on rebasing my PR on master and integrating it with some of the changes that have already since occurred in the modeling package. Then I need to fix several issues it has with parameter constraints, and address the performance concerns Nadia had. I was actually hoping to start on that later this afternoon once I get through a few more things, but I'm not sure how long it will take. It's going to be an ugly merge :) |
I have started to implement basic WCS functionality in
specutils
and worked with the newModel
class fromastropy.modeling
. This showed me that the functionality inModel
is quite good, however the API is a bit "clunky". I've worked a lot with thesqlalchemy
- an object relational mapper. They represent their Tables (or table rows) as classes and have implemented a simple, but powerful API. Each individual column has a name, a type (and other properties like Foreignkey). This is very similar in my mind to a Model which has Parameters which have properties (e.g. fixed). Attached my suggestion of what I feel would makeModel
much easier to work with (mostly when writing your own).What are people's thoughts.