Skip to content

copula: 0, not 1, when every margin lies on one side of its target - #179

Closed
gitRasheed wants to merge 1 commit into
rasheed/py-mode-class-tiesfrom
rasheed/py-copula-degenerate-target
Closed

gitRasheed wants to merge 1 commit into
rasheed/py-mode-class-tiesfrom
rasheed/py-copula-degenerate-target

Conversation

@gitRasheed

Copy link
Copy Markdown
Collaborator

R's NNS.copula returned 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_nd in _nnscore_bindings.cpp and the NumPy path in copula.py compute each margin's lower share LPM(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.
  • Before and after, with after equal to R main: a 10 x 10 grid at target (0, 0) 1 -> 0, [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

Review

GPT-6.1 Sol reviewed the #143, #125 and #123 mirrors together: SHIP.

Mirrors OVVO-Financial/NNS#143

… 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.
@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 cdf2bbcd51393b7f5af6f97258153dc7a0d5a1e6 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-copula-degenerate-target 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