Repository navigation
Fix binary_intercept and fit_line validation on unbounded search - #1141
Open
davrens101 wants to merge 1 commit into
Open
davrens101 wants to merge 1 commit into
davrens101 wants to merge 1 commit into
Conversation
Signed-off-by: Davis Rens <166565828+davrens101@users.noreply.github.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.
Summary of Changes
In
sinter._probability_util:binary_interceptdid not caststepto float before doubling it inwhile ...: step *= 2. Whenstepis passed as an integer (e.g.,-1or1infit_line_slopeandfit_line_y_at_x), repeated doubling grows arbitrarily large as a Python arbitrary-precision integer rather than overflowing tofloat('inf'). When passed tonp.isinf(step), NumPy 2.x raises:Furthermore, evaluating
func(start_x + step)with massive values can raiseOverflowError: (34, 'Result too large')before reaching the termination condition.Fix: Cast
step = float(step)somath.isinf(step)cleanly catches float overflow, and catchOverflowErrorduring evaluation to raiseValueError("Failed.")as intended when no intercept exists.In
fit_line_slopeandfit_line_y_at_x,max_extra_squared_errormust be non-negative. A negative value causestarget_y = base_cost + max_extra_squared_error < base_cost. Becausebase_costis the global minimum of the sum of squared errors,target_ycan never be achieved, causing an infinite doubling loop. Added input validation checkingmax_extra_squared_error >= 0.Before
After
Unit tests added to
_probability_util_test.pyverifying the validation and failure conditions.