Part X: Sensor Fusion, World Models, and Spatial AI
Chapter 54: Graph Neural Networks for Sensor Networks

Spatial, process, and dynamic graphs

"Nobody handed me the wiring diagram, so I inferred one from the correlations. It was confident, tidy, and wrong in exactly the two places a leak would have shown up."

A Graph-Building AI Agent

Prerequisites

This section builds directly on Section 54.1, where sensors became nodes and their relations became edges. Here we ask the harder question: where does the edge set actually come from? You will lean on the distance and positioning notions of Chapter 25, on the correlation and mutual-information tools of Chapter 8, and on the idea (from Chapter 11) that a graph encodes which variables are allowed to talk to which. Comfort with a weighted adjacency matrix \(A \in \mathbb{R}^{N \times N}\) and with reading time synchronization (Chapter 3) as a precondition for comparing two streams is assumed.

The adjacency matrix is a modeling decision, not a given

A graph neural network is only as good as the graph you feed it, and for a sensor network that graph is almost never handed to you cleanly. You are choosing, edge by edge, which sensors are permitted to exchange evidence during message passing. Get it right and information flows along the pathways physics already uses, so a model learns from a handful of examples. Get it wrong and you either starve the network of real couplings or drown it in spurious ones. This section lays out the three families of answer: spatial graphs, where an edge means physical nearness; process graphs, where an edge means an engineered or causal pathway; and dynamic graphs, where the edge set itself is learned or changes with time. Knowing which family your problem belongs to is the single most consequential design choice in the chapter, more than the number of layers or the width of the hidden state.

Recall from Section 54.1 that message passing updates each node from its neighbors. The neighbor set is defined by \(A\). So constructing \(A\) is constructing the model's inductive bias: it declares, before any weight is trained, what "nearby in the world" means. The three families below answer that declaration differently.

Spatial graphs: geometry as the prior

What a spatial graph does is turn physical positions into edges. Why it works is the first law of geography: near things are more related than distant things, so two sensors a few meters apart usually see correlated phenomena. How you build one is a kernel over pairwise distance. The workhorse is a thresholded Gaussian on the distance \(d_{ij}\) between sensors \(i\) and \(j\):

$$A_{ij} = \begin{cases} \exp\!\left(-\dfrac{d_{ij}^2}{2\sigma^2}\right) & \text{if } \exp\!\left(-\dfrac{d_{ij}^2}{2\sigma^2}\right) \ge \kappa \\[2pt] 0 & \text{otherwise,} \end{cases}$$

where \(\sigma\) sets the correlation length scale and the threshold \(\kappa\) sparsifies the graph so distant pairs are simply disconnected. Two knobs, two jobs: \(\sigma\) controls how fast influence decays, \(\kappa\) controls how many neighbors survive. The alternative construction is a \(k\)-nearest-neighbor graph, which fixes the degree (every node keeps its \(k\) closest peers) rather than the radius; \(k\)-NN is the right call when sensor density varies wildly across the network, because a fixed radius would leave dense clusters over-connected and sparse regions isolated.

When spatial graphs shine is when the physical field is smooth and the medium is roughly homogeneous: air-quality monitors across a city, weather stations, seismic arrays, or the loop detectors of the METR-LA and PEMS-BAY traffic datasets you will meet in Section 54.3. A subtle but important refinement: for traffic and pipe flow, Euclidean distance lies. Two loop detectors on opposite sides of a highway median are meters apart yet functionally unrelated, while two detectors far apart along the same on-ramp are tightly coupled. The fix is to measure \(d_{ij}\) as road-network distance (shortest travel path) rather than straight-line distance, which quietly turns a spatial graph into a process graph.

Distance is a proxy for coupling, and sometimes a bad one

Every spatial graph makes one bet: that geometric proximity predicts statistical dependence. That bet pays off in a free field (heat, sound, pollutant dispersion) where influence really does fall off with distance. It fails wherever an engineered structure routes influence around geometry: a firewall between two rooms, a highway median, a valve that isolates two adjacent pipes. When you catch yourself drawing an edge because two sensors are close on a map, ask whether anything physical actually connects them. If the honest answer is "the medium in between," a spatial graph is right. If it is "a pipe, a wire, or a road," you want the process graph of the next subsection, because the process, not the map, carries the signal.

The snippet below builds a thresholded Gaussian adjacency from raw sensor coordinates and reports the resulting sparsity, the number that decides whether message passing is cheap.

import numpy as np

