Repository navigation
var: integer-degree VaR roots no longer depend on the data's units - #180
Closed
gitRasheed wants to merge 1 commit into
Closed
gitRasheed wants to merge 1 commit into
gitRasheed wants to merge 1 commit into
Conversation
… var-root-tolerance)
Mirrors R LPM.VaR / UPM.VaR (OVVO-Financial/NNS var-root-tolerance). The
integer-degree solver accepted an interval end when the polynomial residual
(1 - p) * LPM - p * UPM was within sqrt(eps). That residual scales with
x^degree, so data of order 1e-3 at degree 4 took the first end it saw:
lpm_var(0.5, 4, [-.003, -.002, -.001, .001, .002, .003]) was -0.001.
The end test now uses the dimensionless ratio gap LPM / (LPM + UPM) - p at
eps^0.75, and the root is solved to rounding (R's zeroin port, the one
_var_uniroot uses, at eps^2 times the interval width) because a tolerance on
t does not bound the ratio where it is steep. Without a sign change, which
only rounding at a break produces, it takes the endpoint with the smaller
gap instead of minimising |f|.
Before -> after (= R main):
lpm_var(.5, 4, symmetric 1e-3 data) -0.001 -> 0
lpm_var([.01, .05, .5, .95], 3, 1e-4 * x) [-2e-5, 4e-5, 1.2e-4, 1.2e-4]
-> [9.20e-6, 5.44e-5, 1.61e-4, 2.88e-4]
No cache entry moves: the LPM.VaR and UPM.VaR shards, and the ARMA and ANOVA
entries that use VaR, still match.
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.
R's integer-degree
LPM.VaRandUPM.VaRaccepted an interval end when the polynomial residual(1 - p) * LPM - p * UPMwas within sqrt(eps). That residual scales with x^degree, so small-unit data took the first end it tested:LPM.VaR(.5, 4, c(-.003, -.002, -.001, .001, .002, .003))was -0.001 instead of 0. OVVO-Financial/NNS#125 (merged) tests the dimensionless ratio gap instead and solves the root to rounding. This slice mirrors it.Stacked on #179; merge with a merge commit.
Changes
_lpm_var_integer_interval(var.py) accepts an end whenLPM / (LPM + UPM) - pis within eps^0.75. The root uses the repo's port of R'szeroin2(the one_var_unirootalready uses) at eps^2 times the interval width, as R'sunirootcall now does, because a tolerance on t does not bound the ratio where it is steep. Without a sign change, which only rounding at a break produces, it takes the endpoint with the smaller gap instead of minimising |f| withminimize_scalar.LPM + UPM(subnormal data) gives a NaN gap instead of raising ZeroDivisionError; the existing hypothesis range test found that.lpm_var([.01, .05, .5, .95], 3, 1e-4 * x)for an 8-point skewed x went from interval ends [-2e-5, 4e-5, 1.2e-4, 1.2e-4] to [9.20e-6, 5.44e-5, 1.61e-4, 2.88e-4]. Python matches R main to 1e-15 relative; the last-ulp differences come fromnp.sumvs R's long-doublesumin the prefix powers, which predate this change.Tests
set.seed(42), so I drew the same shapes from NumPy; these are property tests. Plus R main's literal roots for degrees 2 and 3 at rtol 1e-13.NNS_DISABLE_NATIVE=1: 2913 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 #143, #125 and #123 mirrors together: SHIP.
Mirrors OVVO-Financial/NNS#125