Skip to content

Add robust-Poisson GLM constant background to the GPU integrator#110

Merged
dimitrivlachos merged 10 commits into
mainfrom
glm
Jun 22, 2026
Merged

Add robust-Poisson GLM constant background to the GPU integrator#110
dimitrivlachos merged 10 commits into
mainfrom
glm

Conversation

@dimitrivlachos

@dimitrivlachos dimitrivlachos commented Jun 19, 2026

Copy link
Copy Markdown
Collaborator

This PR fills in the Glm branch that #109 reserved, adding the DIALS
robust-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() in
    include/integrator/background.hpp: an IRLS fit of a constant Poisson
    mean (log link) with Huber weighting, seeded from the histogram
    median, reproducing dials::algorithms::RobustPoissonMean. The tuning
    constant (1.345), tolerance (1e-3), iteration cap (100) and minimum
    pixel count (10) match the DIALS defaults and live alongside
    NUM_BG_BINS as shared constants. Failures (too few pixels, too much
    overflow, non-convergence, or a degenerate parameter) are reported
    through the BackgroundResult::valid channel the device reduction
    already uses.

  • Evaluates the Poisson CDF as a finite sum rather than
    boost::math::gamma_q, which is exact for the integer argument here
    and removes the special-function dependency on the device. High-tail
    overflow pixels sit far above the upper Huber bound, so their weight
    clips to +c regardless of value, which is why the overflow count
    alone 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 GLM
    has no analogue of Tukey's second, tuning-parameter-aware range guard
    (q3 + 1.5*IQR >= num_bins): the Huber weighting clips the high tail
    into the score rather than fencing it against the range, so the
    overflow-fraction test is its only range gate.

  • Dispatches the Glm branch in the device reduction
    (integrator/background.cu) and accepts glm in
    parse_background_model, alongside the existing constant/tukey.
    background.sum.value is mean * N, since the GLM models every
    background pixel at the fitted mean.

  • Adds GLM parity tests to test_background.cc, locking the core
    against 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 * b directly where DIALS sums b per pixel, equal in exact arithmetic
    but differing in floating-point rounding.

Closes #96.

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.
@dimitrivlachos dimitrivlachos marked this pull request as ready for review June 19, 2026 15:53

@jbeilstenedmands jbeilstenedmands left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for implementing this, along with a test suite. I think this is good to go.

@dimitrivlachos dimitrivlachos merged commit e83250a into main Jun 22, 2026
4 checks passed
@dimitrivlachos dimitrivlachos deleted the glm branch June 22, 2026 11:28
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.

Unit tests for integrator

2 participants