-
Notifications
You must be signed in to change notification settings - Fork 286
Calculate, store correlated uncertainties for variable parameters for easier downstream calcs #888
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
Conversation
… variable parameters
… to serialize it fully
Codecov Report
@@ Coverage Diff @@
## master #888 +/- ##
==========================================
- Coverage 93.32% 93.25% -0.07%
==========================================
Files 10 10
Lines 3653 3679 +26
==========================================
+ Hits 3409 3431 +22
- Misses 244 248 +4
|
…ed to add derived parameters
This has now morphed a bit, but for the better, I think. All of the code to propagate uncertainties for parameters has been moved out of An example of this is given. As hinted at above, one way this might be used is to not have "derived parameters" (like It would be possible to have these or other derived parameters defined in a While we could change Docs and tests are still needed. |
Funny, I was going suggest exactly the same thing for the derived parameters when I saw the PR. |
@newville I was out of the country for a bit and catching up with work right now. But I'll take a look at this in the -hopefully- near future and comment here. |
@reneeotten Thanks, and no worries -- I got part way through this and sort of stalled, focusing on other things too. I think the "add basic uvars" could be called nearly complete, though doc/examples could be improved. I hope to get back to that next week. There is no rush! The idea of I think it would be worth adding It would be perfectly fine with me to say that "adding uvars" is a complete PR unit, and that |
@reneeotten I added tests, so I think this is ready to discuss / review. No rush, no real commitment to everything here. |
I would like to merge this and then work on other issues, including working on the whole business of "array-like inputs for Model" and the coercion of data to float64, and cleaning up many of the tests. It would be helpful to have reviews or comments on PRs, but I think we do have to be able to make progress and not have issues or PRs go too long without resolution. |
@@ -12,8 +12,7 @@ | |||
|
|||
@pytest.mark.parametrize( | |||
"value, expected_result", | |||
[(1, 1.0), (-1, -1.0), (0, tiny), (-0, -tiny), (np.array([1]), 1.0)], | |||
) | |||
[(1, 1.0), (-1, -1.0), (0, tiny), (-0, -tiny)]) |
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.
this doesn't fix a deprecation warning in the not_zero
method, it merely removes the test that triggers this warning. So unless now the test is suddenly not necessary anymore because we can never get into this situation, it doesn't really seem to fix the underlying problem - correct?
I've looked a bit at the release notes of the recent SciPy and NumPy versions and I can probably spend some time to get some of this sorted out. But as I said in previous PRs as well, just removing tests because they don't pass anymore or produce warnings doesn't look like the best approach.
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 view this as removing a test because it fails but removing a test that tests something we don't do. That is, none of the 3 uses of not_zero()
pass in an array. We're not checking the data type of the value passed to not_zero()
within the function: a string, dict, tuple, list, would also fail. It turns out that, weirdly, arrays with length=1 used to work.
There are probably 25 or more places in lineshapes.py
alone where non_zero()
could be used but is currently using val = max(tiny, val)
instead: None of those would work with anything but floats (or ints, I suppose) either.
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.
fair enough, I see that the dho
lineshape code is now indeed such that non_zero
is not used on arrays anymore. I think initially it (or some variant thereof) was used and that is why the test was there. Anyway, if the conclusion is that the test is not needed anymore, that's okay with me - at the very least then the commit message is rather misleading ;)
If you consider this PR finalized I am happy to take another look at if if you think that's helpful. However, if you're not interested in opinions and/or suggestions and just want to keep merging PRs that's also fine, but then I'll not waste any time on it. Just let me know.
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.
OK, thanks, yeah sometimes single-line commit comments are not enough, and good commit comments are hard enough anyway...
Yes, I consider this PR ready to merge.
@reneeotten OK, I'm going to merge this, and then try to resolve #900 and #875. I would like to see if #883 can get resolved too. |
Description
This adds a
uvars
attribute toModelResult
that contains the correlated uncertainties for the fitting variables using theuncertainties
package. That allows post-fit calculations using fit results to properly propagate uncertainties, including taking correlations into account.This is a work-in-progress, docs and tests needed, maybe a bit of discussion. See #887 for a bit of rationale.
Type of Changes
Tested on
Python: 3.10.10 | packaged by conda-forge | (main, Mar 24 2023, 20:17:34) [Clang 14.0.6 ]
lmfit: 1.2.1.post3+g502cc9b.d20230517, scipy: 1.10.1, numpy: 1.24.3, asteval: 0.9.29, uncertainties: 3.1.7
Verification
Have you
Many of these should be done before merging, but are not done yet.