---
title: Nearest-Neighbor Derivative Process (NNDP)
url: https://www.emergentmind.com/topics/nearest-neighbor-derivative-process-nndp
type: topic
---

# Nearest-Neighbor Derivative Process (NNDP)

Searching arXiv for the cited NNDP paper and closely related nearest-neighbor GP context.
The Nearest-Neighbor Derivative Process (NNDP) is a scalable Gaussian-process framework for joint inference on a spatial process $w(s)$ and its derivatives, particularly the gradient field $D(s)=\nabla w(s)$ and, when smoothness permits, second derivatives such as the Hessian. It is designed for settings in which full Gaussian-process inference on $[w,\nabla w]$ is computationally prohibitive because dense covariance matrices induce cubic complexity in the number of locations. NNDP replaces the dense joint density by a product of sparse nearest-neighbor conditionals on an augmented state that bundles function values and derivatives at each site, thereby reducing the computational time complexity from $O(n^3)$ to $O(n)$ when the neighborhood size and spatial dimension are treated as fixed [2509.02752].

## 1. Problem setting and motivation

Many tasks in spatial analysis require not only interpolation of a latent field $w(s)$ but also inference on spatial rates of change. The target object is often the gradient field $D(s)=\nabla w(s)$, and in some applications second derivatives are also relevant for curvature or Hessian analysis. A full Gaussian process for $[w,\nabla w]$ is statistically natural because any finite collection of function values and derivatives is multivariate Gaussian when the kernel is sufficiently differentiable. The computational obstacle is that the corresponding covariance matrices are dense and scale cubically with the number of spatial locations [2509.02752].

NNDP addresses this obstacle by extending Nearest-Neighbor Gaussian Process ideas to derivative inference. The central construction augments the state at each location $s_i$ as
$$
z_i=\left[w(s_i),\frac{\partial w}{\partial s_1}(s_i),\ldots,\frac{\partial w}{\partial s_d}(s_i)\right]^T \in \mathbb{R}^{1+d},
$$
and then approximates the joint density of the stacked vector $z=(z_1^T,\ldots,z_n^T)^T$ by a directed acyclic nearest-neighbor factorization. This preserves a valid stochastic-process interpretation for the joint field of function values and derivatives while avoiding dense $n\times n$ algebra.

The method is positioned against a straightforward plug-in estimator that first fits a scalable Gaussian process for $w(s)$ and then approximates $\nabla w(s)$ by finite differences of predicted means. That approach is sensitive to the step size $h$, to grid spacing, and to sampling irregularities; moreover, the approximate gradient may not be a valid Gaussian process, which compromises inference and uncertainty quantification. NNDP instead directly models $[w,\nabla w]$ as a nearest-neighbor Gaussian process and therefore supplies coherent posterior inference for both fields without tuning $h$ [2509.02752].

## 2. Gaussian-process and derivative-process foundation