# 12 sensors scattered in a 2 km square (positions in meters).
rng = np.random.default_rng(0)
pos = rng.uniform(0, 2000, size=(12, 2))

# Pairwise Euclidean distance matrix.
diff = pos[:, None, :] - pos[None, :, :]
dist = np.sqrt((diff ** 2).sum(-1))

sigma = 400.0                       # correlation length scale (meters)
kappa = 0.1                         # keep an edge only if the kernel >= 0.1
W = np.exp(-(dist ** 2) / (2 * sigma ** 2))
np.fill_diagonal(W, 0.0)           # no self-loops here; GNN layers add them back
A = np.where(W >= kappa, W, 0.0)   # sparsify

deg = (A > 0).sum(1)
print(f"edges kept      : {int((A > 0).sum() // 2)}")
print(f"mean degree     : {deg.mean():.1f} neighbors/node")
print(f"isolated nodes  : {int((deg == 0).sum())}")
Constructing a thresholded Gaussian spatial adjacency from sensor coordinates. The length scale \(\sigma\) sets how fast influence decays and \(\kappa\) sparsifies the graph. Watch the two reported diagnostics: mean degree tells you the message-passing cost, and any isolated node is a sensor the GNN can never reach, a silent failure worth catching before training.

Process graphs: topology from the plant

A process graph replaces "close in space" with "connected by the process." What defines an edge here is a real conduit for influence: a pipe segment between two pressure sensors, a busbar between two substations, a conveyor between two stations, a shared shaft between two bearings. Why this beats a spatial graph in engineered systems is that the process topology is the causal structure. Water pressure propagates along pipes, not across the parking lot the pipes happen to run under; a fault current follows the electrical one-line diagram, not the geographic layout of the poles. How you obtain the edges is by reading the system's own documentation: a piping-and-instrumentation diagram (P&ID), an electrical single-line diagram, a SCADA point-to-point map, or a bill of materials that lists which components are bolted to which.

Process graphs are typically directed and often weighted by a physical quantity. Flow has a direction, so an edge from an upstream to a downstream pressure sensor is not the same as its reverse; a weight might be pipe conductance, line admittance, or nominal flow rate. This directedness matters for message passing because it tells the GNN which way evidence should propagate, a distinction a symmetric spatial graph throws away. When the documentation is incomplete, you can recover process structure statistically: a partial-correlation or Granger-style test between sensor streams (the conditional-dependence machinery of Chapter 11) proposes edges where one sensor's variation predicts another's after controlling for the rest. This is exactly the fault-propagation backbone that Section 54.4 exploits to localize a failure to its source.

A district water utility that stopped chasing phantom leaks

A municipal water utility instrumented a district metered area with roughly forty pressure and flow sensors and first modeled it as a spatial \(k\)-NN graph on GPS coordinates. The GNN flagged anomalies whenever two geographically adjacent sensors disagreed, but many alerts were phantoms: the two sensors sat on different pipe loops fed by different mains, so a genuine pressure difference between them was normal, not a leak. The team rebuilt the graph from the utility's hydraulic model, one edge per pipe segment, directed along nominal flow and weighted by pipe conductance. On the process graph, a real leak now showed as a coherent pressure drop propagating downstream from a single junction, exactly where message passing concentrated the anomaly score. False alerts fell sharply and, more importantly, the model now pointed at the offending segment rather than a vague neighborhood. The lesson mirrors the condition-monitoring practice of Chapter 37: encode the plant's real connectivity and anomalies become localizable instead of merely detectable.

Dynamic and learned graphs: when the topology is unknown or moves

Sometimes no clean documentation exists, the true couplings drift over time, or the nodes themselves move. Dynamic graphs answer all three. There are two distinct notions worth separating. The first is a time-varying graph, where the node set or edge set genuinely changes: vehicles in a V2X network join and leave, a wearable body-sensor network re-routes as limbs occlude radio links, a swarm of robots re-forms neighbors as it moves. The adjacency becomes a sequence \(A^{(t)}\), and the GNN must consume a graph per timestep.

The second, more subtle notion is a learned adjacency, where you admit you do not know the true graph and let the model discover it. How this works in practice is a self-adaptive adjacency matrix: assign each node a learnable embedding \(\mathbf{e}_i \in \mathbb{R}^{c}\) and define

$$A^{\text{adp}} = \operatorname{softmax}\!\big(\operatorname{ReLU}(E E^{\top})\big),$$

