Rotation merge: outlier band multiplicative in the error model's b term
The 6-sigma outlier band was symmetric in I about the reflection's median, while the error model's systematic term b*<I> is a multiplicative error (absorption, illuminated volume, a scale that is off), as likely a factor 1/f as f. With b of a few percent the two agree; with a large b the linear band reaches far below the median and only a little above it. On a strongly absorbing cubic crystal (internal b = 0.34) 96% of the 828 rejected fulls read 2-7x their median in well-illuminated frames - the least absorbed, nearest the true intensity - and almost none read low. The b part of the band is now exp(+-n*b) about the expected intensity, the counting part stays linear (OutlierBand.h, one formula for the host loop and the device kernel; the two exp constants are taken once on the host). To first order in n*b it is the old band. That set's SHELXL R1 0.116 -> 0.103 (--reject-outliers 12 / 20 on the old band: 0.107 / 0.101; no rejection at all: 0.31). Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01K5K8jvPPbmCrbqnWkddTuB
This commit is contained in:
1 parent
b126b9fc15
commit
a012a0b5cb
3 files changed
+52
-5
No files matched your search
@@ -0,0 +1,37 @@
|
||||
// SPDX-FileCopyrightText: 2026 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
#pragma once
|
||||
|
||||
// The merge's outlier test (MergeAndStats and its device twin MergeAccumKernel): is a full outside the
|
||||
// band its reflection's median and the error model allow? Written once for both, so they read the same
|
||||
// formula.
|
||||
//
|
||||
// The error model's systematic term b*<I> is a MULTIPLICATIVE error - absorption, the illuminated
|
||||
// volume, a scale that is off - and a factor is as likely to be 1/f as f. A band of +-n*sigma about the
|
||||
// median is symmetric in I instead: with b of a few percent the two agree, but where b is large the
|
||||
// linear band reaches far below the median and only a little above it. On a strongly absorbing crystal
|
||||
// (b = 0.34) every full the test removed read 2-7x its median - the least absorbed fulls, the ones
|
||||
// nearest the true intensity - and none read low, so the merged intensities were cut from above only.
|
||||
// Here the multiplicative part of the band is exp(+-n*b) about the expected intensity, which is the
|
||||
// linear band to first order in n*b, and the counting part stays linear.
|
||||
// up = exp(n*b) - 1 and down = 1 - exp(-n*b) are per-merge constants, taken on the host and handed to
|
||||
// the device, so that both sides compute them from the same library call.
|
||||
|
||||
#include <cmath>
|
||||
|
||||
#ifdef __CUDACC__
|
||||
#define OUTLIER_BAND_HD __host__ __device__ inline
|
||||
#else
|
||||
#define OUTLIER_BAND_HD inline
|
||||
#endif
|
||||
|
||||
// I: the full's intensity; median: its reflection's outlier-test median; var: the full's variance under
|
||||
// the error model plus any added variance; b_I: the multiplicative part of that sigma, b * I_expected.
|
||||
OUTLIER_BAND_HD bool OutsideOutlierBand(double I, double median, double nsigma, double var, double I_expected,
|
||||
double b_I, double up, double down) {
|
||||
const double count_var = var - b_I * b_I > 0.0 ? var - b_I * b_I : 0.0;
|
||||
const double n2c = nsigma * nsigma * count_var;
|
||||
const double hi = I_expected * up, lo = I_expected * down;
|
||||
return I - median > sqrt(n2c + hi * hi) || median - I > sqrt(n2c + lo * lo);
|
||||
}
|
||||
@@ -25,6 +25,7 @@
|
||||
#include "FrenchWilson.h"
|
||||
#include "ResolutionCutoff.h"
|
||||
#include "WilsonOutliers.h"
|
||||
#include "OutlierBand.h"
|
||||
#include "../../common/CorrelationCoefficient.h"
|
||||
#include "../../common/CrystalLattice.h"
|
||||
#include "../../common/Definitions.h"
|
||||
@@ -4981,6 +4982,9 @@ RotationScaleMerge::Result RotationScaleMerge::MergeAndStats(int n_groups, bool
|
||||
did_gpu_acc = true;
|
||||
}
|
||||
#endif
|
||||
// The multiplicative part of the outlier band (OutlierBand.h), from the error model as it stands.
|
||||
const double reject_up = std::expm1(reject_nsigma * error_model_b);
|
||||
const double reject_down = -std::expm1(-reject_nsigma * error_model_b);
|
||||
if (!did_gpu_acc)
|
||||
for (const auto &o : fulls) {
|
||||
if (!usable_merge(o)) continue;
|
||||
@@ -4994,9 +4998,10 @@ RotationScaleMerge::Result RotationScaleMerge::MergeAndStats(int n_groups, bool
|
||||
if (reject_outliers && error_model_active && std::isfinite(reject_median[o.group])) {
|
||||
// The pooled pair, widened by the shell's measured anomalous variance.
|
||||
const double v_add = reject_var_add.empty() ? 0.0 : reject_var_add[o.group];
|
||||
const double tol = reject_nsigma
|
||||
* std::sqrt(static_cast<double>(sigma_corr) * sigma_corr + v_add);
|
||||
if (std::fabs(I_corr - reject_median[o.group]) > tol) {
|
||||
const double I_b = std::isfinite(em_mean[o.group]) ? em_mean[o.group] : I_corr;
|
||||
if (OutsideOutlierBand(I_corr, reject_median[o.group], reject_nsigma,
|
||||
static_cast<double>(sigma_corr) * sigma_corr + v_add, I_b,
|
||||
error_model_b * I_b, reject_up, reject_down)) {
|
||||
++reject_count;
|
||||
rejected_obs[&o - fulls.data()] = 1;
|
||||
continue;
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
#include "RotationScaleMergeGPU.h"
|
||||
#include "OutlierBand.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <chrono>
|
||||
@@ -461,6 +462,7 @@ namespace {
|
||||
struct MergeParams {
|
||||
int n_groups;
|
||||
double min_partiality, error_model_a, error_model_b, reject_nsigma;
|
||||
double reject_up, reject_down; // the multiplicative part of the outlier band (OutlierBand.h)
|
||||
int for_search, error_model_active, reject_outliers;
|
||||
const float *I, *sigma, *corr, *partiality, *d, *reject_median, *var_bkg, *var_per_I, *capture;
|
||||
const float *reject_var_add; // per group: the shell's measured share of dI^2/4
|
||||
@@ -593,8 +595,9 @@ namespace {
|
||||
? ModelSigma(i, p, isfinite(p.em_mean[g]) ? p.em_mean[g] : double(I_corr), sigma_raw)
|
||||
: sigma_raw;
|
||||
if (p.reject_outliers && p.error_model_active && isfinite(rmed)) {
|
||||
const double tol = p.reject_nsigma * sqrt(double(sigma_corr) * sigma_corr + v_add);
|
||||
if (fabs(double(I_corr) - rmed) > tol) {
|
||||
const double I_b = isfinite(p.em_mean[g]) ? p.em_mean[g] : double(I_corr);
|
||||
if (OutsideOutlierBand(I_corr, rmed, p.reject_nsigma, double(sigma_corr) * sigma_corr + v_add,
|
||||
I_b, p.error_model_b * I_b, p.reject_up, p.reject_down)) {
|
||||
++rejected; p.rejected_obs[i] = 1; continue;
|
||||
}
|
||||
}
|
||||
@@ -1222,6 +1225,8 @@ void RotationScaleMergeGPU::MergeAccum(double error_model_a, double error_model_
|
||||
p.error_model_a = error_model_a; p.error_model_b = error_model_b;
|
||||
p.error_model_active = error_model_active ? 1 : 0;
|
||||
p.reject_outliers = reject_outliers ? 1 : 0; p.reject_nsigma = reject_nsigma;
|
||||
p.reject_up = std::expm1(reject_nsigma * error_model_b);
|
||||
p.reject_down = -std::expm1(-reject_nsigma * error_model_b);
|
||||
p.reject_median = d.reject_median.get();
|
||||
p.reject_var_add = d.reject_var_add.get();
|
||||
p.I = d.f_I.get(); p.sigma = d.f_sigma.get(); p.corr = d.f_corr.get(); p.partiality = d.f_partiality.get();
|
||||
|
||||
Reference in new issue
Block a user