Repository navigation
Fix sample sorting algorithms - #261
Merged
Merged
Conversation
yoelcortes
approved these changes
Oct 11, 2026
yoelcortes
left a comment
Member
There was a problem hiding this comment.
Thanks for the improvements. Reading the code, it looks straight forward. But just to make sure, I also checked the outputs with the old version and they match.
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.
Model.load_samples(samples)sorts samples with a nearest-neighbour walk over the coupled-parameter columns. Two inputs made that sort crash.sort=Falseavoided both.1. Samples that share the same coupled-parameter values
Raised
AssertionError: issue in sorting algorithm(orKeyError) when several samples have identical values for all coupled parameters and differ only in isolated parameters. Morris and Sobol designs produce many such samples. I saw it with Morris N >= 20 and Sobol N = 256, on models with 6 to 11 parameters of which 1 to 3 are coupled.Cause: the walk assumed
argsortputs each row itself at position 0 of its neighbour list, and scanned from position 1. With ties at distance 0, another duplicate can land at position 0 and is never considered. If it is the last remaining sample, the loop makes no progress and the assertion fires. The initial step (nearest_arr[0, 1]) had the same flaw and could pick row 0 itself, raisingKeyError.Fix:
remaining, so this is safe.2. A coupled parameter that is constant across all samples
Raised
FloatingPointError(when numpy errors are set to raise; otherwise the distances became NaN). The column has zero range, so normalizing(samples - min) / (max - min)divided by zero.Fix: replace zero ranges with 1 before normalizing, so a constant column normalizes to zeros.
The result is still a greedy nearest-neighbour path.