Quant Memo
Core

Graphs as Data: Adjacency and Node Features

Before any graph neural network can run, a graph has to be turned into numbers — an adjacency matrix recording who is connected to whom, and a feature matrix recording what each node itself looks like — and everything a GNN does starts from these two objects.

Prerequisites: Graph Theory Basics, Graph Representations

A neural network needs numbers to operate on — matrices it can multiply, add, and take gradients through. A graph, as a mental object, is nodes and connections: a network of counterparties, a supply chain, a correlation structure between assets. To make a graph usable by any neural network, including a graph neural network, it first has to be converted into two plain numeric objects: a matrix describing the connections, and a matrix describing what each node is. Every graph-ML method, no matter how sophisticated, starts from exactly these two ingredients.

The analogy: a seating chart and a set of name tags

Think of a graph as a room full of people at a mixer. The adjacency matrix is the seating chart's connection list — a record of who is standing next to whom, with nothing at all about who any individual person actually is. The node feature matrix is the set of name tags, one per person, listing whatever attributes matter — job title, years of experience, department — with nothing about the room's layout. Neither object alone describes the mixer fully: you need the seating chart to know who can talk to whom, and the name tags to know anything about the individuals doing the talking. A graph neural network's entire job is to combine both.

The two matrices, defined

For a graph with nn nodes, the adjacency matrix AA is n×nn \times n, with Aij=1A_{ij} = 1 if nodes ii and jj are connected (an edge exists) and 00 otherwise — for a weighted graph, AijA_{ij} can instead hold the edge's weight, e.g. exposure size between two counterparties. The node feature matrix XX is n×dn \times d, one row per node, each row a dd-dimensional vector of that node's own attributes — for a company in a supply-chain graph, perhaps revenue, sector code, and credit rating.

A{0,1}n×n,XRn×dA \in \{0,1\}^{n \times n}, \qquad X \in \mathbb{R}^{n \times d}

In words: AA answers "who is connected to whom," entirely structural, no node attributes involved; XX answers "what does each node look like," entirely attribute-based, no connection information involved. A graph neural network's first layer typically combines them by having each node gather its neighbors' rows of XX, using AA to know which rows count as neighbors.

Worked example 1: building both matrices for a tiny counterparty network

Four firms, {A,B,C,D}\{A, B, C, D\}, with trading relationships A-BA\text{-}B, B-CB\text{-}C, C-DC\text{-}D, and A-CA\text{-}C. The adjacency matrix (rows/columns in that order):

Aadj=(0110101011010010)A_{\text{adj}} = \begin{pmatrix} 0&1&1&0 \\ 1&0&1&0 \\ 1&1&0&1 \\ 0&0&1&0 \end{pmatrix}

Row for firm CC reads (1,1,0,1)(1,1,0,1) — connected to AA, BB, and DD, matching the three edges touching CC above. Now suppose each firm has a 2-feature vector (leverage ratio, sector code): X=[(2.1,1),(1.4,2),(3.0,1),(0.9,3)]X = \big[(2.1, 1), (1.4, 2), (3.0, 1), (0.9, 3)\big]. Firm CC's row, (3.0,1)(3.0, 1), is its leverage and sector — completely independent information from the adjacency row just computed; you need both to know that "CC is a highly levered, sector-1 firm connected to three others."

Worked example 2: one step of neighbor aggregation using both matrices

A common first GNN operation averages each node's own features with its neighbors' features. For firm BB, neighbors are AA and CC (from row B=(1,0,1,0)B = (1,0,1,0)), with features (2.1,1)(2.1,1) and (3.0,1)(3.0,1); BB's own feature is (1.4,2)(1.4,2). Averaging all three: (2.1+3.0+1.43,1+1+23)=(2.17,1.33)\big(\frac{2.1+3.0+1.4}{3}, \frac{1+1+2}{3}\big) = (2.17, 1.33). Firm DD, by contrast, has only one neighbor, CC, with feature (3.0,1)(3.0,1); averaging DD's own (0.9,3)(0.9,3) with just that one neighbor: (1.95,2.0)(1.95, 2.0). Notice how much DD's updated feature shifts toward CC's values simply because DD has only one connection — a direct, numeric illustration of why a node's position in AA (how many and which neighbors it has) directly shapes what a GNN computes for it, on top of whatever XX says about the node itself.

Matrix explorer
dashed = before · solid = after
det 1.25trace 2.50λ 1.81, 0.69area scales by 1.25×

Think of the adjacency matrix the same way you'd think of the transformation matrix above: it's a fixed matrix that reshapes what a vector of node features becomes after one round of neighbor mixing, exactly as a 2×2 matrix reshapes a vector on the plane.

A B C D A: adjacency (who connects) X: features (what each node is)
The same four firms produce two independent objects: the adjacency structure on the left, and a features table on the right — a GNN layer is the operation that mixes information across the first using the second.

Every graph, before any model touches it, is reduced to two matrices: an adjacency matrix AA recording connections with no information about the nodes themselves, and a feature matrix XX recording node attributes with no information about connections — a graph neural network's job is combining the two, typically by having each node aggregate its neighbors' feature rows as identified by AA.

What this means in practice

This split matters for what a graph-ML pipeline has to assemble: a correlation-based asset graph needs a thresholding rule to turn continuous correlations into an AA, plus a choice of directed (payment flow) versus undirected (mutual exposure); a firm's feature vector in XX is chosen and normalized entirely separately from that structure.

A richer XX cannot substitute for missing structure in AA, or vice versa. A firm's own financials say nothing about contagion risk from its counterparties, and the counterparty structure alone says nothing about how exposed the firm itself is; a GNN's value comes from needing both together, and a pipeline that builds only one well loses exactly the information a graph model was meant to add.

Related concepts

Practice in interviews

Further reading

  • Hamilton, Graph Representation Learning (2020), Ch. 1-2
ShareTwitterLinkedIn