modeling is broken for multi param sets?#1680
Conversation
…ng n_inputs and n_outputs class attributes. In most cases the number of inputs/outputs is a property of the model class itself, and not of individual model instances. So it makes sense that they should be class attributes. There are a few exceptions currently, such as for PolynomialModel. But that might change as well since I don't think the PolynomialModel class is meant to be used directly.
|
Yeah, it might be worth putting this back in for at least Parametric models. The problem is that there's ambiguity in how multiple parameter sets are currently assigned (without explicitly giving But in most cases I agree that if |
|
Related to this issue, the following is also wrong: |
|
@embray - I am confused. How can 1D model accept a vector? Vector is 2D. |
|
"1D" may be a bit of a misnomer in this case, as it refers to the number of arguments to the function (in this case |
|
Maybe we are thinking about different definition of vectors? http://en.wikipedia.org/wiki/Euclidean_vector So what is the behavior of |
|
The difference is basically in the "shape" of the parameter value: I agree though this is still a little confusing, though this was the case before #1086 as well I think. In the former case the |
|
There's really no way to know how many parameter sets a model instance has unless it's specified through the This worked as expected initially, then |
|
So what kind of output am I supposed to get for With |
should give an error as it does. Pass |
|
In the case of |
|
Right about |
Using the current API, yes. But I don't know that passing in each parameter as an array is the best way the pass in the values for multiple param sets. Because what if you want something like |
That argument should probably just be called |
…ng param_dim in class factory.
|
I think it should be possible since there is no restriction in general on the shapes of parameter values. If Nadia is saying it shouldn't be possible then there should be a formal way of declaring the allowed size and/or number of dimensions of parameter values. |
|
Okay, I get your point. Although I cannot visualize what potential use something like this can be, but that certainly does not mean it should not be done. p/s: As you know, the code above currently does not work because it gives |
|
Now I am confused. Both There is (was) a formal way of declaring the shape and dimension of a parameter. I still say the current behavior is correct but |
|
I think 3 of us are confusing each other. Should we just meet offline and talk about this? I mean, our offices are just a few steps away. |
|
@plim Why would we do that? |
|
I think we need to have a discussion on the mailing list on what exactly a parameter to a model can be. This is something I'm still planning to add as an "open question" to APE2 (which I will get to probably after the 0.3 release is done). My feeling about this is that one should be allowed to define models using either scalar or arbitrary compound values for the parameters (so long as they're compatible with each other in the context of a given function, or at least broadcastable into common shape). For example, I should be allowed to define something like this (forgetting This effectively gives me a "matrix" of Gaussians that can be evaluated/fitted simultaneously. Perhaps even more simply one could have just set Basically this is just a generalization of the param_sets feature that already exists, except that you have a collection of parameter sets that have a shape and dimensionality of their own. This is sort of what I've been getting at, though it clashes with the existing param_sets feature, which is why the example you originally gave is currently broken.
Well, no, if we don't want to allow compound parameters for now if we can't allow the user to do something like In the latter case something like my above Gaussian example would be allowed, though it would ignore the shape of the parameter values and just go by the number of elements (in other words it doesn't matter whether you set So for now I think I will return it to the behavior described in the previous 2 paragraphs since they fit better with the existing design. But I would like to revisit this question... |
|
Right. I think that will work better for now. But I think it's a little confusing in principle. |
|
Two things I do want to try to keep, which I don't think will be hard:
the param_dim will be taken as 4 (this is the old behavior that @nden prefers). When returning the param_sets this shape is ignored, but when directly returning the parameter its shape is preserved:
You can see in this example that |
|
Slight modification to the second example: For |
|
Okay, I have this mostly working except for one test, and I think this test is responsible for a lot of the confusion about this: This test claims it should be possible to do something like: Here we have two parameter sets, and the "coeff" parameter is passed in two values: But again, nowhere does it make explicit that each value for "coeff" should be in the form I guess I just don't understand what use case this test is intended to cover, as it seems to contradict with most other use cases... |
and multiple param_dims. Now, for ParametricModels, if param_dim is not specified in the model's constructor (which will be the common case) the param_dim is automatically determined from the size of the input parameter values (which must all match). The one exception is that if param_dim > 1 and one of the parameters is passed in as a scalar, that scalar value is automatically repeated accross all param sets. The shape of each parameter value is largely irrelevant so long as it has the same number of elements as the model's param_dim. However one difference retained from astropy#1086 is that the shape of the input parameters is preserved when the user asks for a parameter's values. For example: >>> m = Const1DModel([[1, 2,], [3, 4]]) >>> m.param_dim 1 >>> m.amplitude.value array([[ 1., 2.], [ 3., 4.]]) Otherwise the shape of the parameter has no effect on evaluating or fitting the model. This fix isn't quite complete yet, as there is one test, test_object_pars, which currently fails. The behavior it tests for seems to contradict the desired behavior that @nden has suggested, and yet clearly this test worked in older versions of the code...
|
This use case, by the way, suggests that it should also be possible to do what originally brought up this issue: or even Update: Pre-#1086 the first case in this comment, using the So basically, for general subclasses of I'm fine with either way. This test case just makes it unclear what the actual intended behavior is... |
|
I think it is OK to release the code as it is. And push this for discussion for 0.3.1. |
|
@nden - thanks - postponed! |
|
Hold on...I'm still trying to fix this one. If nothing else I want to get it back to the previous functionality, though I don't fully understand the intent behind it. |
…al parameter values. I think this case is a bit odd since it's not possible with the Parametric1D and Parametric2D subclasses. But at least it works--this has effectively the same behavior as pre-astropy#1086 with respect to param sets
…added a test for this (really updated an existing test to reflect the new behavior).
|
Okay, as far as I can tell the changes in this PR effectively revert the behavior of |
|
👍 |
|
Sounds good - feel free to merge once it passes. |
|
Alright, looks like the tests passed, so merging. |
|
😌💦 |
I rebased astropy this morning and I started getting errors when trying to use some of the models with multiple parameter sets. Example:
After some investigation, I found out that unless
param_dimis explicitly set as inGaussian1DModel, it will always be 1.