458. Graph Neural Network



Node Embedding:
𝑥1𝑥2𝑥𝑛
Edge Embedding:
𝑥1𝑥2𝑥𝑛
Adjacency Matrix:[0110010110110000100100010]




Graph Data

458.0.1. Message Passing

Allows nodes in a graph to exchange information and update their representations (embeddings) based on their local neighborhood

𝐺=(𝑉,𝐸)

Where:

Step 1: Message computation

Each node 𝑣 receives messages from its neighbors 𝑢𝒩︀(𝑣). A message function 𝑀 defines how information is sent:

𝐦𝑣𝑘=𝑢𝒩︀(𝑣)𝑀(𝐡𝑣𝑘1,𝐡𝑢𝑘1,𝑒𝑢𝑣)

Step 2: Aggregation

Aggregation combines incoming messages. This is often already done by the summation, mean, or max:

𝐦𝑣𝑘=AGGREGATE({𝐡𝑢𝑘1:𝑢𝒩︀(𝑣)})

Step 3: Update

Each node updates its state with an update function 𝑈:

𝐡𝑣𝑘=𝑈(𝐡𝑣𝑘1,𝐦𝑣𝑘)

Common choce:

𝐡𝑣𝑘=𝜎(𝑊[𝐡𝑣𝑘1𝐦𝑣𝑘])

Where:

Example

458.0.2. Invariance

A function is invariant to node permutations if its output stays the same no matter how the nodes are reordered (i.e., relabeled)

𝑓(𝑃𝑋,𝑃𝐴𝑃𝑇)=𝑓(𝑋,𝐴)

If you shuffle the node labels, the graph is still the same — just redrawn

If you reorder the rows of 𝑋 (node features) and both rows and columns of 𝐴 (adjacency matrix) using the same permutation matrix 𝑃, the output does not change

458.0.3. Equivariance

A function is equivariant to node permutations if permuting the input nodes results in the output being permuted in the same way

𝑓(𝑃𝑋,𝑃𝐴𝑃𝑇)=𝑃𝑓(𝑋,𝐴)

If you shuffle the nodes in the input graph, the output values (e.g., node embeddings or predictions) shuffle in the same way

If you reorder the rows of 𝑋 (node features) and both rows and columns of 𝐴 (adjacency matrix) using the same permutation matrix 𝑃, the output is reordered in the same way — i.e., its rows are permuted by 𝑃 too

Example

Let 𝐺=(𝑉,𝐸) be a directed graph where

𝑉={0,1}𝐸={(0,1)}

Adjacency matrix:

𝐴=[0100]

Node feature matrix:

𝑋=[1234]

Permutation matrix (swaps node 0 and node 1):

𝑃=[0110]

Equivariance

Let’s define a very simple equivariant function:

𝑓(𝑋,𝐴)=𝐴𝑋

Message passing: sum over neighbors’ features

Step 1: Compute output without permutation

𝑓(𝑋,𝐴)=𝐴𝑋=[0100][1234]=[3400]

Step 2: Compute permuted inputs

  • Permute 𝑋
𝑃𝑋=[0110][1234]=[3412]
  • Permute 𝐴
𝑃𝐴𝑃𝑇=[0110][0100][0110]=[0010]

This is now node 1 pointing to node 0

Step 3: Apply function to permuted inputs

𝑓(𝑃𝑋,𝑃𝐴𝑃𝑇)=(𝑃𝐴𝑃𝑇)(𝑃𝑋)=[0010][3412]=[0034]

Step 4: Compare with 𝑃𝑓(𝑋,𝐴)

𝑓(𝑋,𝐴)=[3400]𝑃𝑓(𝑋,𝐴)=[0034]

So this function is equivariant:

𝑓(𝑃𝑋,𝑃𝐴𝑃𝑇)=𝑃𝑓(𝑋,𝐴)

Invariance

Let’s define a simple invariant function:

𝑔(𝑋,𝐴)=𝟏𝑇𝐴𝑋

Step 1: Compute 𝑔(𝑋,𝐴)

𝐴𝑋=[0100][1234]=[3400]

Sum over rows:

𝟏𝑇𝐴𝑋=[3+04+0]=[34]

Step 2: Compute permuted inputs

  • Permute 𝑋
𝑃𝑋=[0110][1234]=[3412]
  • Permute 𝐴
𝑃𝐴𝑃𝑇=[0110][0100][0110]=[0010]

Step 3: Compute new output

𝑃𝐴𝑃𝑇𝑃𝑋=[0010][3412]=[0034]

Step 4: Apply function to permuted inputs

𝟏𝑇(𝑃𝐴𝑃𝑇)(𝑃𝑋)=[11][0034]=[34]

Result:

𝑔(𝑋,𝐴)=[34]=𝑔(𝑃𝑋,𝑃𝐴𝑃𝑇)

So the function is invariant under node permutation:

𝑓(𝑃𝑋,𝑃𝐴𝑃𝑇)=𝑓(𝑋,𝐴)