Chapter 3
Vector quantization and topology learning
Large data sets are expensive to turn into graphs, and noisy samples create spurious edges. Vector quantization replaces the samples by a few hundred representatives; topology learning additionally links the representatives so that the graph follows the shape of the data. This chapter starts with k-means and the Linde–Buzo–Gray algorithm, introduces neural gas and the topology representing network, and then presents the growing networks—growing neural gas, grow when required, the dynamic topology representing network, and the weighted incremental network—that do not need the number of representatives in advance. The graphs learned here are the input of TRNMap and the other topology-based maps of chapter 8.
3.1 Problem and idea
A vector quantizer maps every sample to the nearest of codebook vectors and thereby partitions the data space into Voronoi cells. Quantization reduces the number of objects from to , averages out noise within each cell, and makes the subsequent graph algorithms cheap: a geodesic distance matrix of nodes is computed in milliseconds even if the data contain millions of samples. For clustering and mapping, however, the codebook alone is not enough; we also need to know which codebook vectors are neighbors along the data. Two nodes on opposite sides of a gap may be close in space, yet no data connect them.
Martinetz [42] answered this question with competitive Hebbian learning: for every sample, link its nearest and its second nearest node. The two nodes are then adjacent in the Voronoi diagram, and the point halfway between them lies in a region where data exist. The edges collected in this way form the induced Delaunay triangulation: the Delaunay triangulation of the nodes, masked by the data distribution (fig. 3.1). It is a much better graph than a kNN graph of the nodes, because it neither depends on a neighbor count nor bridges gaps.
3.2 Theory
3.2.1 k-means and the Linde–Buzo–Gray algorithm
k-means [43, 44] minimizes the distortion by alternating two steps: assign every sample to its nearest codebook vector, and move every codebook vector to the mean of its samples. The algorithm converges to a local minimum that depends on the initial codebook, and codebook vectors that start in empty regions may never receive any sample. The Linde–Buzo–Gray (LBG) algorithm [45] reduces this sensitivity by growing the codebook: it starts with the centroid of all data, splits every codebook vector into two slightly perturbed copies, refines the doubled codebook with k-means iterations, and repeats until vectors exist. k-means and LBG learn no graph; the package links their codebooks afterwards by competitive Hebbian learning on the data.
3.2.2 Neural gas
Neural gas [46, 47] replaces the hard assignment of k-means by a soft, rank-based one. In every step a sample is drawn at random, the nodes are sorted by their distance to it, and node with rank moves towards the sample by
|
| (3.1) |
The step size and the neighborhood range decrease exponentially, . While is large, all nodes move together and the codebook first contracts to the center of the data; as shrinks, the update becomes more and more winner-take-all and the nodes spread over the data like a gas filling a container. Neural gas performs a stochastic gradient descent on a cost function that interpolates between a smooth, almost convex function and the k-means distortion, which explains why it is far less sensitive to the initial codebook than k-means.
3.2.3 Topology representing networks
A topology representing network (TRN) [42] runs neural gas and builds the graph by competitive Hebbian learning at the same time (algorithm 3.1). Because the nodes move during learning, early links may become invalid; every link therefore has an age that is reset whenever the link is confirmed and increased whenever its end node wins without confirming it. Links older than the lifetime are removed. Martinetz and Schulten proved that, for a sufficiently dense codebook, the resulting graph is the induced Delaunay triangulation, and it preserves the topology of the data manifold in the sense that neighboring nodes on the graph are neighbors on the manifold and vice versa.
The parameters follow eq. (3.1) plus the lifetime. With , from to , from to , and a lifetime growing from to the network is robust for most data; the number of nodes is by far the most influential choice.
3.2.4 Growing networks
A fixed is a nuisance when the size of the structure is unknown. Growing networks start with one or two nodes and add nodes where the current representation is poor.
Growing neural gas (GNG). Fritzke’s algorithm [48] adapts only the winner (step ) and its graph neighbors (step ), links and as in the TRN, accumulates the squared distance of each sample in an error variable of its winner, and every steps inserts a new node halfway between the node with the largest error and its neighbor with the largest error. The link – is replaced by links to the new node, and errors decay by a factor at insertion and by in every step. All parameters are constant in time, so GNG can run indefinitely on a data stream.
Grow when required (GWR). Marsland, Shapiro, and Nehmzow [49] insert a node as soon as it is needed rather than at fixed intervals. If the activity of the winner is below a threshold and the winner has already been trained enough—its habituation counter, which decays with every win, is low—a new node is placed between the winner and the sample. Otherwise the winner and its neighbors move with steps proportional to their habituation. GWR reacts quickly to new regions of the input space and is popular in robotics and continual learning.
Dynamic topology representing network (DTRN). Si, Lin, and Vuong [50] combine competitive Hebbian learning with a vigilance test. If the winner is farther than the vigilance threshold from the sample, the sample becomes a new node linked to the winner; otherwise the winner and its neighbors move towards the sample with Gaussian-normalized steps
|
| (3.2) |
where are the graph neighbors of the winner, and the winner is linked to the second nearest node. Old links are removed together with the nodes they leave isolated. The final number of nodes is controlled by the vigilance schedule instead of a fixed count.
Weighted incremental neural network (WINN). Muhammed [51] extends GNG with weights that estimate density: every sample increments the weight of its nearest nodes and of the edges between the winner and the other of them, and inserted nodes inherit averaged weights. Node and edge weights are later used for fuzzy clustering of the network. The paper recommends a maximal edge age of ; on curved manifolds this keeps many transient links, and ages of a few steps give clean graphs (fig. 3.5).
In a nutshell: Topology learners
- Neural gas places nodes robustly by rank-based soft competition; the TRN adds competitive Hebbian links and yields the induced Delaunay triangulation.
- GNG and WINN grow by error-driven insertion at fixed intervals, GWR when a sample is poorly represented, DTRN by a vigilance test; none needs in advance, but each has a threshold that controls the final size.
- Edge ages remove links created while the nodes were still moving; long lifetimes keep spurious links across gaps.
- All produce a graph with Euclidean edge lengths that serves for geodesic distances, clustering, and mapping.
3.3 Using it in graphclust
graphclust.vq
NeuralGas(n_nodes, max_iter, eps=(0.3, 0.05), lam=None, init="range"), TopologyRepresentingNetwork(n_nodes, ..., lifetime=None, prune=True), GrowingNeuralGas(max_nodes, eps_b, eps_n, max_age, lambda_, alpha, d), GrowWhenRequired(activity_threshold, habituation_threshold, ...), DynamicTopologyRepresentingNetwork(max_iter, alpha, rho, max_age), WeightedIncrementalNetwork(n_nodes, n_winners, max_age, ...), LBG(n_nodes). All set nodes_, adjacency_ (Euclidean edge lengths), labels_, n_nodes_, n_edges_, and offer predict, transform, quantization_error, and graph_distances.
A topology representing network is fitted like any scikit-learn estimator:
trn = TopologyRepresentingNetwork(n_nodes=n, random_state=0).fit(X)
3.4 Examples
3.4.1 Neural gas on shapes of different dimension
The Boxlinecircle data of the authors combine a noisy cube, a bent line, and a circle (7100 samples). Figure 3.2 shows 300 neural gas nodes after increasing numbers of adaptation steps. After a hundred steps the nodes have contracted towards the middle of the data; after ten thousand steps they cover all three shapes, with a density that follows the data density. The quantization error falls from 1.93 to 0.57.
3.4.2 Topology representing networks of curved manifolds
Figure 3.3 shows TRNs of the S curve with 100 and 200 nodes and of the swiss roll with 200 nodes. The graphs follow the sheets: links connect nodes along the surface but not across the folds or between the windings. More nodes resolve the surface more finely.
3.4.3 Growing networks
Figure 3.4 compares the four growing networks on the swiss roll scaled to the unit cube. GNG and WINN, which grow at fixed intervals up to a node budget, produce regular networks of about 200 nodes. GWR inserts nodes wherever a sample is poorly represented and stops when the activity threshold is met everywhere. DTRN creates many nodes early, while the vigilance threshold is still large relative to the node spacing, and prunes isolated ones later; its size depends on the vigilance schedule and the number of iterations.
Open in ColabExample plot_03_growing_networks.py in the gallery
3.4.4 Edge lifetime
The maximal edge age decides which transient links survive. Figure 3.5 trains WINN on the swiss roll with the age limit recommended in the original paper () and with an age limit of three. The long lifetime keeps hundreds of links that jump between windings; the short one keeps only links along the sheet.
Open in ColabExample plot_04_edge_lifetime.py in the gallery
3.5 Further reading
The neural gas algorithm and its cost function are analyzed by Martinetz, Berkovich, and Schulten [47]; the topology preserving property of competitive Hebbian learning by Martinetz and Schulten [42]. Kohonen’s book [52] relates these methods to the self-organizing map of chapter 7. The growing networks are described in the original papers of Fritzke [48], Marsland et al. [49], Si et al. [50], and Muhammed [51].