Skip to content

Commit 572a02b

Browse files
fix(dml): drop dead mu_hat line in IRM that referenced undefined names
`_fit_one` referenced `g1_hat_full` / `g0_hat_full` behind a `if 'g1_hat_full' in locals()` guard that always evaluated False, so the resulting `mu_hat` was unconditionally `None` and never read by any caller. flake8 (E9/F7/F82 strict subset in CI) caught the unbound names as `F821 undefined name`, breaking every Linux/macOS lint job. Removed the dead branch and merged the leftover comment block into a single explanation of the residuals we actually expose. No behavior change — `_last_rep_residuals` already returned `{y_resid, d_resid, pscore}`, which is exactly what `dml_diagnostics` consumes. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 8faacd7 commit 572a02b

1 file changed

Lines changed: 5 additions & 7 deletions

File tree

src/statspai/dml/irm.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -205,13 +205,11 @@ def _fit_one_rep(self, Y, D, X, Z, n, rng_seed, sample_weight=None):
205205
"weighted": sample_weight is not None,
206206
}
207207
# Stash IRM-relevant residuals for sensitivity / diagnostics.
208-
# For IRM the natural "Y residual" is Y - μ̂(X, D) and the
209-
# natural "D residual" is D - m̂(X). Both are length-n.
210-
mu_hat = np.where(D == 1, g1_hat_full, g0_hat_full) if 'g1_hat_full' in locals() else None
211-
# We didn't save full per-fold g1/g0; reconstruct using a final
212-
# within-fold lookup is non-trivial. Instead, surface ψ_scores
213-
# and m_hat_full so dml_diagnostics can build overlap plots, and
214-
# provide y_resid/d_resid as defined for sensitivity:
208+
# We don't save per-fold g1/g0 — surface ψ_scores and m_hat_full
209+
# so dml_diagnostics can build overlap plots, and provide
210+
# y_resid/d_resid as defined for sensitivity. The natural "D
211+
# residual" is D - m̂(X); for "Y residual" we use ψ - θ̂ (see
212+
# below).
215213
d_resid = D - m_hat_full
216214
# For IRM, y_resid uses ψ - θ̂ (the score residual) which is the
217215
# influence function input — appropriate for OVB sensitivity per

0 commit comments

Comments
 (0)