Repository navigation
nns_var: forecast the horizon and report the regressors actually used (v2.1.0) - #143
Merged
Merged
Conversation
…used Port of the matching R NNS fix (OVVO-Financial/NNS branch claude/trusting-allen-usj1cz), keeping nns_var in exact parity with R: - nns_stack returns NNS.dim.red.variables (0-based predictor indices) and NNS.dim.red.coefficients; nns_var reports that selection as relevant_variables, so it lists exactly the regressors behind each multivariate estimate. - The multivariate stack is evaluated on the h forecast rows of the lagged matrix instead of the last h observed training rows. - obj_fn (a callable) and objective now reach both nns_arma_optim and nns_stack; DataFrame column names are kept; tau / h are validated up front (numpy integer tau no longer crashes); h defaults to 1. - Trailing NaNs are nns_arma_optim extrapolations; seasonal periods fall back to unrestricted nns_seas periods, then lag 1; never-negative variables keep non-negative outputs; own-lag weights map columns exactly. Parity bugs found along the way: - gravity (pure Python and the native gravity_exact) capped the histogram at 4n bins; R does not, so small partition quadrants with an outlier got a different regression point. The cap is now a 1e6 memory guard only. - nns_stack dim_red_method="nns.caus" used the outer NNS.caus seasonal lag search (and could raise) where R's Uni.caus uses a fixed lag of 3 for "ts"; "all" omitted R's equal-weight term from the average. - nns_var's default objective uses R's two-pass mean, so constant candidate predictions score Inf as in R (objective="max" used to pick them). Tests: new parity tests on driven three-variable data for every dim_red_method, tau form, own-lag weights, objective="max" and missing values (all exact); stack selection parity for cor / nns.dep / nns.caus / all; invariants proving regressors outside relevant_variables cannot move the estimate. NNS.VAR caches regenerated from the fixed R; stack shards gain the new-key entries. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Wws6NsSKm9v45EKYaXEdJJ
nns_var now forecasts the horizon and reports the regressors it actually uses; nns_stack gains NNS.dim.red.variables / NNS.dim.red.coefficients. uv.lock regenerated with `uv lock` (only the ovvo-nns entry changes). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Wws6NsSKm9v45EKYaXEdJJ
This was referenced Nov 3, 2026
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.
Summary
nns_varnow forecasts the horizon, and its multivariate estimate is a true multivariate fit on exactly the regressors listed inrelevant_variables. Version bumped to 2.1.0.The multivariate stage has two steps per variable:
nns_stackdimension reduction selects the relevant regressors. It runs Method 2 alone, which makes exactly the selection it makes inside a full stack (checked identical on 100 of 100 cases).nns_stack(stack=False)runs on exactly those regressors, sonns_reguses each one as its own dimension. Before, they were collapsed into a single synthetic X* regressor, which astack=Truefit always does.relevant_variablesis that selection. If the blend givesnns_regzero weight, it reports the regressors the dimension-reduction component carries instead. A single selected regressor is fit with method 1 alone, as R does.This ports the matching R fix on
OVVO-Financial/NNSbranchclaude/trusting-allen-usj1cz(commit1aa7bdc, not yet merged). The regeneratedNNS.VAR/NNS.stackcache entries come from that R build.nns_var / nns_stack
nns_stackreturnsNNS.dim.red.variables(0-based predictor indices, ranked by |coefficient|) andNNS.dim.red.coefficients. Withstack=True, regressors outside the selection cannot movestack(tested).hforecast rows of the lagged matrix, which carry the univariate forecasts. Before, it was evaluated on the lasthtraining rows: on a straight line −2…17 it returned 15, 16, 17 instead of 18, 19, 20.obj_fn(a callable) andobjectivenow reach bothnns_arma_optimandnns_stack. The MSE fallback for the default objective also covers the Method-2-only "No candidate produced a finite out-of-fold objective." case.tauandhare validated up front;numpyintegertauno longer crashes.hdefaults to 1, as in R.nns_arma_optimextrapolations.nns_seasperiods, then lag 1, when ARMA rejects them;tau=12on short series used to fail.Parity bugs fixed along the way
gravity_exactcapped the histogram at4nbins; R does not. Small partition quadrants with an outlier therefore got a different regression point. The cap is now only a 1e6-bin memory guard. The full suite passes unchanged.nns_stackwithnns.caus/all."nns.caus"used the outerNNS.causseasonal-lag search, and could raise, where R'sUni.caususes a fixed lag of 3 for"ts"."all"omitted R's equal-weight term from its average. Both now match R exactly.Infas in R; withobjective="max"it used to be selected.Tests
dim_red_method, everytauform, own-lag weights,objective="max", interior plus trailing NaNs; plus stack selection parity forcor/nns.dep/nns.caus/all.nns_stack(stack=False)on only the relevant columns, including a two-driver fixture whereyselects both drivers.obj_fnforwarding, non-negativity, seasonal fallback.NNS.caus: R and Python normalize it about 1e-15 apart, which flips ties and can change how many regressors are kept. On that fixture only, each variable is compared exactly whenever R and Python selected the same regressors, and checked for validity otherwise. The driven-data tests holdnns.caus/allto exact parity everywhere.test_nns_stack_pred_int_shape_invariants_holdnow excludes two-valued responses, which switchnns_stackto classification. That was a pre-existing random failure; it reproduces onmain.ruff check .,mypy, andpytest tests/invariants tests/parity tests/property tests/plotting tests/tools tests/docswithNNS_R_CACHE_ONLY=1pass. The live-R macro VAR practical tests also pass against the fixed R.Behaviour change
multivariateandensemblevalues change for everynns_varcall, because the multivariate stage now forecasts the horizon and fits the relevant regressors jointly.relevant_variablesis ordered by importance rather than column order.Version
2.0.0→2.1.0inpyproject.toml,nns.__version__, the README version row, anduv.lock(regenerated withuv lock; only theovvo-nnsentry changes).scripts/check_version_consistency.pypasses.Follow-ups
sync/nns_source.jsonr_commitshould be bumped once the R branch merges.docs/benchmarks.mdtimings predate this change.🤖 Generated with Claude Code
https://claude.ai/code/session_01Wws6NsSKm9v45EKYaXEdJJ