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
Linear1D and Planar2D should be able to fit as model sets #10623
Conversation
e4f7078
to
207e15c
Compare
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.
Mostly minor comments
@@ -969,6 +970,8 @@ astropy.modeling | |||
without units when the expression involves operators other than addition | |||
and subtraction. [#10415] | |||
|
|||
- Fixed a problem with fitting ``Linear1D`` and ``Planar2D`` ain model sets. [#10623] | |||
|
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.
typo before model
docs/modeling/models.rst
Outdated
in the correct shape. The shape depends on the ``model_set_axis`` attribute of the | ||
model to be fit. The rule is that the dependent variable for each model in a set should | ||
be along the ``model_set_axis`` dimension. For example, for a 1D model set with 3 models | ||
with ``model_set_axis == 1`` the shape of ``y`` should be (x, 3):: |
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 don't know for sure, but I find the use of 'dependent' variable in this description to be confusing, Dependent on what? The input x values or the model set? I think it should be more specific, something like "the index of the dependent variable that corresponds to the model set should be the model_set_axis, for example, if there were 10 x input values and 3 model sets the shape of y should be (10, 3). Or something like that.
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.
Thanks, I was struggling with this sentence.
docs/modeling/models.rst
Outdated
>>> m = Polynomial1D(1, n_models=3, model_set_axis=1) | ||
>>> mfit = fitter(m, x, y) | ||
|
||
For a 2D model set with ``model_set_axis == 0`` the shape of ``z`` should be (2, x, y):: |
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.
Here 2D is potentially misunderstood. Perhaps reword as "For 2D models with the model_set_axis = 0" (should we really use '==' instead of '='?)
>>> print(z.shape) | ||
(2, 2, 4) | ||
>>> m = Polynomial2D(1, n_models=2, model_set_axis=0) | ||
>>> mfit = fitter(m, x, y, z) |
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 always figure it is good to avoid dimensions that are identical in size to prevent confusion. Here we have two that are 2.
fixderivs = self._deriv_with_constraints(model_copy, | ||
fixparam_indices, | ||
x=x) | ||
lhs = np.asarray(self._deriv_with_constraints(model_copy, |
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.
Just to understand better, what was being returned before?
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.
Previously, it was a list.
|
||
with pytest.raises(ValueError): | ||
p1(x) | ||
|
||
with pytest.raises(ValueError): | ||
p1(xx) | ||
with pytest.raises(ValueError): |
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.
Why the nesting?
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.
cut and paste error, removed it
@@ -204,11 +210,43 @@ def test_shapes(): | |||
assert t.e.shape == (2,) | |||
|
|||
|
|||
def test_linearlsqfitter(): | |||
def test_eval(): | |||
""" Tests evaluation of Linear1D and Planar2D with differrent model_set_axis.""" |
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.
different misspelling
@perrygreenfield I addressed your comments. Thanks. |
@@ -495,9 +494,6 @@ def __call__(self, model, x, y, z=None, weights=None, rcond=None): | |||
lhs *= weights[:, np.newaxis] | |||
rhs = rhs * weights | |||
|
|||
if rcond is None: | |||
rcond = len(x) * np.finfo(x.dtype).eps | |||
|
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.
To explain: numpy now deals with this, if rcond
is None.
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.
LGTM
c4dcbd0
to
c228476
Compare
Linear1D and Planar2D should be able to fit as model sets
Linear1D and Planar2D should be able to fit as model sets
Linear1D and Planar2D should be able to fit as model sets
Linear1D and Planar2D should be able to fit as model sets
Linear1D
andPlanar2D
should be able to fit as model sets withLinearLSQ
fitter which this PR enables.While fixing the problem I noticed a larger (design) issue with the way the fitter calls the derivative of a model. Currently the call is
This works fine with single models. However, the signature of this method for non-linear models lists all parameters as keyword parameters. When a model set is fit the list
*model.parameters
becomes longer than the list of parameters in the signature.When fitting.py is refactored the call to
fit_deriv
needs to be changed to solve this problem.