Fix removal of units from CompoundModel with * or / and fix fitting of these models#16678
Conversation
|
Thank you for your contribution to Astropy! 🌌 This checklist is meant to remind the package maintainers who will review this pull request of some common things to look for.
|
|
👋 Thank you for your draft pull request! Do you know that you can use |
…level parameters on the CompoundModel were out of sync with the constituent models. It is cleaner to instantiate a new CompoundModel rather than try and modify a copy.
97e4101 to
2bd3dc3
Compare
perrygreenfield
left a comment
There was a problem hiding this comment.
Does it make sense to have tests that employ fitting on degenerate models?
|
@perrygreenfield probably not, but I wanted to avoid changing the tests too much since they do work as long as we don't look at the degenerate parameters values? |
|
I'd be happier with replacing these but someone else thinks they are OK, I can go with that. Otherwise I didn't see any other problems. |
|
I'll have a think whether there is a way to rewrite the tests that would preserve their essence, and fail on main to make sure they act as a regression test. |
|
What if we checked the values of combination of parameters? For example if and and b are degenerate, I might still be able to check the value of a*b? |
|
Can we just fix one of the intercept values? That should remove the degeneracy shouldn't it? |
|
Good idea about fixing one or more of the parameters, will investigate! (Might need to fix more than one for the compound models formed of four sub-models) |
daa4b1d to
197b51a
Compare
|
@perrygreenfield - ok I've now gone and fixed parameters - due to the nature of the model we need to fix all but two of the parameters, but I think this is fine and still tests what we need to test. There are no longer any degeneracies so we can check the parameter values. |
|
devdeps failure unrelated, so merging. Thanks, all! |
…th * or / and fix fitting of these models
…678-on-v6.1.x Backport PR #16678 on branch v6.1.x (Fix removal of units from CompoundModel with * or / and fix fitting of these models)
…f these models (#16678) * Fixed a bug in CompoundModel.without_units_for_data - before the top-level parameters on the CompoundModel were out of sync with the constituent models. It is cleaner to instantiate a new CompoundModel rather than try and modify a copy. * Added regression test * Fix tests of fitting compound models with * or / * Added changelog entry * Increase number of iterations * Fix parameters to avoid degeneracies and compare parameter values to those expected.
This fixes a bug that caused compound models created via
CompoundModel.without_units_for_datato be incorrect if the compound expression included*or/, because the top-level parameters were decoupled from the parameters of the constituent models (see examples in #16675). The safer route is to instantiate a newCompoundModelrather than copy and modify. Example of incorrect behavior:As you can see,
gg_nounit.left.amplitudewas actually incorrect, as it should be 5 now. This is now fixed with this PR.A more serious issue that this caused was that fitting was in fact completely broken for compound models with units and with a * or / - the fitting simply returned the same model as the original unfit one. There were several tests of the fitting which were incorrectly written and assumed the fit and unfit output should be the same, which it should not be, so I have now adjusted those tests so that they pass again.
Fixes #16675