Graph-Based Clustering and Data Visualization in PythonThe graphclust toolbox

Chapter 8
Topology-preserving maps

Replacing Euclidean input distances by graph distances lets a map unfold curved manifolds. This chapter presents the methods that do so: Isomap, which applies classical scaling to geodesic distances; Isotop, a self-organizing map whose neighborhood is measured along a graph; curvilinear component and distance analysis; the online methods OVI-NG and GNLP-NG, which learn a neural gas codebook and its map simultaneously; and the topology representing network map (TRNMap), which maps the graph of a topology representing network by metric or non-metric MDS. Component planes show how the maps carry the original variables.

8.1 Problem and idea

The methods of chapter 7 preserve Euclidean distances or neighborhoods. When the data lie on a curved low-dimensional manifold—a rolled sheet, a bent curve—the Euclidean distance between far-apart samples measures the shortcut through the ambient space, and preserving it forces the map to fold the manifold. Geodesic distances measured along a neighborhood graph (chapter 2) do not have this problem: for a manifold that is isometric to a subset of the plane, the geodesic distances are planar distances, and a distance-preserving map of them unrolls the manifold (fig. 8.1).

The methods of this chapter differ in three choices: which graph (kNN graph of the samples, competitive Hebbian graph of a codebook, topology representing network), which mapping (eigendecomposition, stress minimization, online adaptation), and whether the map is computed for all samples or for a codebook of representatives.

Figure 8.1

Figure 8.1. Geodesic distances unfold manifolds. A map that preserves distances measured along the graph unrolls the curve; a map of Euclidean distances must keep the ends close.

8.2 Theory

8.2.1 Isomap

Isomap [6] builds a kNN or 𝜀-graph of the samples, computes all geodesic distances δij (algorithm 2.1), and embeds them by classical scaling eq. (7.1). It is fast, has no local minima, and is exact for manifolds isometric to convex planar regions with dense sampling. Its weaknesses are the cubic cost of the eigendecomposition for large N, sensitivity to short circuits, and disconnected graphs for data with several clusters; the package joins components by their shortest connecting edges so that multi-cluster data can still be mapped.

8.2.2 Isotop

Isotop [81] keeps the self-organizing principle of the SOM but replaces the fixed lattice by a graph of the data. It quantizes the data (optionally), links the nodes by a kNN graph, computes geodesic distances δij with mean edge length μδ, and then adapts the map positions yi by repeating: draw a point g from a Gaussian kernel centered on a randomly chosen map node, find the node c whose map position is closest to g, and move all nodes,

yi ←yi + α(t)exp ⁡ { − 1 2 ( δci λ(t)μδ )2 }(g −y i).
(8.1)

Nodes close to c along the graph follow g, distant ones hardly move, so the map spreads out while the graph neighborhoods stay together. Isotop needs no eigendecomposition and handles non-convex manifolds, but, like all stochastic self-organizing methods, it can be caught in local minima, and its schedules require some care.

8.2.3 Curvilinear component and distance analysis

Curvilinear component analysis (CCA) of Demartines and Hérault [82] minimizes a stress that weighs each distance error by a decreasing function of the map distance,

ECCA = 1 2∑ i≠j(dij∗−d^ ij)2F(d^ ij,λ),
(8.2)

for example the step function F(d^,λ) = 1 if d^ < λ and 0 otherwise. Short map distances are enforced, long ones may stretch, so the map can tear a manifold apart where necessary. CCA minimizes eq. (8.2) by a fast stochastic rule: choose a sample i and move every other point by α(t)F(d^ij,λ(t))dij∗−d^ij d^ij (yj −yi), with λ shrinking over time. With geodesic input distances dij∗ = δij the method becomes curvilinear distance analysis (CDA) [83], which combines the unfolding power of geodesic distances with the tearing ability of CCA.

8.2.4 OVI-NG and GNLP-NG

Estévez and Figueroa [84] attached a map to the neural gas codebook. In OVI-NG every adaptation step of a topology representing network is followed by an update of the map positions zj of the nodes towards consistency with the codebook distances around the winner s:

zj ←zj + α(t)e−rj∕σ(t)d^js −djs d^js (zs −zj),
(8.3)

where d^js is the map distance, djs the codebook distance, and rj the rank of node j by map distance from s. Only ranks enter the neighborhood factor, so the method behaves like a neighborhood-preserving, online version of Sammon’s mapping. Because djs is Euclidean, OVI-NG does not unfold curved manifolds.

GNLP-NG [85] uses geodesic distances instead. It first trains the codebook with neural gas and links nodes by competitive Hebbian learning, connects the graph, and computes geodesic distances δjs; then it adapts the map positions by eq. (8.3) with djs replaced by δjs and the neighborhood factor exp ⁡ {−(rj∕σ(t))2} computed from the rank of node j by geodesic distance from s.

8.2.5 The topology representing network map

TRNMap [4, 5] combines the topology representing network of chapter 3 with multidimensional scaling (algorithm 8.1). Compared with the methods above, it has three properties. Its graph is learned by competitive Hebbian learning and does not depend on a neighborhood size or on the data density. Its mapping is a one-shot MDS of the geodesic distances, without online iterations whose schedules must be tuned. And it lets the user decide what to preserve: metric MDS keeps the geodesic distances (distance-preserving TRNMap, DP-TRNMap), non-metric MDS only their order (neighborhood-preserving TRNMap, NP-TRNMap). The nodes are prototypes with codebook vectors in the original space; drawing the map once per variable with nodes shaded by that variable gives component planes, which show the distribution of each variable over the map and reveal correlated variables by similar shadings.

