Merge branch 'd-chi2-gate' into rc172-2

This commit is contained in:
leonarski_f committed 2026-09-20 20:00:06 +02:00
commit b74a922fc0
2 files changed
+43 -1

No files matched your search

@@ -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
@@ -481,6 +481,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