Skip to content

Return CV stopping diagnostics from cv.learner() and fix blank heatmaps after plot_objective() - #9

Merged
stmcg merged 4 commits into
mainfrom
cv-diagnostics
Nov 6, 2026
Merged

stmcg merged 4 commits into
mainfrom
cv-diagnostics

Conversation

@Jodielidada

@Jodielidada Jodielidada commented Nov 6, 2026 •

Copy link
Copy Markdown
Collaborator

cv.learner() diagnostics

cv.learner() now returns cv_diagnostics, a data frame with one row per candidate and fold. The columns are candidate, fold, lambda_1_row, lambda_1_col, lambda_2, updates, stop_code and selected. The stopping codes mean the same as in learner(): 1 for the stopping rule, 2 for the iteration limit, 3 for excessive growth or non-finite values. The records are saved during CV, so nothing is refitted.

Example output of cv_multi$cv_diagnostics, using the data and settings of the multiple-source example in the vignette. The vignette itself prints only the selected rows and the count of stopping codes:

cv_diagnostics for the multiple-source example: one row per candidate and fold, with the number of updates and the stopping code

If a candidate gives non-finite values, its remaining folds are skipped and their updates and stop_code are NA.

cv_learner_cpp() now returns a list with the scores, the stopping codes and the update counts. The scores and the other elements of the cv.learner() result are unchanged.

In the vignette, the section on CV fits used to recreate the folds with the same seed and refit them. It now reads cv_diagnostics. It also shows the codes for all 18 fits in the multiple-source search: 14 meet the stopping rule and 4 reach the iteration limit, two of them in the selected candidate. Section 4 now uses cv_multi from Section 3, so its introduction and its check ask the reader to run the cross-validation in Section 3 first. The example script has the same changes, and its check at the top now looks for cv_diagnostics.

plot_objective() and RStudio

In RStudio, the second CV heatmap in the tutorial was blank once plot_objective() had run. plot_objective() no longer calls par(), so it uses the current margins instead of setting mar = c(5, 4.5, 4, 1.5). With the default margins the plot looks almost the same, but with very small margins the title and axis labels can be cut off. This is noted in the help page and in NEWS. I checked in RStudio and the second heatmap is drawn now. I do not know exactly why the par() calls caused it. There are two new tests: one checks that plot_objective() records no par() call, and one checks that a CV heatmap drawn before it is not damaged.

Checks

R CMD check --no-manual gives Status OK on macOS (R 4.6.1) with no warnings or notes. 737 expectations pass and the vignette builds. I also ran inst/examples/advanced-learner.R from top to bottom. I have not checked the PDF manual or other platforms. GitHub Actions should cover those.

Please merge with a regular merge commit.

In RStudio, the second CV heatmap in the advanced tutorial was blank once
plot_objective() had run. plot_objective() no longer sets the margins with
par(), so it uses the current margins. With very small margins the title
and axis labels can be cut off. The help page and NEWS say so.

New tests check that plot_objective() records no par() call and that a CV
heatmap drawn before it is not damaged.
cv.learner() now returns cv_diagnostics, a data frame with one row per
candidate and fold. It has the candidate number, the fold, the penalties,
the number of updates, the stopping code, and whether the candidate was
selected. The records are saved during CV, so no fold has to be refitted.
If a candidate gives non-finite values, its remaining folds are skipped and
their updates and stopping codes are NA. cv_learner_cpp() returns a list
with the scores, the stopping codes and the update counts.

The vignette and the example script read cv_diagnostics instead of
recreating the folds and refitting them, and the multiple-source search is
checked the same way. Section 4 uses cv_multi from Section 3, so its
introduction and its check say to run the cross-validation in Section 3
first.

The new tests compare the saved stopping codes and update counts with
separate refits of every fold.
@codecov

codecov Bot commented Nov 6, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.18%. Comparing base (a5eb931) to head (4656f5d).

Additional details and impacted files
@@            Coverage Diff             @@
##             main       #9      +/-   ##
==========================================
+ Coverage   99.16%   99.18%   +0.01%     
==========================================
  Files           7        7              
  Lines         599      610      +11     
==========================================
+ Hits          594      605      +11     
  Misses          5        5              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Jodielidada
Jodielidada requested a review from stmcg November 6, 2026 06:12
@stmcg
stmcg merged commit 9bc6dc5 into main Nov 6, 2026
8 checks passed
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.

2 participants