Repository navigation
nns_seas: score every component series of each lag (book ch25) - #170
Closed
gitRasheed wants to merge 2 commits into
Closed
gitRasheed wants to merge 2 commits into
gitRasheed wants to merge 2 commits into
Conversation
gitRasheed
force-pushed
the
rasheed/book-seas-all-phases
branch
from
November 2, 2026 04:12
fb469dd to
b392514
Compare
gitRasheed
force-pushed
the
rasheed/vendor-core
branch
from
November 2, 2026 04:12
d9ce7b3 to
84af909
Compare
…ses)
Mirrors R's seas-all-phases branch (NNS.seas), including its round-2
fixes. NNS.seas scored only three reverse-stride subsamples per lag
(ending at n, n-1 and n-2), averaged them unweighted, accepted ties with
<= and fell back to 1/|acf1| when the mean was exactly 0. The book
(ch. 25) defines the test on all m component series of lag m with a
length-weighted mean CV, kept when strictly below CV(X).
Now each lag m in 1..n/2 is scored on all m components x[j::m], weighted
by length, and kept when strictly below CV(X). When |mean(x)| <=
sqrt(eps) * sd(x) the sd replaces the CV. A constant component scores 0,
and a component with a near-zero mean has its CV capped at 1/sqrt(eps).
Each component's sums are added in R's order, so the scores are
bit-identical to R's (new invariant against a transcription of the C++
loop). The dead acf1/subsample helpers go. R's ARMA.seas.weighting
equal-weights fallback was already in nns_arma.
Before -> after (= R):
AirPassengers best period 50 -> 12; periods 18 -> 3 (12, 13, 6)
nns_arma(AirPassengers[:132], h=12) holdout MAPE 0.2434 -> 0.0389
rep([0, 10], 10) periods 2 4 6 8, CV 0
constant series periods 1..9 -> 1 (no seasonality)
AirPassengers[:24], seasonal_factor=False, h=4
122 102 162 213.67 -> 120 153 149 115
nns_seas at n = 20000 takes 2.2 s (was 0.05 s; the rule is O(n^2)).
Refilled from R: the 15 NNS.seas, 11 NNS.ARMA, 2 NNS.caus and 11 NNS.VAR
entries these tests read (all predate the R change; NNS.caus with
tau="ts" picks its lag from NNS.seas). The nine NNS.VAR
tests also need R's optim-pi-from-returned-model change in
NNS.ARMA.optim, so they are strict xfails until that is ported. The
airline smoke values are updated from R.
…irror of the R fix) A repeated 0.1 does not centre to exactly 0, so the sd of a constant series or component was rounding noise and nns_seas(np.full(20, 0.1)) reported period 4. As R now does, a series or component whose raw values are all equal has sd 0: that series gives best period 1 and np.tile([0.1, 1.0], 10) gives 2.
gitRasheed
force-pushed
the
rasheed/vendor-core
branch
from
November 2, 2026 23:09
84af909 to
448c27a
Compare
gitRasheed
force-pushed
the
rasheed/book-seas-all-phases
branch
from
November 2, 2026 23:09
b392514 to
0f3610d
Compare
Contributor
|
Incorporated through NNS R 14.0 integration #192, merged as |
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.
nns_seasscores only three reverse-stride subsamples per lag, ending at n, n-1 and n-2, averages them unweighted, accepts ties with<=and falls back to 1/|acf1| only when the mean is exactly 0. Book ch25 (ch25:183, 257-284) tests lag m on all m component series with a length-weighted mean CV, kept when strictly below CV(X). We mirror OVVO-Financial/NNS#91, which makes R follow the book, including its round-2 fixes. That PR changes the method, so the R author may close it; if so, this slice should be dropped too.Stacked on #169; merge with a merge commit.
Changes
x[j::m], weighted by length, and kept when strictly below CV(X). When |mean(x)| <= sqrt(eps) * sd(x), the sd replaces the CV. Each component's sums are added in R's order, so the scores are bit-identical to R's.rep([0, 10], 10)keeps periods 2 4 6 8, and a near-zero-mean component is capped at 1/sqrt(eps). A constant series goes from periods 1..9 to 1 (no seasonality).nns_arma(AirPassengers[:132], h=12)goes from 0.2434 to 0.0389, and the forecast equals R's to 1e-15.nns_arma.nns_seasat n = 20000 goes from 0.05 s to 2.2 s, because the rule is O(n^2). R takes 0.91 s, and the R PR lists the cost under its tradeoffs.Tests
A new invariant pins the scores to a transcription of the C++ loop, and new parity cases cover the constant-component and AirPassengers cases. The 15
NNS.seas, 11NNS.ARMA, 2NNS.causand 11NNS.VARentries these tests read predate the R change and are refilled;NNS.causwith tau = "ts" picks its lag from NNS.seas. The parity cache encodes R 13.3 plus the fixes in OVVO-Financial/NNS#73-#92.Nine
NNS.VARtests are strict xfails here and in the next three slices. Their R values also depend on OVVO-Financial/NNS#88, and #174 removes the marks.Mirrors OVVO-Financial/NNS#91
Part of OVVO-Financial/NNS#69
Update
This push mirrors the seasonality part of OVVO-Financial/NNS#99. A constant series or component scores 0 by exact equality. Before, a constant 0.1 series had a rounding-level spread and reported period 4. The best period for
rep(0.1, 20)is now 1, and forrep(c(0.1, 1), 10)it is 2.Review
GPT-6.1 Sol reviewed this slice and found nothing. It compared 200 new inputs against R.