Fix InfixFormatter coefficient precision loss on model output - #176
Merged
Conversation
Fixed-point {:.6f} silently rounded coefficients below ~5e-7 to
0.000000, producing genuine division-by-zero when independent tooling
re-parses the printed model. Switch to general/%g-style formatting at
max_digits10 (round-trip-exact); found via 0.17% of the already-published
production matrix reporting "feasible" for numerically non-finite models.
…branches were still fixed-point, missed in the initial pass; also fix the two remaining hardcoded-6 call sites.
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.
Summary
The
InfixFormatterclass printed coefficients at a fixed 6-decimal precision ({:.6f}), which silently rounds any coefficient below roughly 5e-7 to0.000000. A caller that re-parses the printed model text gets a different model back: a tiny, load-bearing coefficient (for example in a divisor) becomes a literal zero.Fix: switch coefficient formatting from fixed-point to general (
%g-style) notation, and standardize every call site onstd::numeric_limits<Operon::Scalar>::max_digits10, the minimum digit count that round-trips afloatexactly. This replaces a mix of hardcoded6,digits10(insufficient for round-trip), anddigits(correct but needlessly verbose) acrossoperon_gp.cpp,operon_nsgp.cpp,operon_enum.cpp,pareto_front.cpp,operon_parse_model.cpp, andcustom_primitives.cpp.Test plan
-0.000000now prints as-0.000000761; re-parsing the corrected text produces finite predictions instead of an all-non-finite error.