question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

LinearLSQFitter cannot fit compound models

See original GitHub issue

Undo the doc modifications in #6041 before closing this as resolved.

@nden tells me that “I think in general a compound model should be fitted with a non-linear fitter because at least currently the LinearFitter cannot construct the Vandermonde matrix for compound models”. It would be useful to have this working if possible, as I believe non-linear fitters are not guaranteed to converge on the solution without a good starting guess, which may not always be available. Also, the documentation should mention that it currently doesn’t work (which I’ll fix in the meantime). This is just for the record and in case someone wants to work on it before one of us gets to it.

Running LinearLSQFitter on a couple of compound models currently gives errors like the following:

>>> LinearLSQFitter()(Mapping((0,)) | Chebyshev1D(2), range(0,10), range(0,10))
Traceback (innermost last):
  File "<console>", line 1, in <module>
  File "/home/jturner/anaconda2/envs/peylian/lib/python2.7/site-packages/astropy-2.0.dev18162-py2.7-linux-x86_64.egg/astropy/modeling/fitting.py", line 254, in __call__
    raise ModelLinearityError('Model is not linear in parameters, '
ModelLinearityError: Model is not linear in parameters, linear fit methods should not be used.
>>> LinearLSQFitter()(Chebyshev1D(2) | Chebyshev1D(2), range(0,10), range(0,10)) 
Traceback (innermost last):
  File "<console>", line 1, in <module>
  File "/home/jturner/anaconda2/envs/peylian/lib/python2.7/site-packages/astropy-2.0.dev18162-py2.7-linux-x86_64.egg/astropy/modeling/fitting.py", line 279, in __call__
    lhs = model_copy.fit_deriv(x, *model_copy.parameters)
TypeError: 'NoneType' object is not callable

Issue Analytics

  • State:open
  • Created 6 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
jehturnercommented, May 10, 2017

Thanks. I was wondering if I should leave this for some new contributor at tomorrow’s sprints, but there are lots of “effort-low/package-novice” issues, so I’ll just do the docs (which could conceivably help people sprinting) 😄.

0reactions
jehturnercommented, Jun 19, 2017

Just a thought for later: For this to work, I believe we need a reliable way of determining whether a compound model is linear after combining its constituent models, which may or may not be the case. There is some such logic in _CompoundModelMeta, but, at a glance, it seems quite simplistic and I think the true outcome will depend on the individual models, as well as on the operator. I’m not sure whether this is feasible to do rigorously with a reasonable effort, as alluded to by an existing comment. Currently, however, the | operator produces linear=True when both operands are linear, which doesn’t seem like it can be generally correct (since the parameters of the first model may get coupled to multiple terms of the second one)?

Read more comments on GitHub >

github_iconTop Results From Across the Web

LinearLSQFitter — Astropy v5.2
Notes —– Note that currently LinearLSQFitter does not support compound models. Fit data to this model. Fit data to this model. Input coordinates....
Read more >
astropy.modeling.fitting - Read the Docs
Notes ----- Note that currently LinearLSQFitter does not support compound models. ... cannot fit model sets with masked " "values".format(type(self.fitter).
Read more >
LinearLSQFitter — Astropy v1.0.4
A class performing a linear least square fitting. ... Given a model and data, fits the model to the data and changes the...
Read more >
Why Can't we Just Use Regression? (Linear Marginal Models)
Sorry about the typo in the video! I noticed it after the fact, hopefully it bugs you less than it bugs me!An introduction...
Read more >
astropy Changelog - pyup.io
Fixes error when fitting multiplication or division based compound models ... Fixed cannot import name imperial from astropy.units namespace. [11977]
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found