liveBook · Manning

Edge index

As explained in Build AI Drug Discovery Pipelines

edge_index is a two-row sparse tensor that records source and destination node indices for graph edges.

An edge_index is a two-row sparse tensor that records graph connectivity: the first row stores each edge's source node and the second stores its destination node. In PyTorch Geometric, its shape is [2, num_edges]. section 11.4 section 11.5.5

This representation supports graph neural network processing by:

  • Storing only existing connections instead of a mostly empty dense adjacency matrix. section 11.5.5
  • Allowing message-passing layers to find each node's neighbors and aggregate their features. section 11.4
  • Representing directed entries explicitly; an undirected bond can therefore appear in both directions. section 11.5.5

Molecule graph in PyTorch Geometric

A molecule with 20 atoms and 25 bonds can use 20 node-feature rows. With bidirectional bonds and self-loops, edge_index may have shape 2×75: 50 directed bond entries plus 20 self-loop entries. section 11.5.5

from torch_geometric.data import Data
GCNData_mol = Data(
    x=torch.Tensor(features),
    edge_index=torch.LongTensor(edge_index).transpose(1, 0),
    y=torch.FloatTensor([affinity_value])
)

Constructs a PyTorch Geometric Data object with node features, a transposed edge_index tensor, and a graph-level affinity target. section 11.5.5

How Build AI Drug Discovery Pipelines covers it

How deep it goes
Explains row semantics, COO sparsity, dimensions, bidirectional edges, self-loops, and Data-object construction.
Examples
Uses a 20-atom molecule with 25 bidirectional bonds and self-loops, plus a PyTorch Geometric Data construction listing.
What you can do after
Operate/configure PyTorch Geometric Data objects by building edge_index tensors from graph connectivity.
How it connects
Connects edge_index to graph neural networks, message passing, node features, edge features, adjacency matrices, and PyTorch Geometric Data objects.

Also explained in

Compare how 2 books explain edge index →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build AI Drug Discovery Pipelines. The section links point to the parts of the book it draws on.