Repository navigation
Stochastic dominance: midpoint check and compensated prefix sums - #167
Closed
gitRasheed wants to merge 3 commits into
Closed
gitRasheed wants to merge 3 commits into
gitRasheed wants to merge 3 commits into
Conversation
This was referenced Nov 2, 2026
gitRasheed
force-pushed
the
rasheed/mirror-dominance
branch
from
November 2, 2026 04:12
b484a71 to
795254e
Compare
gitRasheed
force-pushed
the
rasheed/mirror-timeseries
branch
from
November 2, 2026 04:12
99810a0 to
d581bd9
Compare
…nts (mirror of the R fix) When the continuous ratios agree at every knot and X's is lower between two knots, X dominates Y, but the test saw equal curves and returned no dominance in both directions. Two linear-fractional ratios that agree at both ends of an interval and at its midpoint agree on the whole interval, so, as in R's sd_dom_pair (sd-dominance), also compare them at the midpoint while the curves have not yet differed. Before -> after (= R), fsd(type="continuous"); fsd_uni x>y, y>x: x = [0, 1, 1], y = [0, 0, 1] 0; 0, 0 -> 1; 1, 0 x = [1, 1], y = [0, 1] 0; 0, 0 -> 1; 1, 0 SSD and TSD need no such check: their curves are polynomial between the knots with the next-lower LPM as derivative.
The pairwise SD test treats differences up to 64 * eps * S^d as ties,
but its prefix sums and the sample mean were plain running sums whose
rounding grows with the sample size. As in R's SD finish_col
(sd-dominance), use Neumaier compensated sums. np.cumsum adds in order,
so the per-step error terms are recovered from the running sums without
a Python loop, and the result equals R's sequential Neumaier sum.
Before -> after (= R), z = qnorm(ppoints(1e5)), x = z + 100, y = 2z + 100:
ssd / tsd 0 / 0 -> 1 / 1 ("X SSD Y" / "X TSD Y")
ssd_uni / tsd_uni 0 / 0 -> 1 / 1
The existing SD parity cases are unchanged.
… fix) The tie tolerances scaled with |value|^degree, so a common shift such as a price level of 20000 grew the TSD tolerance past real differences: tsd_uni(x + 20000, y + 20000) was 1 where tsd_uni(x, y) is 0. As R now does, every test except discrete FSD centres the pair on its joint midrange c and uses E1 = 64 eps S + din (din = 4 eps |c|) for the mean gate, SSD and the continuous FSD ratios, and 64 eps S^2 + 2 din (|LPM1x| + |LPM1y| + din) per threshold for TSD.
gitRasheed
force-pushed
the
rasheed/mirror-timeseries
branch
from
November 2, 2026 23:09
d581bd9 to
d2767c8
Compare
gitRasheed
force-pushed
the
rasheed/mirror-dominance
branch
from
November 2, 2026 23:09
795254e to
11a8a43
Compare
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.
Two fixes from the R stochastic dominance PR that the first mirror did not have. Continuous FSD missed dominance when the two ratio curves agreed at every knot and differed between them. The prefix sums were plain running sums, whose rounding grows with n past the 64 * eps * S^d tie tolerance.
Stacked on #166; merge with a merge commit.
Changes
fsd([0, 1, 1], [0, 0, 1], "continuous")goes from 0 to 1, as in R.ssd/tsdgo from 0/0 to 1/1.The existing SD parity cases are unchanged.
Tests
New parity cases for the midpoint and large-sample cases in
NNS.FSD,NNS.FSD.uni,NNS.SSD,NNS.TSDand the efficient set. The parity cache encodes R 13.3 plus the fixes in OVVO-Financial/NNS#73-#92.Mirrors OVVO-Financial/NNS#82
Update
This push mirrors OVVO-Financial/NNS#105. Each pair is compared centred on its joint midrange, with a tolerance for the rounding of the shifted inputs. The fallback matches R and the vendored core on the translation cases: TSD with both samples shifted by 20000 now matches the unshifted answer (0, where it gave 1), and at +1e6 the efficient set is [0], where it was [0, 1].
Review
GPT-6.1 Sol reviewed this slice and found nothing. It compared 500 small, tied, constant and unequal-length cases against live R.