Repository navigation
Accept CRIM volumetric fractions that sum to one within rounding - #868
Merged
Merged
Conversation
Crim.check_inputs() compared np.sum(volumetric_fractions) to 1 with an exact float equality, so valid mixtures such as [0.7, 0.2, 0.1] or [0.6, 0.3, 0.1] (which sum to 0.9999999999999999 in binary floating point) were rejected and the fit exited with "The summation of volumetric volumes should be equal to 1". Compare the sum against 1 with a small absolute tolerance (1e-9) instead, which absorbs floating-point rounding while still rejecting fractions that genuinely do not add up to one. Add regression tests for both cases.
Member
|
Thanks for finding this float comparison and fixing it. Once tests pass will merge into master. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix CRIM volumetric-fraction sum check in DebyeFit
Crim.check_inputs()comparednp.sum(volumetric_fractions)to1with exact float equality. Because of that, valid mixtures like[0.7, 0.2, 0.1]or[0.6, 0.3, 0.1](both sum to0.9999999999999999) were rejected, and the fit exited with "The summation of volumetric volumes should be equal to 1". Whether a mixture passed could depend only on the order of the fractions:[0.1, 0.2, 0.7]passed but[0.7, 0.2, 0.1]failed.Changes
gprMax/toolboxes/DebyeFit/Debye_Fit.py: compare the sum to 1 withnp.isclose(..., rtol=0.0, atol=1e-9)instead of!=. This allows for rounding error but still rejects fractions that really don't add up to one.tests/toolboxes/test_debye_fit.py: add regression tests. One checks that fractions summing to 1 within rounding are accepted. The other checks that fractions that don't sum to 1 ([0.7, 0.2, 0.2],[0.5, 0.3, 0.1]) are still rejected.Testing
python -m pytest tests/toolboxes/test_debye_fit.py: before the fix, the two new "accepts" cases fail withSystemExit. After the fix, all 10 tests pass.Crim(...).run()with[0.7, 0.2, 0.1]. It now finishes and prints the#material/#add_dispersion_debyecommands.blackandisort(repo pre-commit settings) on the changed lines. The only remaining warnings intest_debye_fit.pywere already on master, and I left them alone to keep the diff small.Fixes #867