Add robust-Poisson GLM constant background to the GPU integrator#110
Merged
Conversation
Implement the DIALS "glm constant3d" background as a single-source, device-safe function over the per-reflection histogram: Poisson pdf/cdf, Huber psi, the expectation values and the IRLS fit, reproducing dials::algorithms::RobustPoissonMean. Tests assert 1e-6 parity with DIALS reference means over hand-built histograms.
… in test_baseline_integrator
for more information, see https://pre-commit.ci
jbeilstenedmands
approved these changes
Jun 22, 2026
jbeilstenedmands
left a comment
Collaborator
There was a problem hiding this comment.
Thanks for implementing this, along with a test suite. I think this is good to go.
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.
This PR fills in the
Glmbranch that #109 reserved, adding the DIALSrobust-Poisson GLM constant background to the GPU integrator. As with
the Tukey model, the GLM core is written once as a
__host__ __device__function over the same per-reflection integer-histogram view and
compiled into both the baseline and the device, so the two paths produce
matching estimates analagous to DIALS'
glm constant3d.It reads the same histogram the Tukey model already accumulates, so
there are no new device buffers or major changes to the reduction.
Changes:
Adds
glm_constant_background()ininclude/integrator/background.hpp: an IRLS fit of a constant Poissonmean (log link) with Huber weighting, seeded from the histogram
median, reproducing
dials::algorithms::RobustPoissonMean. The tuningconstant (1.345), tolerance (1e-3), iteration cap (100) and minimum
pixel count (10) match the DIALS defaults and live alongside
NUM_BG_BINSas shared constants. Failures (too few pixels, too muchoverflow, non-convergence, or a degenerate parameter) are reported
through the
BackgroundResult::validchannel the device reductionalready uses.
Evaluates the Poisson CDF as a finite sum rather than
boost::math::gamma_q, which is exact for the integer argument hereand removes the special-function dependency on the device. High-tail
overflow pixels sit far above the upper Huber bound, so their weight
clips to
+cregardless of value, which is why the overflow countalone suffices.
Reuses the same overflow gate Tukey applies (reject when more than 25%
of a reflection's background pixels land above
NUM_BG_BINS). The GLMhas no analogue of Tukey's second, tuning-parameter-aware range guard
(
q3 + 1.5*IQR >= num_bins): the Huber weighting clips the high tailinto the score rather than fencing it against the range, so the
overflow-fraction test is its only range gate.
Dispatches the
Glmbranch in the device reduction(
integrator/background.cu) and acceptsglminparse_background_model, alongside the existingconstant/tukey.background.sum.valueismean * N, since the GLM models everybackground pixel at the fitted mean.
Adds GLM parity tests to
test_background.cc, locking the coreagainst DIALS fixture values (tight low background, a downweighted
high outlier, a clipped overflow tail, a moderate level, and the
too-few- pixels and excessive-overflow rejections). These assert to
1e-6 rather than bit-equality: the Fisher information is taken as
N * bdirectly where DIALS sumsbper pixel, equal in exact arithmeticbut differing in floating-point rounding.
Closes #96.