โš ๏ธ This is an AI-generated test article for theme demonstration/testing only. All content is synthetic.

Message passing

Graph neural networks learn by passing messages between connected nodes. A single layer aggregates neighbour features.

1
2
3
4
5
6
7
8
9
10
11
12
import torch
import torch.nn as nn

class GCNLayer(nn.Module):
def __init__(self, in_dim, out_dim):
super().__init__()
self.linear = nn.Linear(in_dim, out_dim)

def forward(self, x, adj):
# x: [N, in_dim], adj: [N, N] (normalised)
h = torch.mm(adj, x)
return self.linear(torch.relu(h))

Why adjacency matters

Normalising the adjacency matrix prevents feature magnitudes from exploding as graphs get denser.

Batch considerations

Graphs have variable sizes; batching typically requires padding or mini-batch sampling.

Memory and scale

For very large graphs, neighbourhood sampling keeps training tractable.