Conversation
With sparse or poorly-distributed crossings, -Ed/-Et can silently return a per-track offset many times larger than the crossover-error scale, corrupting the corrected signal instead of fixing it (residuals still look fine since the fit technically "closes"). Add a warning naming the affected track and how unstable it is, and an opt-in -E<mode>+r[<K>] modifier that ridge-regularizes the solve so poorly-constrained tracks fall back towards a plain offset instead of blowing up, while barely touching well-constrained ones. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Parse +r with gmt_validate_modifiers/gmt_get_modifier instead of strstr, so a mistyped modifier (e.g. -Ed+R) is reported instead of silently falling through to the unregularized solve. Also guard the "unnormalize slopes" step with R[p] > 1: for a track with a single crossing that index is the next track's offset, which got divided by the normalization range and effectively zeroed. It also masked the new instability warning for exactly those tracks. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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.
Description of proposed changes
x2sys_solve -Ed(or-Et) can return per-track offsets hundreds of metres in size on a survey only a few hundred metres deep. Applying that correction table doesn't clean the data, it destroys it — and nothing warns you, since the crossover residuals stay small and the fit still looks fine.The cause is conditioning, not a coding error: these models fit two parameters per track, and when a track's crossings are few or clustered together, the offset is barely constrained, so least squares is free to return a huge value that still satisfies the crossovers.
This PR adds:
-E<mode>+r[<K>]modifier for-Ed/-Etthat ridge-regularizes the solve, pulling poorly-constrained tracks back towards a plain offset while leaving well-constrained ones alone. DefaultK = 10; smallerKdamps harder.Implementation notes
Standard Tikhonov/ridge fix: before the
gmt_gaussjordansolve, addlambdato the diagonal ofNfor each real unknown (not the Lagrange rows enforcing the per-cluster offset-sum-to-zero gauge):Scaling to the mean diagonal keeps it invariant to data/weight units.
Kis a trust multiplier on |offset| relative to the pre-correction COE st.dev., default 10; smallerKdamps harder. Well-constrained tracks (N[i][i] >> lambda) are essentially unaffected.Done with Sonnet 5 and reviewed with Opus 5
Tested with
I personally tested it with my own data, and it works fine. Below is the script to test it with synthetic data.
Full script:
Nine of the thirteen tracks are flagged by the new warning, e.g.: