Skip to content

Normalise DebyeFit imaginary-part error by the loss magnitude - #871

Merged
agianno merged 1 commit into
gprMax:masterfrom
SajalDevX:fix/debyefit-imag-error-normalisation
Oct 3, 2026
Merged

agianno merged 1 commit into
gprMax:masterfrom
SajalDevX:fix/debyefit-imag-error-normalisation

Conversation

@SajalDevX

Copy link
Copy Markdown
Contributor

Normalise DebyeFit imaginary-part error by |e''| + 1

Fixes #870

Relaxation.error() and plot_result() divided the imaginary-part residual by self.im + 1. self.im is stored as -e'' (e' - je'' convention) for all relaxation functions, so the denominator was really 1 - 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 raised FloatingPointError if 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 in Debye_Fit.py, the search picked 7 poles instead of 3.

Changes

  • gprMax/toolboxes/DebyeFit/Debye_Fit.py: divide by np.abs(self.im) + 1 in error() and in the relative-error plot in plot_result(). This matches the self.rl + 1 normalisation already used for the real part.
  • tests/toolboxes/test_debye_fit.py: add a regression test that calls error() with e'' = 0.5, 1 and 2 and a 0.01 residual. It checks that the result is finite and equals the mean of 0.01 / (1 + |e''|).

Testing

  • python -m pytest tests/toolboxes/test_debye_fit.py: before the fix, the new test fails with FloatingPointError: divide by zero encountered in divide. After the fix, all 11 tests pass.
  • I ran the Kelley example (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.
  • I ran black and isort with the pre-commit settings on the changed lines. The remaining black/isort warnings in test_debye_fit.py were already on master, so I left them alone.

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.
@agianno
agianno merged commit 0b54f2e into gprMax:master Oct 3, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DebyeFit imaginary-part error divides by 1 - e'', so it blows up near e'' = 1 and the auto pole search picks too many poles

2 participants