Skip to content

Fix DimensionMismatch in DataDrivenSolution for empty bases (#514) - #689

Merged
ChrisRackauckas merged 1 commit into
SciML:masterfrom
dwan-ith:fix/empty-basis-dimension-mismatch
Nov 2, 2026
Merged

ChrisRackauckas merged 1 commit into
SciML:masterfrom
dwan-ith:fix/empty-basis-dimension-mismatch

Conversation

@dwan-ith

@dwan-ith dwan-ith commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Resolves #514

When sparsity thresholds zero out all basis coefficients (e.g. SR3 with strong regularization), __construct_basis filters out all equations, leaving an empty basis whose prediction Ŷ = b(prob) has 0 rows. Attempting residuals = Y .- Ŷ resulted in a DimensionMismatch between (n, T) and (0, T).

This PR:

Checks isempty(Ŷ) in DataDrivenSolution and assigns rss = sum(abs2, Y) (the residual of "no model" being the data itself).
Safely handles isempty(Ŷ) in StatsBase.summarystats(sol).
Adds regression tests in test/Core/solution.jl.

Used Claude Opus 4.6

@ChrisRackauckas-Claude

Copy link
Copy Markdown
Member

🤖 Automated comment from an AI agent running as @ChrisRackauckas — not written or reviewed by Chris.

Independent review (Codex CLI 0.166.0 / gpt-6.1-sol), session 01a1975f-0acf-7dc2-985a-b2b93af6fbc0, reviewed head 7e09643

  • Verdict: MERGE-WITH-ISSUES
  • Risk: medium-low (ML1: A previously returning single-target empty-model path changes to correct residual statistics; the multi-target regression fails before and passes after. L6 also covers the dimension-mismatch fix.)
  • Round / slot: 1 / 1
  • Blocking priorities: none

Review written by the reviewer named above in a session other than the PR author's, and copied here by the posting agent without change to its findings. The posting agent did not re-run the reviewer's commands.

Summary: Treats an empty recovered basis as a zero predictor for residual sums and summary statistics. The added regression fails on base and passes at head; only comment cleanup is requested.

Blast radius: DataDrivenSolution construction, rss-derived information criteria, and StatsBase.summarystats for empty predictions; nonempty prediction calculations remain unchanged.

Evidence: Blind L6 assessment sealed before author context; expanded analysis of the single-target path raises the final rating to ML1. The PR test file passes 26/26 at head and fails on the merge-base with DimensionMismatch after 23 passing assertions. An independent head probe passes 33/33 assertions for hand-calculated residual statistics, information criteria, and sparse recovery. No PR CI checks are reported.

Blocking findings

None.

Non-blocking findings

  1. [P3] src/solution.jl:47 — Suspected from reading: shorten the empty-model explanation and remove “strictly worse than any fit.” A fit can have greater RSS, and BIC additionally penalizes parameters, so zero prediction does not imply that ranking. Added comments also exceed the approximately 10% comment budget. A short statement that the empty basis represents zero predictions and therefore has residuals equal to the data suffices.

What I ran

  • Read RULES.md and TARGET.md; inspected the complete diff and relevant basis construction, problem evaluation, solution callers, and test wiring. No repository AGENTS.md or CLAUDE.md was present.
  • Git commands: git fetch origin '+refs/pull/689/head:refs/remotes/pr/689' master; git checkout --detach pr/689; git rev-parse HEAD; git diff origin/master...HEAD; git merge-base origin/master HEAD; git log -1 --no-merges --format=%B. Head matched the target and live head; the diff merge-base is the Base above. Extracted the merge-base with git archive d6b98d4eba86b8596c2ec82b900113677f837a41 for an isolated source snapshot.
  • Sealed the blind assessment using sha256sum INITIAL.md > INITIAL.sha256 before reading gh pr view 689 --repo SciML/DataDrivenDiffEq.jl --json title,body,commits,statusCheckRollup or gh issue view 514 --repo SciML/DataDrivenDiffEq.jl.
  • gh pr checks 689 --repo SciML/DataDrivenDiffEq.jl exited 1: “no checks reported.” gh run list --repo SciML/DataDrivenDiffEq.jl --branch master --event push --limit 5 exited 0; the five returned runs succeeded, including IntegrationTest, Downgrade, Documentation, Sublibrary CI, and format-check. There were no failed PR jobs to compare or inspect.
  • Julia invocations used JULIA_NUM_THREADS=4 OPENBLAS_NUM_THREADS=1 TMPDIR="$PWD/tmp" JULIA_DEPOT_PATH="$REVIEW_DEPOT:" JULIA_PKG_PRECOMPILE_AUTO=0 timeout 3600 julia +1.13.2 --startup-file=no --compiled-modules=existing SCRIPT. REVIEW_DEPOT represents the supplied shared depot; its literal machine path is omitted. Exactly three sequential Julia 1.13.2 processes ran, without Pkg.test or the whole suite. The environment resolved ModelingToolkit 11.46.1 and StatsBase 0.34.13.
  • Run 1, SCRIPT=run_head.jl, exit 0: activated an isolated environment, developed the head checkout, added the direct imports needed by test/Core/solution.jl, and included an unchanged copy of that complete PR test file under Test. Tail: PR regression at head | 26 26.
  • Run 2, SCRIPT=run_base.jl, exit 1: developed the merge-base snapshot in the same environment and included the identical head test file. Tail: PR regression at merge-base | 23 1 24 (23 passes, one error); DataDrivenSolution threw DimensionMismatch for target axes 2 versus prediction axes 0 at src/solution.jl:45 on base. A separate reviewer single-target check errored before its assertions because unqualified init was ambiguous; this is a probe defect, not a package finding.
  • Run 3, SCRIPT=probe.jl, exit 0: restored the head source and developed its DataDrivenSparse sublibrary (0.2.3). Independent zero-predictor references passed 28/28 assertions; a full STLSQ solve with threshold 1e6 passed 3/3; the corrected single-target head probe passed 2/2. Direct and continuous hand-written matrices each have RSS 91; discrete next-state data have RSS 74. Checked per-row means/minima/maxima, degrees of freedom, log-likelihood and BIC against these references, plus all-zero data and an unchanged exact identity model. Output: rss=91.0 means=[0.6666666666666666, -1.6666666666666667] bic=16.314600223732768; continuous means [4.0, -3.0]; discrete rss=74.0 means=[2.5, 5.5] bic=11.671082928337116; STLSQ zero model: equations=0 rss=91.0; single target: rss=14.0 summary rows=1.

What I did not verify

The supplemental full-constructor single-target check did not execute on base because of the probe import ambiguity; its old zero-RSS behavior is inferred from the inspected broadcast and empty-residual branch. No whole-package or downstream suite, GPU, AD, MPI, alternate Julia version, or Windows execution was performed; the change adds no such specialized paths. Implicit-model recovery and no-observation datasets were not exercised. The issue's exact SR3/normalization/batching example was not reproduced; the end-to-end sparse check used STLSQ. No PR CI results are available.

🤖 Posted by an AI agent — harness: Claude Code · model: claude-sonnet-5-5
Conversation: https://claude.ai/code/session_01379heiiB35TtywhR7uSU74

@ChrisRackauckas
ChrisRackauckas merged commit 22e0eb7 into SciML:master Nov 2, 2026
11 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.

DimensionMismatch error - Symbolic Regression failing for sparse hyperparameters

3 participants