Optimize CallawaySantAnna WIF computation with vectorized NumPy operations#65
Merged
Merged
Conversation
…tions Vectorize the weight influence function (WIF) computation in _compute_aggregated_se_with_wif() to achieve 4-10x speedup over R at all dataset scales while maintaining exact SE accuracy (0.0% difference). Changes: - Replace O(n_units × n_keepers) nested loops with NumPy broadcasting - Use precomputed unit-group mapping instead of O(n) DataFrame lookups - Vectorize influence function aggregation with np.add.at() - Add indicator_matrix, if1/if2 matrix operations, and matrix multiply for wif_contrib = wif_matrix @ effects Performance improvements (vs R's did package): - small: 2.7x → 10.5x faster - 1k: 1.0x → 8.8x faster - 5k: 0.5x → 6.8x faster - 10k: 0.4x → 5.3x faster - 20k: 0.3x → 4.2x faster SE accuracy remains at 0.0% difference from R at all scales. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
igerber
pushed a commit
that referenced
this pull request
Jan 15, 2026
Reviews the vectorized WIF computation changes: - Methodology correctness: PASS (mathematical equivalence verified) - Code quality: PASS (clean vectorization, proper edge handling) - Performance: PASS (4-10x faster than R, 0.0% SE difference) - Tech debt: MINIMAL (clean extension of existing patterns) Final verdict: APPROVE
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.
Vectorize the weight influence function (WIF) computation in _compute_aggregated_se_with_wif() to achieve 4-10x speedup over R at all dataset scales while maintaining exact SE accuracy (0.0% difference).
Changes:
Performance improvements (vs R's did package):
SE accuracy remains at 0.0% difference from R at all scales.