Algorithm

The number of nodes is the decisive parameter. Too few nodes are spaced farther apart than the gaps of the manifold, and their links bridge the gaps; too many nodes receive too few samples each and may settle in empty space. A few hundred nodes, or about a fifth of the samples for small data sets, work well in practice. The other TRN parameters can stay at their defaults.

In a nutshell: Topology-based maps

  • Geodesic input distances let distance-preserving maps unfold manifolds; Euclidean ones (CCA, OVI-NG) keep them folded.
  • Isomap: kNN graph and classical scaling, global and exact but sensitive to k.
  • Isotop, CCA/CDA, OVI-NG, GNLP-NG: stochastic self-organization with decaying schedules; CDA can tear, Isotop can stall in local minima.
  • TRNMap: competitive Hebbian graph and one-shot metric or non-metric MDS; nodes double as prototypes and give component planes.

8.3 Using it in graphclust

graphclust.manifold

Isomap(n_components, k=10, eps=None, graph=None); Isotop(n_components, n_nodes=None, k=6, n_iter, alpha, lam); CurvilinearComponentAnalysis(n_components, geodesic=False, k, n_nodes=None, n_epochs, alpha, lam); OnlineVisualizationNG(n_nodes, ...); GeodesicNLPNG(n_nodes, ...); TRNMap(n_nodes, mapping="metric", "nonmetric" or "classical", fine_tune=False, normalize=True, lifetime, prune=True). The node-based maps store nodes_, adjacency_, dist_matrix_, and embedding_ (one row per node); transform(X) places samples at their nearest node. plotting.plot_component_planes(positions, nodes, adjacency).

ovi = OnlineVisualizationNG(n_nodes=n, random_state=0).fit(X) 
gnlp = GeodesicNLPNG(n_nodes=n, random_state=0).fit(X) 
dp = TRNMap(n_nodes=n, mapping="metric", random_state=0).fit(X) 
np_ = TRNMap(n_nodes=n, mapping="nonmetric", random_state=0).fit(X)
   

8.4 Examples

8.4.1 Isomap, Isotop, CCA, and CDA on the swiss roll

Figure 8.2 maps the swiss roll with the four methods (Isotop, CCA, and CDA on 250 neural gas nodes). Isomap unrolls the sheet into a rectangle colored smoothly by the position along the roll. CDA unrolls it as well, with mild distortions at the ends. CCA with Euclidean distances cannot unroll the sheet and tears it into pieces that are internally consistent but arranged arbitrarily. Isotop unfolds most of the roll but leaves a fold, an example of the local minima of stochastic self-organization.

Figure 8.2

Figure 8.2. Isomap, Isotop, CCA, and CDA on the swiss roll, colored by the position along the roll. The methods with geodesic distances unroll the sheet; CCA with Euclidean distances tears it.

Open in ColabExample plot_01_isomap_isotop_cda.py in the gallery

8.4.2 OVI-NG, GNLP-NG, and TRNMap on the S curve

All four methods of fig. 8.3 map 120 nodes of the S curve and draw the learned graph. OVI-NG, whose map follows Euclidean codebook distances, reproduces the S shape: the sheet is bent in the plane rather than unrolled. GNLP-NG unrolls it into a slightly distorted strip. DP-TRNMap and NP-TRNMap unroll it into a regular rectangle in which the color, the position along the S, varies monotonically from one end to the other; the non-metric version differs from the metric one only in small local adjustments, because the geodesic distances are nearly Euclidean in the plane.

Figure 8.3

Figure 8.3. OVI-NG, GNLP-NG, and the two TRNMap variants on the S curve. Nodes are colored by the position along the S of the samples they represent; the lines are the learned links.

Open in ColabExample plot_02_ovi_gnlp_trnmap.py in the gallery

8.4.3 Component planes

The component planes of a TRNMap of the S curve (fig. 8.4) show the three coordinates over the unrolled map. The height of the sheet varies across the strip, the two other coordinates along it; the S shape appears as the two coordinates oscillating against each other along the map.

Figure 8.4

Figure 8.4. Component planes of a TRNMap of the S curve: the map is drawn once per coordinate, nodes shaded by the value of that coordinate.

Open in ColabExample plot_03_component_planes.py in the gallery

8.4.4 The number of nodes

Figure 8.5 maps the swiss roll with 50, 150, and 400 nodes and evaluates the node maps against the geodesic distances. With fifty nodes the node spacing exceeds the gap between the windings, competitive Hebbian learning links neighboring windings, and the map folds the roll into a ring; trustworthiness and continuity stay around 0.93. With 150 and 400 nodes the links stay on the sheet, the roll is unrolled, and both measures exceed 0.99 at all neighborhood sizes. Beyond that, more nodes refine the map without changing its shape.

Figure 8.5

Figure 8.5. The number of nodes of TRNMap. DP-TRNMaps of the swiss roll with 50, 150, and 400 nodes, and the trustworthiness and continuity of the node maps.

Open in ColabExample plot_04_number_of_nodes.py in the gallery

8.5 Further reading

Lee, Lendasse, and Verleysen [83] compare Isomap and CDA in depth; Lee and Verleysen’s book [29] covers Isotop and CCA. The online methods are described by Estévez and co-authors [84, 85]. TRNMap is introduced in [4]; its relations to other combinations of topology representing networks and mappings are analyzed in [5, 86, 87].