Repository navigation
copula: 0, not 1, when every margin lies on one side of its target - #179
Closed
gitRasheed wants to merge 1 commit into
Closed
gitRasheed wants to merge 1 commit into
gitRasheed wants to merge 1 commit into
Conversation
… copula-degenerate-target) Mirrors R NNS.copula (OVVO-Financial/NNS copula-degenerate-target). With every margin's observations on one side of its target, each co-partial moment equals its independence product whatever the dependence, and every pair is trivially fully concordant or discordant, so the perfect-dependence shortcut returned 1. It now returns 0 there, and the shortcut to 1 needs every margin's lower share strictly inside (0, 1). Both the native copula_nd and the NumPy path compute the lower shares before the shortcut. Before -> after (= R main): nns_copula(10 x 10 grid, target=[0, 0]) 1 -> 0 nns_copula([x, x] for x = 1..10, target=[0, 0]) 1 -> 0 nns_copula(rep(0:1) vs rep(1:0), target=[1, 1]) 1 -> 0 2 NNS.copula cache entries (a target of [1, 1] on 0/1 data, continuous TRUE and FALSE) predate the R change and were refilled from the cache's R build plus that change alone; the other 35 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
NNS.copulareturned 1 when every margin's observations lay on one side of its target. Each pair is then trivially fully concordant or discordant, so the perfect-dependence shortcut fired, even though each co-partial moment equals its independence product there whatever the dependence. OVVO-Financial/NNS#143 (merged) returns 0 in that case and only takes the shortcut to 1 when every margin's lower share is strictly inside (0, 1). This slice mirrors it.Stacked on #178; merge with a merge commit.
Changes
copula_ndin_nnscore_bindings.cppand the NumPy path in copula.py compute each margin's lower shareLPM(0, t_j, x_j)before the shortcut. All shares 0 or 1 returns 0; the shortcut to 1 needs none of them at 0 or 1. The shares are then reused as the independence anchors, as before.[x, x]for x = 1..10 at (0, 0) 1 -> 0, 0/1 columns at target (1, 1) 1 -> 0. Perfect dependence at targets inside the data still gives 1, and one margin inside its data with the other one-sided keeps the full measure (0.52704627669472992 on R main and here).Tests
[x, x]and 0/1 cases at one-sided targets give exactly 0, and R's five perfect-dependence cases give exactly 1 for continuous TRUE and FALSE. I left out R'srexp(1000)case, since the NumPy RNG can't reproduce it._reg_enginecalls the copula with column-mean targets, which always sit inside a varying margin, so no NNS.reg entry moves.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#143