Skip to content

fitter = "super" for pooled logistic regression (plr), a faster plr Hessian block, and thread-independent coordinate descent - #122

Merged
msuchard merged 3 commits into
developfrom
super-plr
Nov 20, 2026
Merged

msuchard merged 3 commits into
developfrom
super-plr

Conversation

@msuchard

Copy link
Copy Markdown
Member

Summary

Three commits that make pooled logistic regression (plr) fit, cross-validate and scale like lr on its expanded person-interval rows. NEWS items 44–46. No version bump.

1. fitter = "super" fits plr as it fits lr (NEWS 44)

createControl(fitter = "super") used to give plr the settings of fitter = "default". As a result, a model fit with plr and with lr on its expanded rows could select different variances: 5.84 against 19.78 on the cross-validation test case.

plr now gets lr's settings:

  • the "kkt" criterion;
  • the step-down auto-search, with the null-model bound and refinement;
  • per-fold warm starts;
  • active-set cycling;
  • adaptive intercept steps.

The intercept of a plr model is a subject column without a time-basis column, so lr's extra-step rule applies unchanged. Its moment ratios and rows of work count subjects.

On a 50,000-subject plr fit by coordinate descent, this took 177 iterations instead of 284 (4.3 s instead of 6.0 s), with coefficients within 1e-6.

2. The plr prox-Newton Hessian block in lr's column order and cache tiles (NEWS 45)

Cross-validating a plr censoring model was about twice as slow as lr.

  • Cause: most of the gap was the Hessian block. It added up its pairs of columns in a cache-unfriendly order, and four concurrent folds made that worse.
  • Fix: the block is now built as lr's is:
    • densest columns first;
    • cache-sized tiles of subjects;
    • the same task split on one thread and on several.
  • A Newton iteration also keeps the per-subject layouts of both its free set and its working set instead of rebuilding them.
  • subjectSums skips subjects that add nothing.
CCW hazard-model cross-validation plr before plr now lr (expanded rows)
25,000 persons (72,748 person-intervals, 3,821 columns), 4 threads 218 s 128 s 126 s
same, 1 thread 466 s 402 s 395 s
10^5-person CCW censoring models, package defaults 2,809 s 1,385 s 1,509 s

The selected variances and weights are the same to rounding: 6e-7 and 2e-7.

3. Coordinate descent on threads takes the steps it takes on one thread (NEWS 46)

With threads > 1, models with concurrent gradients (plr, and Cox) ran cycleWithConcurrentGradients(). That cycle always swept every coordinate and took no adaptive extra intercept steps. Under fitter = "super", a plr fit by coordinate descent therefore depended on the number of threads.

The concurrent cycle now:

  • skips the coordinates the serial cycle skips;
  • keeps the active-set bookkeeping;
  • takes the same extra intercept steps;
  • ends a run of concurrently computed gradients after an extra intercept step, as it does after a move.

The end-of-cycle bookkeeping that both cycles share moved to finishCycle().

Effect:

  • plr, super, ccd (600 subjects, 172 columns): on 2 and 4 threads the coefficients moved by 7e-6, with no extra intercept steps against 59 on one thread. They are now identical bit for bit, with the same 59 steps and the same iterations.
  • Cox with activeSetEvery on 4 threads: 44 iterations against 45, and 5e-10 apart, before. Identical now.
  • Unchanged bit for bit: fits on one thread, and threaded fits without an active set or adaptive intercept.

Tests

  • New quick test: plr's gradient and Hessian block equal lr's on the expanded rows, in cache tiles and on threads.
  • Extended test: "plr fits with threads equal those without" now also covers super-fitter coordinate descent with an active set. It fails on develop and passes on this branch.
  • Full suite (test_dir, without NOT_CRAN): 348 tests, 1,904 expectations, 0 failed, 0 errors, 30 skipped.
  • Downstream: CloneCensorWeight's default test tier on this branch has 332 tests and 6,524 expectations, with 0 failures.

🤖 Generated with Claude Code

msuchard and others added 3 commits November 19, 2026 16:53
createControl(fitter = "super") resolved pooled logistic regression ("plr")
to the settings of fitter = "default", so a model fit with plr and with lr
on its expanded rows could select different variances (5.84 vs 19.78 on
the cross-validation test case). plr now gets lr's settings: the "kkt"
criterion, the step-down auto-search with the null-model bound and
refinement, per-fold warm starts, active-set cycling and adaptive
intercept steps. The intercept of a plr model is a subject column without
a time-basis column, so lr's extra-step rule applies unchanged (its moment
ratios and rows of work count subjects). On a 50,000-subject plr fit by
coordinate descent: 177 instead of 284 iterations, 4.3 instead of 6.0 s,
coefficients within 1e-6. NEWS 44; no version change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Cross-validating a plr censoring model was about twice as slow as lr on
4 threads. Most of the gap was the Hessian block: plr added up its pairs
of columns in a cache-unfriendly order, and four concurrent folds made
it worse. It now builds the block as lr does, with the densest columns
first, cache-sized tiles of subjects, and the same task split on one
thread and on several. A Newton iteration also keeps the per-subject
layouts of both its free set and its working set instead of rebuilding
them, and subjectSums skips subjects that add nothing.

25,000 persons (72,748 person-intervals, 3,821 columns): 218 -> 128 s on
4 threads, 466 -> 402 s on 1 (lr 126 s and 395 s); 1e5 CCW defaults:
2,809 -> 1,385 s (lr 1,509 s), same variances and weights to rounding.
New quick test: plr's gradient and Hessian equal lr's on the expanded
rows, and are identical on 1 and 3 threads. NEWS 45; no version change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With threads > 1, models with concurrent gradients (plr, and Cox) ran
cycleWithConcurrentGradients(), which always swept every coordinate and
took no adaptive extra intercept steps. Under fitter = "super" (kkt,
active-set cycling, adaptive intercept) a plr fit by coordinate descent
therefore depended on the number of threads. The concurrent cycle now
skips the coordinates the serial cycle skips, keeps the active-set
bookkeeping (lastStepSE, cycleMaxStepSE), and takes the extra intercept
steps, ending a run of concurrently computed gradients after an extra
intercept step as after a move. The end-of-cycle bookkeeping both cycles
share moved to finishCycle().

plr, super, ccd (600 subjects, 172 columns): 2 and 4 threads moved the
coefficients by 7e-6 with no extra intercept steps (59 on one thread);
now identical bit for bit, with the same 59 steps and iterations. Cox
with activeSetEvery on 4 threads: 44 iterations and 5e-10 apart before,
identical now. Fits on one thread and threaded fits without an active
set or adaptive intercept are unchanged bit for bit. The plr threads
test covers it (fails before, passes after). Suite 348 tests / 1904
expectations, 0 failed. NEWS 46; no version change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov

codecov Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.42%. Comparing base (bcb3804) to head (85e7a87).

Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #122      +/-   ##
===========================================
+ Coverage    85.14%   85.42%   +0.27%     
===========================================
  Files           73       73              
  Lines        15780    15821      +41     
===========================================
+ Hits         13436    13515      +79     
+ Misses        2344     2306      -38     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@msuchard
msuchard merged commit 3aa5e11 into develop Nov 20, 2026
26 checks passed
@msuchard
msuchard deleted the super-plr branch November 20, 2026 13:15
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.

1 participant