Skip to content

nns_copula: perfect-dependence shortcut checks each pair - #165

Closed
gitRasheed wants to merge 1 commit into
rasheed/mirror-moments-cdffrom
rasheed/mirror-dependence
Closed

gitRasheed wants to merge 1 commit into
rasheed/mirror-moments-cdffrom
rasheed/mirror-dependence

Conversation

@gitRasheed

Copy link
Copy Markdown
Collaborator

The perfect-dependence shortcut returned 1 only when the degree-0 pair sum was choose(d, 2). That misses perfect dependence with mixed signs for d >= 3: in (x, x, -x) one pair is fully concordant and two fully discordant, so the sum is 1 and the formula runs instead. We mirror the R rule, which returns 1 when every pair is fully concordant or fully discordant.

Stacked on #164; merge with a merge commit.

Changes

  • copula._copula and the native copula_nd use the per-pair rule. For x = 1..100, nns_copula([x, x, -x]) goes from 0.5774 to 1 and [x, x, x, -x] from 0.2673 to 1, in both paths.
  • nns_reg's default order calls the copula on (x, x, y), so _default_order(x, -x) goes from 8 to 10.

Interior pair sums, (x, x, x) and (x, -x) are unchanged.

Tests

New NNS.copula parity cases for the mixed-sign matrices. The two positional NNS.boost multi-factor entries predate the R fix and are refilled, because the default order feeds the boost feature search: feature.frequency moves from 0.2561 0.2439 to 0.2558 0.2442. The parity cache encodes R 13.3 plus the fixes in OVVO-Financial/NNS#73-#92.

Mirrors OVVO-Financial/NNS#75
Part of OVVO-Financial/NNS#61

Review

GPT-6.1 Sol reviewed this slice and found nothing. It checked mixed-sign shortcuts against live R, including binary ties and two observations.

… fix)

The shortcut returned 1 only when the pair sum of degree-0 co-partial
moments was choose(d, 2), or 0 for d = 2. That drops perfect dependence
with mixed signs for d >= 3: in (x, x, -x) one pair is fully concordant
and two are fully discordant, so the sum is 1 and the formula ran. As
in R NNS.copula (dep-sign-and-ties), return 1 when every pair is fully
concordant (1) or fully discordant (0), in copula._copula and the
native copula_nd. nns_reg's default order inherits it, since it calls
the copula on (x, x, y).

Before -> after (= R), x = 1..100, native and fallback:
  nns_copula([x, x, -x])        0.5774 -> 1
  nns_copula([x, x, x, -x])     0.2673 -> 1
  _default_order(x, -x)         8      -> 10
Unchanged: the interior-pair-sum integer matrices, (x, x, x), (x, -x).
New NNS.copula entries for the mixed-sign tests. The two positional
NNS.boost multi-factor entries predate the R fix (the default order feeds
the boost feature search) and were refilled: feature.frequency
0.2561 0.2439 -> 0.2558 0.2442.
@gitRasheed
gitRasheed force-pushed the rasheed/mirror-dependence branch from 2cd45bb to df1f9c5 Compare November 2, 2026 23:09
@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 df1f9c577cc9169a77bd96e5d93b4ecb65c33941 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/mirror-dependence branch November 7, 2026 18:53
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