Skip to content

Require min_val_rows on the training split too - #242

Merged
pedroliman merged 4 commits into
mainfrom
claude/issue-239-nre-training-split-floor
Aug 28, 2026
Merged

Require min_val_rows on the training split too#242
pedroliman merged 4 commits into
mainfrom
claude/issue-239-nre-training-split-floor

Conversation

@pedroliman

Copy link
Copy Markdown
Owner

Fixes #239

Bug

check_train_controls() (R/train.R) enforces min_val_rows (2 for nre()'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_fraction can clear the validation-side floor while leaving n_tr below it. 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), so both of check_train_controls()'s existing checks passed.

train_restarts() then trained on that single row. nre_atomic_log_prob()'s k < 2L guard -- 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 to patience epochs, and the fit reported a best_val_loss as if training had actually happened. No error, no warning.

Fix

check_train_controls() now also requires n - 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:

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).
  • DESCRIPTION bumped to 0.6.19, NEWS.md entry added (PR number to follow in a follow-up commit once assigned).

Generated by Claude Code

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

codecov Bot commented Aug 28, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.41%. Comparing base (f1ffd19) to head (c4593b0).
✅ All tests successful. No failed tests found.

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.
📢 Have feedback on the report? Share it here.

@pedroliman
pedroliman merged commit 59e1455 into main Aug 28, 2026
5 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.

nre(): a training split of 1 row silently trains on zero gradient instead of erroring

1 participant