⚡ Optimize Logit and Probit Hessian calculations#49
⚡ Optimize Logit and Probit Hessian calculations#49dot-comma-hyphen wants to merge 1 commit intomainfrom
Conversation
Avoid full feature matrix clones and transpositions by computing weighted Gram matrices and gradients manually using column-major access patterns. This significantly reduces memory allocations and improves cache locality during Newton-Raphson optimization. Co-authored-by: dot-comma-hyphen <216583967+dot-comma-hyphen@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
This PR optimizes the Logit and Probit regression implementations in the
oaxaca_blindercrate.💡 What
The optimization replaces high-level matrix operations that triggered full matrix clones and transpositions (like
x.clone(),x.transpose()) with manual, memory-efficient calculations. It leverages the column-major layout ofnalgebra'sDMatrixto compute weighted Gram matrices (for the Hessian) and dot products (for the Gradient) directly from the underlying data slices.🎯 Why
In each iteration of the Newton-Raphson optimization, the original code cloned the entire feature matrix$X$ and transposed it multiple times. For datasets with many observations ($N$ ) or predictors ($K$ ), this led to significant $O(N \cdot K)$ memory pressure and unnecessary CPU cycles spent on allocations and data movement.
📊 Measured Improvement
nalgebraoperations that perform defensive copies.PR created automatically by Jules for task 9108368597733373413 started by @dot-comma-hyphen