NNDP begins from a parent Gaussian process
$$
w(s)\sim GP(\mu(s),k(s,s';\theta)), \qquad s,s'\in D.
$$
The derivative process is defined in the mean-square sense, so kernel smoothness is decisive. First derivatives require $k$ to be once differentiable in each argument, typically ensured for Matérn with $\nu>1$ or for RBF. Second derivatives require $k$ to be twice differentiable, for example Matérn with $\nu>2$. Under these conditions, the joint Gaussian structure for function values and gradient components is determined by differentiating the kernel [2509.02752]:
$$
\operatorname{cov}(w(s),w(s'))=k(s,s'),
$$
$$
\operatorname{cov}\!\left(\frac{\partial w}{\partial s_p}(s),w(s')\right)=\frac{\partial k(s,s')}{\partial s_p},
$$
$$
\operatorname{cov}\!\left(w(s),\frac{\partial w}{\partial s'_q}(s')\right)=\frac{\partial k(s,s')}{\partial s'_q},
$$
$$
\operatorname{cov}\!\left(\frac{\partial w}{\partial s_p}(s),\frac{\partial w}{\partial s_q}(s')\right)=\frac{\partial^2 k(s,s')}{\partial s_p\partial s'_q}.
$$
If second derivatives are modeled, analogous formulas hold for Hessian entries $H_{pq}(s)=\partial^2 w(s)/\partial s_p\partial s_q$ and their cross-covariances.

For isotropic kernels with $k(s,s')=\kappa(r)$, $r=\|h\|$, and $h=s-s'$, the derivative formulas take a compact vector form:
$$
\nabla_s k(s,s')=\kappa'(r)\frac{h}{r}, \qquad \nabla_{s'} k(s,s')=-\kappa'(r)\frac{h}{r},
$$
and
$$
\nabla_s\nabla_{s'}k(s,s')
=
-\left[
\kappa''(r)\frac{hh^T}{r^2}
+
\kappa'(r)\left(\frac{I}{r}-\frac{hh^T}{r^3}\right)
\right].
$$
These identities furnish the $d\times d$ cross-covariance matrix for gradient components.

Two kernel families are explicit in the NNDP formulation. For the RBF kernel
$$
k(s,s')=\sigma^2\exp\!\left(-\frac{\|s-s'\|^2}{2\ell^2}\right),
$$
with $h=s-s'$ and $r=\|h\|$,
$$
\frac{\partial k}{\partial s_p}=-k(s,s')\frac{h_p}{\ell^2}, \qquad
\frac{\partial k}{\partial s'_q}=+k(s,s')\frac{h_q}{\ell^2},
$$
$$
\frac{\partial^2 k}{\partial s_p\partial s'_q}
=
k(s,s')\left[\frac{\delta_{pq}}{\ell^2}-\frac{h_ph_q}{\ell^4}\right].
$$
RBF is infinitely differentiable, so all derivative processes exist. For the Matérn kernel with smoothness $\nu$,
$$
k(s,s')=\sigma^2 c_\nu (\rho)^\nu K_\nu(\rho), \qquad \rho=\|s-s'\|/\ell, \qquad c_\nu=2^{1-\nu}/\Gamma(\nu),
$$
the radial derivatives are
$$
\kappa'(r)= - \sigma^2 c_\nu \ell^{-1}\rho^\nu K_{\nu-1}(\rho),
$$
$$
\kappa''(r)= + \sigma^2 c_\nu \ell^{-2}\rho^\nu K_{\nu-2}(\rho).
$$
Plugging these into the isotropic formulas yields explicit cross-covariances for gradients and Hessians. The smoothness thresholds are explicit: first derivatives exist in mean square when $\nu>1$, and second derivatives exist when $\nu>2$ [2509.02752].

## 3. Nearest-neighbor factorization and process construction

The defining step in NNDP is the nearest-neighbor factorization of the augmented state. After choosing a directed acyclic ordering of locations $\{s_i\}_{i=1}^n$, one selects for each site $s_i$ a neighbor set $N_i$ consisting of the indices of the $m$ nearest neighbors among $\{s_1,\ldots,s_{i-1}\}$. NNDP then defines the approximation
$$
p(z_1,\ldots,z_n\mid \theta)\approx \prod_{i=1}^n p(z_i\mid z_{N_i},\theta),
$$
where each conditional factor is multivariate normal with mean and covariance derived from the corresponding blocks of the full covariance matrix of the stacked augmented state [2509.02752]:
$$
\mu_{i\mid N_i}
=
\mu_i + C_{i,N_i}C_{N_i,N_i}^{-1}(z_{N_i}-\mu_{N_i}),
$$
$$
\Sigma_{i\mid N_i}
=
C_{i,i}-C_{i,N_i}C_{N_i,N_i}^{-1}C_{N_i,i}.
$$

Here $\mu_i\in\mathbb{R}^{1+d}$ collects the mean components
$$
[\mu(s_i);\partial\mu/\partial s_1(s_i);\ldots;\partial\mu/\partial s_d(s_i)],
$$
$C_{i,i}\in\mathbb{R}^{(1+d)\times(1+d)}$ is the on-site covariance block of $w$ and its derivatives at $s_i$, $C_{i,N_i}\in\mathbb{R}^{(1+d)\times(m(1+d))}$ comprises cross-covariances between $[w,\nabla w]$ at $s_i$ and all stacked $[w,\nabla w]$ at neighbors $N_i$, and $C_{N_i,N_i}$ is the block covariance over neighbors. These blocks are assembled from $k(s,s')$, its first derivatives, and its mixed second derivatives evaluated at the relevant pairs of locations.

This construction extends NNGP from $w(s)$ to $z(s)$ by retaining the same sparse conditional structure while replacing scalar or single-field covariance entries with block covariances formed by kernel differentiation. The result is a scalable joint model for the parent field and its derivative field. The recommended neighborhood size is fixed $m$, with values in $10$–$25$ typically balancing accuracy and speed. This suggests that the practical operating regime is one in which local conditioning captures the dominant dependence structure while keeping local linear algebra modest [2509.02752].

## 4. Likelihood, inference, prediction, and computational scaling

Under the NNDP approximation, the log-likelihood of the augmented state is
$$
\ell(\theta;z)=\sum_{i=1}^n \log N(z_i;\mu_{i\mid N_i}(\theta),\Sigma_{i\mid N_i}(\theta)).
$$
In practice, derivatives need not be observed. The likelihood may instead be written on observed $y$ and latent $w$, with NNDP supplying the conditional structure for either maximum-likelihood or Bayesian inference. The observation model for noisy function evaluations is
$$
y(s_i)=w(s_i)+\epsilon_i, \qquad \epsilon_i\sim N(0,\tau^2),
$$
and if derivative observations are available,
$$
d_p(s_i)=\frac{\partial w}{\partial s_p}(s_i)+\eta_{ip}, \qquad \eta_{ip}\sim N(0,\tau_d^2),
$$
independently. The joint model remains Gaussian after adding the appropriate block-diagonal noise components [2509.02752].

Parameter inference can proceed by maximum likelihood or by Bayesian computation. Maximum likelihood uses optimization of $\ell(\theta;y)$ or the corresponding latent-variable objective via quasi-Newton methods such as L-BFGS. In the Bayesian formulation, priors are placed on $\theta=(\sigma^2,\ell,\nu,\ldots)$ and $\tau^2$; the specified examples are IG priors on $\sigma^2$, uniform on $\ell$, fixed $\nu$ such as $\nu\in\{3/2,5/2\}$, and IG on $\tau^2$, with posterior sampling through Gibbs/Metropolis within the NNDP conditional structure.

The linear-time scaling is obtained because each site only conditions on $m$ neighbors. With fixed $m$ and $d$, the per-site Cholesky factorization of $C_{N_i,N_i}\in\mathbb{R}^{(m(1+d))\times(m(1+d))}$ costs $O((m(1+d))^3)$, and the remaining local solves and block operations cost $O((m(1+d))^2)$ per site. Consequently, the total time is
$$
O\!\left(n(m(1+d))^3\right),
$$
which is linear in $n$ when $m$ and $d$ are small constants, and the memory cost is
$$
O\!\left(n(m(1+d))^2\right)
$$
without forming dense $n\times n$ matrices. Numerical stability is handled through Cholesky decompositions of $C_{N_i,N_i}$ with jitter, such as adding $\epsilon I$ with $\epsilon\approx 1\mathrm{e}{-6}\sigma^2$ if needed, together with kernel parameter constraints, reasonable nugget $\tau^2$, and coordinate standardization [2509.02752].

Prediction at a new location $s^*$ follows the same local-conditioning principle. Defining
$$
z_*=\left[w(s^*),\frac{\partial w}{\partial s_1}(s^*),\ldots,\frac{\partial w}{\partial s_d}(s^*)\right]^T
$$
and selecting a neighbor set $M_*$ of size $m$ from the training locations, the predictive distribution is
$$
E[z_*\mid z_{M_*}]
=
\mu_* + C_{*,M_*}C_{M_*,M_*}^{-1}(z_{M_*}-\mu_{M_*}),
$$
$$
\operatorname{Var}[z_*\mid z_{M_*}]
=
C_{*,*}-C_{*,M_*}C_{M_*,M_*}^{-1}C_{M_*,*}.
$$
The requisite blocks use exactly the same kernel derivatives as the training-time construction.

## 5. Theoretical properties and methodological contrasts

NNDP is presented as a valid stochastic process for
$$
z(s)=[w(s),\nabla w(s)]
$$
over $D\setminus Z$, where $Z$ is a set of Lebesgue measure zero associated with neighbor-set discontinuities, such as ties in nearest-neighbor selection. The validity claim follows the NNGP construction together with derivative-process existence, and yields a proper joint Gaussian density over any finite collection. Smoothness is inherited in a corresponding sense: if the parent Gaussian process $w(s)$ is mean-square differentiable of order $1$ or $2$, then the NNGP approximation $\tilde w(s)$ is also mean-square differentiable of order $1$ or $2$ outside a measure-zero set, and the derivative and cross-covariance functions for NNDP are continuous away from $Z$. For Matérn kernels, mean-square differentiability of order $m$ requires $\nu>m$ [2509.02752].

As a Vecchia-type approximation, NNDP is also described as consistent in the limit of increasing neighborhood size. Increasing $m$ shrinks approximation error and recovers the full Gaussian-process derivative process as $m\to n$ with appropriate orderings. Error bounds are inherited from Vecchia approximations for Gaussian-process likelihoods, while derivative-process blocks improve because they are constructed by differentiating the same parent kernel. Under correct kernel specification, the NNDP conditional means deliver approximately unbiased gradient estimates, and uncertainty quantification is valid in the NNDP model.

The principal methodological contrast is with plug-in finite differences. In that approach, a directional derivative is approximated as
$$
D_u w(s)\approx \frac{\hat w(s+hu)-\hat w(s)}{h},
$$
where $\hat w$ is a Gaussian-process predictor. The stated deficiencies are the need to tune $h$, sensitivity to grid spacing and sampling irregularity, numerical errors for small $h$, bias for large $h$, absence of a joint Gaussian process for gradients, and increasing instability for higher-order derivatives. NNDP avoids these issues by modeling $[w,\nabla w]$ jointly with valid cross-covariances and by enabling principled likelihood-based or posterior-based inference. The comparison to other scalable Gaussian-process approaches is narrower but equally important: NNGP, low-rank, and tapering methods target $w(s)$ only and do not natively supply derivative-process covariances. NNDP differs by augmenting the state with derivatives and building blockwise covariances using kernel derivatives, thereby preserving valid uncertainty for spatial rates of change [2509.02752].

## 6. Empirical behavior, applications, and limitations

The empirical evaluation reported for NNDP comprises simulations and real-data analyses. In simulations, two setups are emphasized. Pattern 1 is a two-dimensional sinusoidal surface,
$$
\omega_1(s)=10[\sin(3\pi s_1)+\cos(3\pi s_2)],
$$
with $d=2$, regular grids, and Matérn $\nu=5/2$, compared across exact GP, NNDP, and plug-in finite differences. Pattern 2 is a one-dimensional highly oscillatory function,
$$
\omega_2(s)=\sin(100(s_1-0.5)^2),
$$
used to assess sensitivity to grid spacing and irregular sampling. The evaluation metrics are correlation with truth, mean squared error for gradients, and runtime [2509.02752].

The reported quantitative results are specific. For Pattern 1 on a regular grid, NNDP correlations are approximately $0.999$–$1.000$ with low MSEs; finite differences are substantially worse and sensitive to $h$, and exact GP matches NNDP when feasible for small $n$. For Pattern 2, NNDP consistently outperforms finite differences, while the optimal finite-difference scale depends on grid size and irregular sampling. Runtime results are used to illustrate the asymptotic scaling: for $n$ up to $40{,}000$ with $m=10$, NNDP times scale linearly, with an example of approximately $40$ seconds, whereas exact GP exhibits cubic behavior, with an example of $3108$ seconds for $n=1600$. Finite differences are described as slower than NNDP in comparable settings because they require separate predictions at perturbed locations $s\pm hu$.

Two real-data applications illustrate the intended use cases. In VisiumHD spatial transcriptomics on mouse brain data, involving $19{,}059$ genes and $98{,}917$ spots, NNDP with Matérn $\nu=5/2$ produced high-resolution gradient maps aligned with anatomical boundaries, including the hippocampal formation, CA fields, and dentate gyrus; representative gene gradients were computed in approximately $81$ seconds. In NARR air temperature data over the continental United States with $7{,}706$ grid cells, NNDP identified large temperature gradients along topographic features such as the Sierra Nevada, Cascade Range, and Rockies [2509.02752].

Practical guidance in the NNDP description focuses on smoothness, neighborhood size, and model assumptions. Values of $m$ in $10$–$25$ typically balance accuracy and speed, while larger $m$ improve approximation at the cost of increased local cubic work in $(m(1+d))$. Matérn kernels are recommended for controlled smoothness, with $\nu\ge 3/2$ for first derivatives in practice and $\nu\ge 5/2$ for second derivatives; fixing $\nu$ to values such as $3/2$ or $5/2$ is described as stabilizing inference. Anisotropy can be modeled by separate length scales per coordinate. The limitations are equally explicit: derivative estimation near domain boundaries is harder because there are fewer neighbors and more extrapolation, nonstationary gradients require kernel extensions because NNDP assumes stationarity via $k$, and computational cost scales with $(1+d)^3$ per site, making the method practical for $d\le 3$–$5$ rather than very high-dimensional spatial domains. This suggests that NNDP is best viewed as a scalable derivative-process model for low-dimensional spatial settings with smooth kernels and locality-compatible dependence structure [2509.02752].

Source: https://www.emergentmind.com/topics/nearest-neighbor-derivative-process-nndp