Require min_val_rows on the training split too - #242
Merged
Conversation
map_estimate()'s 1-D optimizer selection tested is.null(prior$lower) && is.null(prior$upper) to decide whether a prior is fully bounded and can take the Brent branch. prior_custom(dim = 1, lower = -Inf, upper = 5) has both fields set -- one is just non-finite -- so is.null() can't tell it apart from a genuine two-sided box, and it took the Brent branch anyway. stats::optim(method = "Brent", lower = -Inf, ...) then errored immediately with "'lower' and 'upper' must be finite values" before the search ran. Require is.finite() on both bounds in addition to the is.null() check. A bound that is present but infinite now falls through to the existing L-BFGS-B branch, which already accepts Inf on the missing side. Fixes #238
check_train_controls() enforced min_val_rows against n_val only, with no matching floor on n_tr = n - n_val. A large validation_fraction can clear the validation-side floor while leaving n_tr below it -- e.g. n_simulations = 4, validation_fraction = 0.75 for nre() gives n_val = 3 (clears min_val_rows = 2) and n_tr = 1 (was never checked). train_restarts() then trained on that single row, and nre_atomic_log_prob()'s k < 2L guard -- the same branch #188 fixed for the validation side -- returned a constant zero loss every step: no gradient, no error. Training ran to `patience` epochs and reported a best_val_loss as if it had actually trained. check_train_controls() now also requires n - n_val >= min_val_rows, mirroring the existing validation-side check and its error message. Adds regression tests at check_train_controls(), train_conditional_de(), fit_nre_net() and nre() covering the issue's exact scenario.
…training-split-floor # Conflicts: # DESCRIPTION # NEWS.md
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #242 +/- ##
=======================================
Coverage 98.40% 98.41%
=======================================
Files 31 31
Lines 4015 4026 +11
=======================================
+ Hits 3951 3962 +11
Misses 64 64 ☔ View full report in Codecov by Harness. |
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.
Fixes #239
Bug
check_train_controls()(R/train.R) enforcesmin_val_rows(2 fornre()'s atomic contrastive objective, per #188) against the validation split (n_val) only. It never applied the same floor to the training split (n_tr = n - n_val).A large
validation_fractioncan clear the validation-side floor while leavingn_trbelow it.n_simulations = 4,validation_fraction = 0.75fornre()givesn_val = 3(clearsmin_val_rows = 2) andn_tr = 1(was never checked), so both ofcheck_train_controls()'s existing checks passed.train_restarts()then trained on that single row.nre_atomic_log_prob()'sk < 2Lguard -- the exact branch #188 fixed for the validation side -- fired on the training side instead:return(nre_logit_tensor(net, theta, x) * 0), a constant zero loss with no gradient.backward()never updated the network, training ran silently topatienceepochs, and the fit reported abest_val_lossas if training had actually happened. No error, no warning.Fix
check_train_controls()now also requiresn - n_val >= min_val_rows, mirroring the existing validation-side check (same style, same error-message shape, just "leaves only N rows ... for training" instead of "holds out only N rows ... for validation").Tests
Added regression tests reproducing the issue's exact scenario (
n = 4,validation_fraction = 0.75) at four levels:check_train_controls()directly (tests/testthat/test-train.R)train_conditional_de()(tests/testthat/test-train.R)fit_nre_net()(tests/testthat/test-nre.R)nre()end-to-end, asserting the simulator is never called -- the check fires before simulation, same as the existing nre() early stopping breaks silently when the validation split has exactly 1 row #188 test (tests/testthat/test-nre.R)All of these are torch-free argument-validation checks, matching the style of the existing #188 tests.
Checks
R CMD INSTALL --no-docs . && (cd tests && Rscript testthat.R):FAIL 0 | WARN 0 | SKIP 79 | PASS 1367(torch unavailable in this sandbox, so neural/MDN/MAF/NSF/NRE-net tests skip; all validation-path tests, including the new ones, ran and passed).DESCRIPTIONbumped to 0.6.19,NEWS.mdentry added (PR number to follow in a follow-up commit once assigned).Generated by Claude Code