Repository navigation
fix: give points with invalid uncertainties no weight instead of dropping all uncertainties or making the residual infinite - #242
Conversation
…nd warn when profileparse drops dy
|
@sbillinge ready for review |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #242 +/- ##
==========================================
- Coverage 84.95% 82.33% -2.63%
==========================================
Files 44 47 +3
Lines 4886 5542 +656
==========================================
+ Hits 4151 4563 +412
- Misses 735 979 +244
🚀 New features to boost your workflow:
|
FitContribution and warn in Profile|
okay this is ready for review again |
|
wow, I love this new way of doing it. Have Claude write all the test cases in more easily accessible and human-readable form. Let's make that a new group standard. That was so easy to follow. The only problem is that I didn't then check (a) whether the test was correctly implemented (I trusted Claude) nor (b) whether any other code was implemented that was not covered by that test. (trusted Claude on that too). But I can check both things in principle. It is a good approach to have Claude do this |
|
@sbillinge Yeah I still do a pretty thorough review of the tests it writes to be safe and sure. I'd say the tests are good 97% of the time where the other 3% are unnecessary. I tried to get agents to do all that review for me but it burns through tokens lol... |
What problem does this PR address?
A point whose uncertainty is zero, negative, infinite or NaN now gets no weight in a fit. Before,
ProfileParserdropped the whole dy column and weighted every point equally, andProfile.set_observed_profilegave an infinite residual. If no point in the fit range has a valid uncertainty, the fit is weighted equally, as for data with no uncertainties.FitResultssays how many points have no weight and leaves them out of Chi2, Reduced Chi2 and Rw.Case 1: some uncertainties are valid
Before:
ProfileParserdropped the whole dy column because of the two zeros, so all 10 points were weighted equally, without a warning.set_observed_profilekept the zeros, so the residual was infinite at those points andleast_squaresstopped withValueError: Residuals are not finite in the initial point.After: The two points with σ = 0 get no weight. The other eight are fitted with their σ, and the results say how many points have no weight.
Case 2: no uncertainty is valid
Before:
ProfileParserdropped the dy column, so the points were weighted equally.set_observed_profilekept the zeros, so the residual was infinite everywhere andleast_squaresstopped withValueError: Residuals are not finite in the initial point.After: Data loaded with
ProfileParserbehave as before. Data set withset_observed_profilenow fit with equal weights instead of stopping with an error, the same as for data with no dy column, and the existing note says the uncertainties are missing.Case 3: all uncertainties in the fit range are valid
The data are the same as case 1, with the points with σ = 0 cut off:
Before:
ProfileParserhad already dropped the whole dy column, so the eight points in the range were weighted equally even though all their σ were valid.set_observed_profilegave a normal weighted fit.After: Data loaded with
ProfileParsernow give a normal weighted fit. Data set withset_observed_profilebehave as before. The results are identical to case 1, because points with no weight count as if they weren't in the data.Case 4: no uncertainty in the fit range is valid
The data are the same as case 1, but the fit range covers only the points with σ = 0:
Before:
ProfileParserhad dropped the dy column, so the points were weighted equally.set_observed_profilekept the zeros, soleast_squaresstopped withValueError: Residuals are not finite in the initial point.After: Behaves as case 2. Only the uncertainties inside the fit range count, so the points are weighted equally (
profile.dyis[1, 1]), and the results say the uncertainties are missing. Settingxmin=7.0instead brings in a point with a valid σ, so it behaves as case 1.