Skip to content

cluster_analysis: raise on fractal dimension of degenerate cluster (bug-sweep #45)#5370

Draft
RudolfWeeber wants to merge 1 commit into
espressomd:pythonfrom
RudolfWeeber:fix/bug-45-fractaldim-small-cluster
Draft

cluster_analysis: raise on fractal dimension of degenerate cluster (bug-sweep #45)#5370
RudolfWeeber wants to merge 1 commit into
espressomd:pythonfrom
RudolfWeeber:fix/bug-45-fractaldim-small-cluster

Conversation

@RudolfWeeber

Copy link
Copy Markdown
Contributor

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

…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant