Skip to content

diff: add dy_d_best — reconciled dy.d_ (dy.dx step + NNS.stack on X*)#132

Merged
OVVO-Financial merged 2 commits into
mainfrom
claude/dy-d-v057-restore
Jul 17, 2026
Merged

diff: add dy_d_best — reconciled dy.d_ (dy.dx step + NNS.stack on X*)#132
OVVO-Financial merged 2 commits into
mainfrom
claude/dy-d-v057-restore

Conversation

@OVVO-Financial

@OVVO-Financial OVVO-Financial commented Jul 17, 2026

Copy link
Copy Markdown
Owner

Summary

Adds nns.dy_d_best, a reconciliation of the original NNS 0.5.7 dy.d_ (Vinod & Viole 2020, SSRN 3681436) with the current regression engine. It keeps the v0.5.7 finite-difference scaffolding but makes two changes so the estimates are uniform across identically-distributed regressors and share step logic with dy.dx.

It is the byte-for-byte counterpart of the reconciled R dy.d_ in OVVO-Financial/NNS (PR #54).

Two changes

  1. h_step shares the dy.dx logic — a locally-adaptive step centred on the evaluation point's percentile, h_step = VaR(p+H, 1, x) − VaR(p−H, 1, x) with p = lpm_ratio(1, eval, x), and no cumulative window. This removes the cross-regressor scatter the raw v0.5.7 step produced.
  2. Estimates from nns_stack on the equal-weight synthetic regressor X* via cbind(X*, X*), with method=(1, 2), dim_red_method="equal", order="max", folds=5. The cross-validated n.best regularises the sharper current engine.

Bandwidths follow v0.5.7 (h_s = 1/log(size(x), [2, 10]), + 10·h_s, doubled when nns_dep(x[:, wrt], y) < 0.5). First = (upper − lower)/(2·h_step), Second = (upper − 2f(x) + lower)/h_step², blended with nanmean.

Result (Example 2, at (1,1,1,1,1))

First = [0.94, 0.95, 0.93, 0.92, 0.93] — tight and uniform (the raw design scattered 0.29–0.62). ~1.4× above the paper's 0.65 (expected: the current engine is sharper; folds=5 sets the level), and closer to the analytic 2.0. Mixed derivative for x₁²·x₂² at (.5,.5) recovers ≈ 1.0.

Validation

  • Vector, matrix (tuple), and mixed branches all exercised.
  • Bandwidths and h_step validated to match the R port to numerical precision.
  • Invariant tests updated (export, shapes, single-wrt 1-D output, mixed, determinism, pinned golden values). 17 diff tests pass; ruff clean.

🤖 Generated with Claude Code

claude added 2 commits July 17, 2026 17:45
…mator

Adds nns.dy_d_best, a faithful Python port of the original NNS 0.5.7 dy.d_ used
to produce the results in Vinod & Viole (2020), SSRN 3681436. It differs from
the shipped dy_d (which sources f(x +/- h) from nns_stack(method=(1, 2))): it
uses nns_reg(dim_red_method='equal', point_only=True) directly (no smoothing),
a quantile-spacing step, a degree-0 quantile grid, plain-mean aggregation,
distance = 2*h_step, and a plain nanmean blend across the v0.5.7 bandwidths
h_s = 1/log(size(x), [2, 10]) extended by 10*h_s and doubled when
nns_dep(x[:, wrt], y) < 0.5.

The wrapper is byte-for-byte the same algorithm as the restored R NNS.dy.d_
(OVVO-Financial/NNS), so R and Python agree given the same NNS.reg engine;
against the current engine both differ from the 0.5.7 paper values because the
regression engine itself changed since 0.5.7.

Adds invariant tests (export, shapes, single-wrt 1-D output, mixed, determinism,
pinned golden values).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
… + NNS.stack)

Reworks dy_d_best from the raw-engine v0.5.7 port into the reconciled estimator:

  * h_step now shares the dy.dx() logic - a locally-adaptive step centred on the
    evaluation point's percentile, h_step = VaR(p+H,1,x) - VaR(p-H,1,x) with
    p = lpm_ratio(1, eval, x) - and drops the cumulative window. This is what
    makes the estimates uniform across identically-distributed regressors
    (previously 0.29-0.62 scatter on the 5-way product benchmark).
  * estimates now come from nns_stack on the equal-weight synthetic regressor X*
    via the increased-dimension trick cbind(X*, X*), with method=(1, 2),
    dim_red_method='equal', order='max', folds=5. The cross-validated n.best
    regularises the sharper current engine.

On Example 2 of Vinod & Viole (2020, SSRN 3681436) this yields a tight, uniform
First = [0.94, 0.95, 0.93, 0.92, 0.93] at (1,1,1,1,1) (vs the paper's ~0.65 on
the retired 0.5.7 engine), and the mixed derivative for x1^2*x2^2 at (.5,.5)
recovers ~1.0. Bandwidths, First=(u-l)/(2h), Second=(u-2f+l)/h^2 blended with
nanmean across bandwidths. Golden test values updated.

Byte-for-byte the same algorithm as the reconciled R dy.d_ (OVVO-Financial/NNS).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@OVVO-Financial OVVO-Financial changed the title diff: add dy_d_best — original v0.5.7 dy.d_ finite-difference estimator diff: add dy_d_best — reconciled dy.d_ (dy.dx step + NNS.stack on X*) Jul 17, 2026
@OVVO-Financial
OVVO-Financial merged commit acce968 into main Jul 17, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants