perf(spillover): sparse cKDTree branch for staggered nearest-treated distances#645
perf(spillover): sparse cKDTree branch for staggered nearest-treated distances#645igerber wants to merge 2 commits into
Conversation
|
Overall Assessment: ✅ Looks Good Executive Summary
Methodology
Code Quality
Performance
Maintainability
Tech Debt
Security
Documentation/Tests
|
18393e1 to
1fbea09
Compare
…distances The staggered cohort loop always built a dense (n_units, n_treated_by_onset) distance matrix per cohort. It now dispatches per cohort to the same cKDTree helper the static path uses (auto-activated past _CONLEY_SPARSE_N_THRESHOLD, built-in metrics only, cutoff_km = the outermost ring edge / _effective_d_bar). Within-cutoff distances are exact (the helper recomputes the true metric for in-range matches); beyond-cutoff units get inf — semantics-preserving because every staggered d_it consumer (ring membership, S_it, the far-away check, the event-study d_bar trigger) compares against thresholds at or below that cutoff. Helper- and fit-level equality tests pin the sparse arm against dense (atol 1e-12 end-to-end, trigger array identical). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1fbea09 to
8e80502
Compare
|
🔁 AI review rerun (requested by @igerber) Head SHA: Overall Assessment: ✅ Looks Good Executive Summary
Methodology
Code Quality
Performance
Maintainability
Tech Debt
Security
Documentation/Tests
|
Summary
_compute_nearest_treated_distance_staggeredalways built a dense(n_units, n_treated_by_onset)distance matrix per cohort. It now dispatches per cohort to the same cKDTree helper the static path already uses (_compute_nearest_treated_distance_sparse) — auto-activated whenn_units > _CONLEY_SPARSE_N_THRESHOLD, built-in metrics only, withcutoff_km = _effective_d_bar(the outermost ring edge), mirroring the static call site exactly. Closes the Wave-B TODO row.inf, and every staggeredd_itconsumer — ring membership,S_it, the far-away-control check, and the event-studyd_bartrigger — compares against thresholds ≤ that cutoff, soinfvs large-finite is indistinguishable downstream (same argument as the documented static-path behavior).TestStaggeredSparseKDTreeBranch: helper-level equality (within-cutoff distances match dense at 1e-8; beyond-cutoff allinf; thed_bartrigger array identical incl. NaN pattern) and end-to-end fit identity (att/SE/per-ring effects at atol 1e-12) with the threshold monkeypatched to force the sparse arm.Methodology references (required if estimator / math changes)
Validation
tests/test_spillover.py::TestStaggeredSparseKDTreeBranch(2 tests); fulltests/test_spillover.pypasses (321).Security / privacy
Generated with Claude Code