so the edge weights are trained end to end by gradient descent alongside the forecasting or detection loss. This is the mechanism inside Graph WaveNet (Wu et al., 2019), which you will study in Section 54.3; it lets the model find couplings the spatial graph missed, such as two distant traffic sensors linked by a commuter pattern rather than by road proximity. When to reach for a learned graph is when your prior graph is weak or suspect and you have enough data to fit the extra parameters; when to distrust it is the low-data regime, where a learned adjacency happily memorizes spurious correlations, the same leakage risk this book flags whenever a model is given freedom it cannot pay for out of data.

Where the state of the art sits

The self-adaptive adjacency of Graph WaveNet (Wu et al., 2019) is the workhorse baseline, and MTGNN (Wu et al., 2020) extended it into a full graph-learning layer that builds a sparse, directed adjacency from node embeddings for multivariate series with no prior graph at all. GTS (Shang et al., 2021) learns a single discrete graph structure jointly with a forecaster, while Neural Relational Inference (Kipf et al., 2018) casts structure discovery as a latent-variable problem, inferring interaction edges from observed dynamics. The current tension is between these fully learned graphs and physics-anchored ones: learned adjacencies win on raw benchmark error yet resist interpretation, whereas a process graph is auditable but only as good as its documentation. Hybrid designs that seed a learnable adjacency with the known physical topology, then let gradients add the missing edges, are the pragmatic frontier and connect directly to the physics-informed models of Chapter 55.

Right tool: graph construction in one line

The coordinate-to-adjacency code above is instructive but you rarely hand-roll it in production. PyTorch Geometric ships torch_geometric.nn.radius_graph(pos, r) and knn_graph(pos, k), which take a tensor of node positions and return the edge index for a thresholded-radius or \(k\)-NN spatial graph, batched across many graphs, on GPU. That is roughly 30 lines of distance-matrix, thresholding, and edge-list bookkeeping collapsed to a single call, and the library handles the sparse COO format the message-passing layers expect natively. For process graphs, loading a documented topology through networkx and exporting with from_networkx keeps you in the same ecosystem. Build the matrix by hand once to understand \(\sigma\), \(\kappa\), and directedness; call the library forever after.

Choosing a family, and mixing them

The three families are not exclusive, and the strongest designs combine them. A common recipe fuses a fixed process (or spatial) adjacency with a learned adaptive one, letting the GNN use documented physics as a backbone and gradients to fill gaps: \(A = A^{\text{phys}} + A^{\text{adp}}\). Choose the starting point by asking what carries influence in your system. If it is a free medium, start spatial. If it is an engineered conduit and you have the drawings, start with a process graph, because it hands you directedness and interpretability for free. If the couplings are unknown, time-varying, or the nodes move, you need a dynamic or learned graph, and you should budget the data to justify the extra freedom. Whatever you pick, validate it the way Chapter 48 validates any fusion assumption: check that edges correspond to real dependence and that no node is silently orphaned, because an adjacency error is a modeling error that no amount of training will repair.

Exercise: the same sensors, three graphs

Take the twelve-sensor layout from the code snippet and treat them as pressure sensors on a small water network. (a) Build the thresholded Gaussian spatial graph and record its mean degree. (b) Now suppose the true pipe topology is a directed tree rooted at sensor 0; construct that process adjacency by hand and compare its edge set to the spatial one, noting which spatial edges cross non-connected pipes. (c) Add a learnable adaptive term \(A^{\text{adp}}\) with two-dimensional node embeddings and argue, in two or three sentences, how much training data you would want before trusting the edges it invents. Which of the three graphs would you actually deploy for leak localization, and why?

Self-check

  1. Give one concrete situation where two sensors are close in Euclidean distance yet should have no edge, and explain which graph family fixes it.
  2. Why are process graphs usually directed while spatial graphs are usually symmetric, and what does that directedness give the message-passing step?
  3. A learned adaptive adjacency lowers benchmark error but is hard to interpret. State one risk of using it in a low-data setting and one way a hybrid graph mitigates that risk.

What's Next

In Section 54.3, we stop constructing graphs and start computing on them over time. Spatiotemporal GNNs such as DCRNN, Graph WaveNet, and BigST marry the adjacency structures of this section to temporal models, diffusing information across the graph at each timestep while a sequence model tracks how each node evolves. You will see the self-adaptive adjacency reappear as a trainable layer, and the spatial-versus-process choice you made here will set how far and how fast a signal can travel through the network.