From 44777a6f1a6a65f56850db635be8a45408b2641a Mon Sep 17 00:00:00 2001 From: Filip Leonarski Date: Sun, 20 Sep 2026 19:59:01 +0200 Subject: [PATCH] Bound the merge chi^2 ratio at its good end as well as its bad one The point-group consistency gate refuses a promotion whose merged reduced chi^2 exceeds max_merge_chi2_ratio times the best subgroup's. A merged reduced chi^2 decomposes as a^2 + b^2<(I/sigma)^2>: a measurement part a fitted error model pins near 1, plus a systematic part. The ratio is meant to compare the systematic parts, but it divides by the total, so the allowance it grants is (ratio - 1) x (a^2 + b_ref^2<(I/sigma)^2>). On a reference merge that is cleanly scaled the systematic term vanishes and only the fixed a^2 term is left, which makes the "ratio" an absolute bound on the added disagreement scaled by the crystal's own <(I/sigma)^2> - so the better the data are measured, the harsher the gate, and a crystal is refused for the cleanliness of its own reference merge. Measured on one crystal collected twice at two resolutions: the added operators cost the same absolute chi^2 (+1.16 and +1.07) and the same systematic b (0.080 and 0.074) both times, but the cleaner reference (chi2_ref 1.21 against 1.44) turned that into 1.96x against 1.74x, and only the better-measured of the two was refused its centred orthorhombic group - which merges to higher completeness, higher multiplicity, higher I/sigma, lower R_meas and higher CC1/2 than the monoclinic subgroup it was held in. So below chi2_ref_informative the ratio is not read. The reference has no systematic error to be a denominator, and the candidate is judged on the absolute form of the same question instead, against the standard chi2_ref_reliable already sets: the merge under it must itself look calibrated. That keeps the degenerate case the ratio read correctly - a noiseless reference against a false operator whose own merged chi^2 is in the thousands - and leaves the H and added-operator-R gates untouched as the necessary conditions no abstention can lift. max_merge_chi2_ratio is unchanged. Co-Authored-By: Claude Opus 5 (1M context) Claude-Session: https://claude.ai/code/session_013nW6FNRP1bBJJ8pfHiByAT --- .../scale_merge/SearchSpaceGroup.cpp | 21 ++++++++++++++++- image_analysis/scale_merge/SearchSpaceGroup.h | 23 +++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/image_analysis/scale_merge/SearchSpaceGroup.cpp b/image_analysis/scale_merge/SearchSpaceGroup.cpp index df62dfde0..8b817a44e 100644 --- a/image_analysis/scale_merge/SearchSpaceGroup.cpp +++ b/image_analysis/scale_merge/SearchSpaceGroup.cpp @@ -1505,6 +1505,23 @@ SearchSpaceGroupResult SearchSpaceGroup( const PointGroupInfo* best_pg = nullptr; int best_pg_order = 0; double best_pg_min_cc = -2.0; + // The chi^2 ratio compares two merges' systematic error but divides by their total, so it only + // measures a ratio where the reference merge HAS systematic error to be the denominator. Once + // chi2_ref falls to the measurement floor a fitted error model pins it at, the bound is an + // absolute one on the added disagreement, scaled by the crystal's own <(I/sigma)^2> - and the + // better the data, the harsher it gets. See chi2_ref_informative for the derivation and the + // controlled pair it was measured on. Both ends of the statistic are now bounded: above + // chi2_ref_reliable the sigmas are too wrong for it, below this they are too right. + // + // Abstaining is not the same as waving the candidate through: where the reference has no + // systematic error to be a denominator, the candidate is judged on the ABSOLUTE standard instead + // of a relative one, and it is the same standard chi2_ref_reliable already sets for the reference + // - the merge under it must itself look like a calibrated one. That keeps the case the ratio was + // reading correctly all along: a reference that merges with no scatter at all (chi2_ref ~ 0, which + // is where a ratio is most meaningless) against a false operator whose own merged chi^2 is in the + // thousands. Only a candidate that merges like a real dataset is let past. + const bool chi2_ratio_uninformative = + std::isfinite(chi2_ref) && chi2_ref < opt.chi2_ref_informative; for (auto& c : pg_cands) { // A genuine symmetry operator merges equivalent reflections, so it barely changes the reduced // chi^2 relative to the best subgroup - across the whole rotation-test battery every correct @@ -1516,7 +1533,9 @@ SearchSpaceGroupResult SearchSpaceGroup( // weakness; the variance-floor fix removed that inflation, and the widening now only let the // twin through, so it is gone.) bool consistent = c.pg->rotations.empty() || !std::isfinite(c.chi2) || - !std::isfinite(chi2_ref) || c.chi2 <= chi2_ref * opt.max_merge_chi2_ratio; + !std::isfinite(chi2_ref) || + (chi2_ratio_uninformative && c.chi2 <= opt.chi2_ref_reliable) || + c.chi2 <= chi2_ref * opt.max_merge_chi2_ratio; // Systematic-error test vs the largest confirmed subgroup (by rotation-set inclusion): merging // under a genuine operator gains multiplicity without intensity-proportional disagreement, so the diff --git a/image_analysis/scale_merge/SearchSpaceGroup.h b/image_analysis/scale_merge/SearchSpaceGroup.h index c02478a8a..5f43761dd 100644 --- a/image_analysis/scale_merge/SearchSpaceGroup.h +++ b/image_analysis/scale_merge/SearchSpaceGroup.h @@ -476,6 +476,29 @@ struct SearchSpaceGroupOptions { // against a twin: both are necessary conditions no rescue can lift. double chi2_ref_reliable = 3.0; + // The other end of the same statistic, where it also stops meaning anything. A merged reduced + // chi^2 decomposes as chi2 = a^2 + b^2 <(I/sigma)^2>: a measurement part, which a fitted error + // model pins at ~1 for every crystal, plus a systematic part b^2<(I/sigma)^2>. The ratio + // chi2_cand / chi2_ref is meant to compare the SYSTEMATIC parts - how much intensity-proportional + // disagreement the added operators bring, against how much the reference merge already carries - + // but it divides by the total. Expanding the bound, a promotion is allowed added variance + // (ratio - 1) x (a^2 + b_ref^2<(I/sigma)^2>): the second term is the intended relative allowance, + // the first is a fixed one that has nothing to do with the crystal. Where the reference merge is + // cleanly scaled its systematic part goes to zero, the fixed term is all that is left, and the + // "ratio" is really an absolute bound on b_added^2<(I/sigma)^2> - so the same real degradation + // reads larger the better the data are measured, and a crystal is refused for the cleanliness of + // its own reference merge. Measured on one crystal collected twice: the added operators cost the + // same absolute chi^2 both times (+1.16 and +1.07) and the same systematic b (0.080 and 0.074), + // but the cleaner reference (chi2_ref 1.21 against 1.44) turned that into 1.96x against 1.74x, and + // only the cleaner merge was refused. So below this chi2_ref the ratio is not read at all. The + // value is where the two parts of chi2_ref are equal - systematic content matching measurement + // content, a^2 ~ 1 plus as much again - not a level tuned to any dataset. The b test is NOT the + // fallback here as it is under chi2_ref_reliable: it divides by the reference's own b and fails in + // exactly the same way. What replaces the ratio is the ABSOLUTE form of the same question, + // against chi2_ref_reliable: the merge under the candidate must itself look calibrated. The H and + // added-operator-R gates still apply on top, as necessary conditions no rescue can lift. + double chi2_ref_informative = 2.0; + // Adopt this space group's point group instead of the one Stage A would choose, and go straight to // Stage B with it. Used when one merge decides the point group and a different merge has to decide // the absences: a caller cannot pass the point group by name, because gemmi reports both P321 and