Repository navigation
diff: dy_dx uses every bandwidth when small samples repeat one - #186
Closed
gitRasheed wants to merge 1 commit into
Closed
gitRasheed wants to merge 1 commit into
gitRasheed wants to merge 1 commit into
Conversation
…x-duplicate-bands) Mirrors R dy.dx (OVVO-Financial/NNS dydx-duplicate-bands). The bandwidths h_s = round(exp(seq(log 2, log floor(sqrt(n)), length.out = 5))) repeat for n < 49. R looped over the values and assigned each block at which(h == h_s), a length-2 index for a repeat, so rbind dropped those blocks, and below n = 16 every value repeats and dy.dx failed. Python copied that, using only the bandwidths that occur once (or the distinct ones below 16). Both now average over all five positions. Before -> after (= R main), dy_dx(seq(0, 3, length.out = 10), x^2, 1.5): first derivative 2.91851 -> 2.91861 (R main 2.9186064885499) second derivative 0.15957 -> 0.16054 (R main 0.1605427056170) For n = 12, 20 and 30 Python now differs from R main because R main's smoothed NNS.reg fit changed with its later dependence work, which Python mirrors in the re-vendor, so the tests check those against R's own construction from Python's nns_reg instead of literal values. 3 dy.dx.numeric cache entries (n = 24 and 30, which repeat bandwidths) predate the R change and were refilled from the cache's R build plus that change alone; the other 4 came back identical.
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
dy.dxuses five bandwidthsh_s = round(exp(seq(log(2), log(floor(sqrt(n))), length.out = 5))), which repeat for n < 49. It looped over the values and assigned each block atwhich(h == h_s), a length-2 index for a repeat, sorbinddropped those blocks. Below n = 16 every value repeats anddy.dxfailed. Python copied this, using only the bandwidths that occur once, or the distinct ones below 16. OVVO-Financial/NNS#147 (merged) loops over the positions, so every bandwidth counts. This slice mirrors it.Stacked on #185; merge with a merge commit.
Changes
_dy_dx_numeric(diff.py) builds the derivative windows for all five entries ofh_s, repeats included.dy_dx(seq(0, 3, length.out = 10), x^2, 1.5): first derivative 2.91851 -> 2.91861 and second 0.15957 -> 0.16054, equal to R main (2.9186064885499, 0.1605427056170) to 1e-11. For n = 12, 20 and 30 Python differs from R main because R main's smoothedNNS.regfit itself changed with its dependence work in Fix #95-#101: NNS.dep, NNS.caus and NNS.seas redesigns, with the follow-up fixes NNS#107 (the point estimates for n = 20 already differ in the second decimal). Python takes that with the core re-vendor.Tests
nns_reg(rtol 1e-12), plus R main's literal values for n = 10.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 #146, #147 and #148 mirrors together: SHIP. Its one nit, docs/conventions.md still saying repeated bandwidths are skipped, is fixed in this slice.
Mirrors OVVO-Financial/NNS#147