Skip to content

Fix #303: align edof_per_coef length with coefficients#507

Closed
MahmoudAdelbghany wants to merge 4 commits intodswah:mainfrom
MahmoudAdelbghany:issue/303-edof-padding
Closed

Fix #303: align edof_per_coef length with coefficients#507
MahmoudAdelbghany wants to merge 4 commits intodswah:mainfrom
MahmoudAdelbghany:issue/303-edof-padding

Conversation

@MahmoudAdelbghany
Copy link

Summary

Fixes the edof_per_coef length mismatch described in #303 so summary() can report term-level effective DoF consistently.

Story / Investigation

  • Bug observed: In high-spline, rank-deficient fits, len(gam.statistics_["edof_per_coef"]) < len(gam.coef_).
  • Reproduction attempts:
    1. Fit PoissonGAM(n_splines=25) on a small synthetic dataset.
    2. Print lengths of edof_per_coef and coef_.
    3. Call gam.summary() and observe missing term-level EDoF output.
  • Root cause: _estimate_model_statistics stores np.diagonal(U1.dot(U1.T)) directly, which can be shorter than coefficient count when rank drops.
  • Fix: Pad the per-coefficient EDoF vector with trailing zeros to len(coef_) before assigning statistics_["edof_per_coef"].

Tests

  • Updated test_more_splines_than_samples to assert aligned lengths.
  • Ran:
    • pytest -q pygam/tests/test_GAM_methods.py -k more_splines_than_samples

- reproduce with high-spline rank-deficient fit\n- root cause: edof diagonal can be shorter than coef_\n- fix: pad missing entries with trailing zeros before storing statistics\n\nCo-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
No code changes.\n\nCo-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Fix intermittent Windows CI failures caused by Tk initialization errors in test_gen_imgs by selecting a non-interactive backend before importing gen_imgs.\n\nCo-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Follow CI ruff hook ordering for stdlib and third-party imports.\n\nCo-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@MahmoudAdelbghany MahmoudAdelbghany deleted the issue/303-edof-padding branch March 14, 2026 06:17
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