Skip to content

meboot: an exactly linear or constant series no longer errors with rho - #188

Closed
gitRasheed wants to merge 1 commit into
rasheed/py-ss-constant-groupfrom
rasheed/py-meboot-zero-residuals
Closed

gitRasheed wants to merge 1 commit into
rasheed/py-ss-constant-groupfrom
rasheed/py-meboot-zero-residuals

Conversation

@gitRasheed

Copy link
Copy Markdown
Collaborator

R's NNS.meboot stopped with "function cannot be evaluated at initial parameters" when a series' detrended residuals were all exactly zero, as for 1:10 or a constant, because there are no ranks to target rho with. Every rho and type failed, and so did NNS.MC(1:20) and NNS.SS(x, 1:10, confidence.interval = TRUE). OVVO-Financial/NNS#149 (merged) skips the rho targeting and scl.adjustment in that case, and force.clt when its reference sd is 0. This slice mirrors it.

Stacked on #187 (rasheed/ss-constant-group); merge with a merge commit.

Changes

  • _nns_meboot_one (meboot.py) skips _target_rho and the scl_adjustment block when every residual is exactly 0, and _force_clt when sd(clt_ref) is 0. The last guard changes nothing in Python, because _force_clt already returned the ensemble unchanged when the target means have sd 0. It's there so the code reads like R's. Any series with a nonzero residual takes the old path.
  • Before and after, with after equal to R main: nns_meboot(1:10, reps=5, rho=0.5) raised and now gives copies of the trend with their means spread by force_clt. rep(3, 10) gives constant columns. nns_mc(1:20, reps=3, by=0.5) gives 5 finite blocks. nns_arma(1:20, h=5, method="lin", pred_int=0.95) raised and now gives intervals around 21:25 (R main: 21 ± 2.625).
  • The nns_meboot docstring and docs/conventions.md say rho has no effect in this case, as R's Rd now does. The comment in stochastic_superiority.py drops "NNS.meboot cannot rescale it".

Tests

  • New invariants mirroring R's test-meboot-zero-residuals.R: for 1:10 at every type and rho in {-1, 0, 0.5, 1}, each replicate is linear to 1e-6 with slope in [1, 1.05], and the sorted replicate means match those of 1:10 + 1e-9 * noise to 1e-6. Also, scl_adjustment gives finite values, reps=1 returns x exactly, drift=False gives means of 5.5, and the constant series gives constant columns for rho 0.5, nnsdep, scl_adjustment and target_drift=0. NNS.SS with a linear group and NNS.MC on 1:20 give finite results.
  • I did not copy R's literal means 5.5 + z * sd(x) / sqrt(10). Python's _force_clt still scales by sqrt(reps). R Inspect R NNS API update 54c98418c2a11499ebb1c456570d2b66c37eb817 #107 changed that to sqrt(n), and the Python side of it waits for the re-vendor. R's constant-series case with target_drift = 0 and no rho runs in Python with rho 0.5, because nns_meboot(rho=None) returns {} (that is what R returns when rho = NULL is passed explicitly). R's ts case has no Python counterpart.
  • Two existing tests expected the error and now check the result: the constant case in tests/parity/test_meboot.py, and the exact-line ARMA prediction interval in tests/invariants/test_arma.py.
  • No cache entry moves. Every cached meboot and MC input has a nonzero residual (the sin terms in the test series), the cached ARMA prediction intervals (NNS.ARMA.pred_int, NNS.ARMA.optim.custom) bootstrap forecasts that aren't exact lines, and the NNS.SS entries have no interval. An all-zero input with rho raised in R, so the cache can't hold one.
  • Gates on the top of this stack (rasheed/co-moment-lengths, which includes this slice), cache only: native 2958 passed, 4 skipped, 3 xfailed, 2 xpassed. With NNS_DISABLE_NATIVE=1: 2936 passed, 29 skipped, 2 xpassed. The 3 xfails are mode: break tied discrete modes by gravity, not their mean (mirrors R #111) #178's strict ones and the 2 xpasses the existing non-strict live-R VAR xfails. tests/parity/test_practical_examples.py against the usual R library: 9 passed, 2 xfailed, as on mode: break tied discrete modes by gravity, not their mean (mirrors R #111) #178. ruff check is clean on every changed file.

Review

GPT-6.1 Sol reviewed the #149 and #132 mirrors together: SHIP, no findings. It checked 198 nonzero-residual meboot cases per backend for bit-identical outputs and RNG state.

Mirrors OVVO-Financial/NNS#149

…o (R meboot-zero-residuals)

Mirrors R NNS.meboot (OVVO-Financial/NNS meboot-zero-residuals). When the
detrended residuals are all exactly zero there are no ranks to target rho
with, so nns_meboot raised "function cannot be evaluated at initial
parameters" for every rho and type, and so did nns_mc and
nns_ss(confidence_interval=True) on such a series and nns_arma's
prediction interval for an exactly linear forecast. The rho search and
scl_adjustment are now skipped when every residual is zero, and force_clt
when its reference series has sd 0. Any series with a nonzero residual
takes the old path.

Before -> after (= R main):
  nns_meboot(1:10, reps=5, rho=0.5)  ValueError -> copies of the trend,
                                     means spread by force_clt
  nns_meboot(rep(3, 10), rho=0.5)    ValueError -> constant columns
  nns_mc(1:20, reps=3, by=0.5)       ValueError -> 5 finite blocks
  nns_arma(1:20, h=5, method="lin", pred_int=0.95)
                                     ValueError -> intervals around 21:25

The parity and ARMA tests that expected the error now check the result.
No cache entry moves.
@github-actions

github-actions Bot commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

Incorporated through NNS R 14.0 integration #192, merged as bd19c3303222af46da79d8c97f258248eb5674d2. Verified exact head 8995f5d1cbf4d8685c6036096f5b71fc4809706c is an ancestor of main; original commits and authorship are preserved. The integration includes the subsequent R14 compatibility corrections and passed the complete GitHub Python 3.11-3.14 matrix. This supersedes the separate landing, not the work or review history.

@github-actions github-actions Bot closed this Nov 7, 2026
@github-actions
github-actions Bot deleted the rasheed/py-meboot-zero-residuals branch November 7, 2026 18:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant