liveBook · Manning

Adjacency matrix

As explained in Financial AI in Practice

A matrix whose entries represent whether or how pairs of graph vertices are connected.

An adjacency matrix represents connections between graph nodes. In transaction fraud detection, it links transactions that share a user ID or device ID; the matrix is built as sparse data, row-normalized, and converted to dense form when the graph is small. section 9.4.2

A graph neural network multiplies transformed node features by the matrix to aggregate neighbor information, then combines that information with each node’s own features. section 9.4.2

Listing 9.7 Defining the GNN model
import torch
import torch.nn as nn
import torch.nn.functional as F
import numpy as np
import pandas as pd
from sklearn.preprocessing import StandardScaler
from scipy.sparse import csr_matrix

# Simple GNN Model
class FraudGNN(nn.Module):
    def __init__(self, input_dim, hidden_dim=32):
        super(FraudGNN, self).__init__()
        self.conv1 = nn.Linear(input_dim, hidden_dim)
        self.conv2 = nn.Linear(hidden_dim, hidden_dim)
        self.classifier = nn.Linear(hidden_dim, 2)  # Normal/Fraud

    def forward(self, x, adj):
        # First GNN layer: Aggregate neighbor information
        h1 = torch.relu(self.conv1(x))
        h1_agg = torch.mm(adj, h1)  # Average neighbors' information
        h1 = h1 + h1_agg

        # Second GNN layer
        h2 = torch.relu(self.conv2(h1))
        h2_agg = torch.mm(adj, h2)
        h2 = h2 + h2_agg

        # Classification
        out = self.classifier(h2)
        return out

See the PyTorch model’s adjacency-matrix multiplication and feature aggregation. section 9.4.2

How Financial AI in Practice covers it

How deep it goes
Explains graph construction, sparse storage, row normalization, and neighbor aggregation without detailing matrix theory.
Examples
Links transaction nodes that share a user ID or device ID.
What you can do after
Apply it via PyTorch as input for aggregating neighboring transaction features.
How it connects
Connects graph neural networks, message passing, and node features.

Also explained in

Compare how 8 books explain adjacency matrix →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Financial AI in Practice. The section links point to the parts of the book it draws on.