get_single_reverse_neighbors: Find reverse neighbors for a single NNGP node

View source: R/v03_RWNNGP_sampler.R

get_single_reverse_neighborsR Documentation

Find reverse neighbors for a single NNGP node

Description

Identifies all "children" (reverse neighbors) for a specific target location j in a Nearest-Neighbor Gaussian Process (NNGP). It searches the neighbor matrix to find all locations k that condition upon location j.

Usage

get_single_reverse_neighbors(target_node, neighbor_idx)

Arguments

target_node

Integer. The index of the location j whose reverse neighbors you want to find.

neighbor_idx

Integer matrix (M \times k). Neighbor indices for all locations, output from computeNeighbors.

Details

This function optimizes the reverse lookup for a single node by avoiding the full O(M) list construction loop. It uses vectorization to scan rows of the neighbor matrix where the row index k is greater than the target index j, enforcing the Directed Acyclic Graph (DAG) structure of the NNGP.

Value

An integer vector containing the indices of all locations k that have target_node as a neighbor, maintaining the NNGP ordering constraint (j < k).

Author(s)

Fabian Ketwaroo

Examples

nn_matrix <- matrix(c(0, 0,
                      1, 0,
                      1, 2,
                      1, 3), nrow = 4, byrow = TRUE)

# Find which nodes have node 1 as a neighbor
get_single_reverse_neighbors(target_node = 1, neighbor_idx = nn_matrix)


BayesNSGP documentation built on Sept. 10, 2026, 5:08 p.m.