Repository navigation
Allow fitting of a wider range of compound models - #10415
Conversation
|
@karllark The fitted scale parameter in |
|
I've run into this problem before. And never found the solution though I did do a fairly deep dive. What are the differences you are seeing? I remember they were not large, but larger than expected for numerical precision. I've solved this problem for tests by changing the tolerance allowed for the test comparison. |
|
I've tried my problem and am now getting a different error. Likely this error is due to my not setting up my attenuation model correctly.
And here is the ` |
|
The values of the scale parameter on Linux vs MacOSX are 5.821110 vs 3.795289, so too large. |
|
In order to fit a model with units you need to write a method called |
Can I be cheeky and ask if there are docs for this or a good example you could point me to? |
|
And using the I wonder if the problem is in the numerical derivative implementation that's used by the |
|
The differences in results is a bit scary. Admittedly, the data is very simple and the model may not be well constrained. But it surprising that it is not repeatable between types of computers given the same fitter. |
|
Let me know if you think more explanation is needed in the documentation than what's on the bottom of this page |
|
Results of fitting a |
How do I specify that |
|
I did this and the fitting works for my case! This is awesome! |
|
Are the results correct? |
Not sure. Checking right now. Converting to units has changed things. Check done. The fitting is returning results that don't make sense. Almost like it didn't update any of the input values. And I get the following for
|
|
What happens if you use the Simplex fitter - |
|
Doesn't work with SimplexLSQFitter. Different error.
|
|
Let's move this to slack next week. |
|
The difference in the results on the two platforms may be due to an ill-conditioned model. I need to do some more verification with that model specifically, however if that's the case there's no guarantee we should get identical results. Regardless the principle issue here with handling the fitting of compound models is solved and I think this should be merged if approved. |
|
Possibly a new issue was identified in this comment. Will follow up on it separately. |
|
Did anyone do a plot vs the data for the two different fits on the two platforms? And do the corresponding plots for the solution on the other platform on the one that disagrees? In other words, such plots should definitively show whether there is an error in evaluation vs being poorly conditioned (the latter being confirmed by both sets of parameters showing good visual fits). Or is that not possible? |
perrygreenfield
left a comment
There was a problem hiding this comment.
Looks good except for the docstring.
As far as the blackbody inconsistency, try more points over a broader spectral range and see if that improves consistency.
| @@ -1323,13 +1323,6 @@ def without_units_for_data(self, **kwargs): | |||
| For compound models this will only work when the expression only | |||
| involves the addition or subtraction operators. | |||
| """ | |||
There was a problem hiding this comment.
The docstring should have a corresponding removal of the restriction
Allow more types of compound models t obe fitted.
Allow fitting of a wider range of compound models
Allow fitting of a wider range of compound models
| with NumpyRNGContext(12345): | ||
| n = np.random.normal(3) | ||
|
|
||
| y = model(x) | ||
| res = fitter(model, x, y * (1 + n)) | ||
| # The large rtol here is due to different results on linux and macosx, likely | ||
| # the model is ill-conditioned. | ||
| np.testing.assert_allclose(res.parameters, [3000, 2.1433621e+00, 2.647347e+00], rtol=0.4) |
There was a problem hiding this comment.
I don't fully understand this model's construction, but it certainly looks ill-conditioned.
I. model is simply multiplying a BlackBody of default scale=1.0 with another constant of 1.0, so scale and amplitude are fully degenerate, right?
II. np.random.normal(3) just creates a single value in the vicinity of 3.0, which for the given seed always evaluates to 2.795292 (on macOS with numpy 1.26.2). So this whole construct just seems a very complicated way of applying an extra factor of 3.795292 to the input blackbody.
That said I cannot seem to get the fitter to adjust any parameters of such a mixture model at all.
Fixes #10414