liveBook · Manning

Max pooling

As explained in Graph Neural Networks in Action

max_pool is a PyTorch Geometric pooling function that coarsens a graph by pooling clustered nodes using maximum-valued features.

Use max pooling when a graph is too large to process at its original resolution and clusters of nodes can be represented by fewer nodes. In PyTorch Geometric (PyG), `max_pool()` takes an existing node-to-cluster assignment and produces a coarser graph. It is the pooling step, not the clustering algorithm. section 7.10

The workflow has two steps:

  • Cluster nodes, for example with `graclus(edge_index)`. The resulting tensor maps each original node to a cluster. section 7.10
  • Pass the clusters and graph data to `max_pool(cluster, data)`. Nodes in each cluster are pooled into a node of the coarser graph using maximum-valued features. section 7.10

Coarsen a Karate Club graph

With a PyG `Data` object named `data`, make its edges undirected, then run `cluster = graclus(to_undirected(data.edge_index))` and `data_coarse = max_pool(cluster, data)`. The shown run reduces the graph from 34 nodes and 156 edges to 22 nodes and 98 edges. section 7.10

Clustering and pooling can be repeated to form a hierarchy of progressively smaller graphs, but size reduction can discard important detail. For supervised or semi-supervised tasks, labels for pooled nodes need careful reconciliation with the original labels. A road-network trial lost detail in high-traffic areas and produced unsatisfactory clustered-node labels; applying coarsening only at an intermediate geographic layer offered a way to retain finer-level detail. section 7.10 section 7.10.1

Do not confuse graph-coarsening `max_pool()` with max aggregation elsewhere in a graph model. For example, Jumping Knowledge can select the maximum feature value across layer outputs; that combines representations rather than clustering nodes into a smaller graph. section 7.10 section 3.2.2

How Graph Neural Networks in Action covers it

How deep it goes
Shows the two-step clustering-and-pooling procedure and a PyG call, without detailing pooling internals.
Examples
Uses a Karate Club graph with before-and-after sizes and a road-network trial that loses important detail.
What it assumes
Assumes basic Python and PyTorch graph-data handling while defining clustering and pooling as separate steps.
What you can do after
Apply it via PyTorch Geometric's `graclus()` and `max_pool()` to coarsen a graph and assess information loss.
How it connects
Connects graph coarsening to Graclus clustering, hierarchical graphs, and label preservation.

Also explained in

Compare how 10 books explain max pooling →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Graph Neural Networks in Action. The section links point to the parts of the book it draws on.