cluster_analysis: raise on fractal dimension of degenerate cluster (bug-sweep #45)#5370
Draft
RudolfWeeber wants to merge 1 commit into
Draft
Conversation
…ug-sweep #45) Cluster::fractal_dimension fits a line through (log diameter, log particle count) points accumulated over radial shells. A 2-particle cluster (the normal minimum of pair-based clustering) yields at most one such point: with dr=0 the loop appends a single point, and with dr large enough that no second shell forms, no points are appended at all. Passing n<2 points to gsl_fit_linear, together with the residual division by log_diameters.size() (which is zero when the vector is empty), produced a silent [NaN, NaN] result with no diagnostic. The fractal dimension is mathematically undefined for fewer than two radial shells, so fabricating a value is wrong. Prevent the degenerate input by raising a clear std::runtime_error (surfacing to Python as RuntimeError via the script-interface dispatch, matching the existing sanity_checks() and no-GSL conventions) before calling gsl_fit_linear. Adds testsuite/python/cluster_analysis.py coverage that a 2-particle cluster raises RuntimeError for both dr=0 and a large dr. Co-Authored-By: Claude Opus 4.8 <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.
Cluster::fractal_dimension fits a line through (log diameter, log particle
count) points accumulated over radial shells. A 2-particle cluster (the
normal minimum of pair-based clustering) yields at most one such point:
with dr=0 the loop appends a single point, and with dr large enough that
no second shell forms, no points are appended at all. Passing n<2 points
to gsl_fit_linear, together with the residual division by
log_diameters.size() (which is zero when the vector is empty), produced a
silent [NaN, NaN] result with no diagnostic.
The fractal dimension is mathematically undefined for fewer than two
radial shells, so fabricating a value is wrong. Prevent the degenerate
input by raising a clear std::runtime_error (surfacing to Python as
RuntimeError via the script-interface dispatch, matching the existing
sanity_checks() and no-GSL conventions) before calling gsl_fit_linear.
Adds testsuite/python/cluster_analysis.py coverage that a 2-particle
cluster raises RuntimeError for both dr=0 and a large dr.
Co-Authored-By: Claude Opus 4.8 noreply@anthropic.com
🤖 Generated with Claude Code