Repository navigation
Normalise DebyeFit imaginary-part error by the loss magnitude - #871
Merged
agianno merged 1 commit intoOct 3, 2026
Merged
Conversation
Relaxation.error() and plot_result() divided the imaginary-part residual by (self.im + 1). The imaginary part of every relaxation function is stored with the e' - je'' sign convention, so self.im is negative and the denominator is 1 - e''. It goes to zero where the loss reaches 1 and turns negative above it, so the reported imaginary-part error blows up (or raises FloatingPointError, since gprMax sets numpy divide errors to raise) even when the fit is close. Because the automatic pole search (number_of_debye_poles=-1) stops on this error, the inflated value also made it pick more poles than needed: the Kelley Havriliak-Negami example in Debye_Fit.py picks 7 poles instead of 3. Divide by |e''| + 1 instead, matching the rl + 1 normalisation used for the real part.
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.
Normalise DebyeFit imaginary-part error by |e''| + 1
Fixes #870
Relaxation.error()andplot_result()divided the imaginary-part residual byself.im + 1.self.imis stored as -e'' (e' - je'' convention) for all relaxation functions, so the denominator was really1 - e''. It hits zero where the loss reaches 1 and goes negative above that. As a result, the reported imaginary error blew up near e'' = 1. It raisedFloatingPointErrorif a grid point had e'' exactly 1, because gprMax sets numpy divide errors to raise. It also made the automatic pole search (number_of_debye_poles=-1) choose more poles than needed. For the Kelley Havriliak-Negami example inDebye_Fit.py, the search picked 7 poles instead of 3.Changes
gprMax/toolboxes/DebyeFit/Debye_Fit.py: divide bynp.abs(self.im) + 1inerror()and in the relative-error plot inplot_result(). This matches theself.rl + 1normalisation already used for the real part.tests/toolboxes/test_debye_fit.py: add a regression test that callserror()with e'' = 0.5, 1 and 2 and a 0.01 residual. It checks that the result is finite and equals the mean of0.01 / (1 + |e''|).Testing
python -m pytest tests/toolboxes/test_debye_fit.py: before the fix, the new test fails withFloatingPointError: divide by zero encountered in divide. After the fix, all 11 tests pass.HavriliakNegami(f_min=1e7, f_max=1e11, alpha=0.91, beta=0.45, e_inf=2.7, de=5.9, tau_0=9.4e-10, f_n=50, number_of_debye_poles=-1, optimizer_options={"seed": 111})). The auto pole search now picks 3 poles, compared with 7 on master.blackandisortwith the pre-commit settings on the changed lines. The remaining black/isort warnings intest_debye_fit.pywere already on master, so I left them alone.