Unsupervised learning
Similarity Graphs, Density, and Connectivity
Construct neighborhood graphs, reason about density and connectivity, and understand how graph choices shape later clustering and embeddings.
By the end you can
- Build k-nearest-neighbor, radius, and weighted affinity graphs from observations
- Distinguish local density, connectivity, and global distance
- Explain how graph sparsification and kernel scale alter structure
- Audit a similarity graph before using spectral or manifold methods
Analogy
Designing a transit map from travel times
Planners turn travel-time estimates into a transit map. Connecting every nearby stop creates local routes. A single express link can merge regions that otherwise feel separate.
Transit routes are physical. Data edges are modeling choices built from measurements. A shortcut in the graph can be an artifact of measurement rather than a real connection in the domain.
Inspect the bridges before trusting the neighborhoods they create.
As dimension rises, the popular node becomes the bridge
A node's k-occurrence count is the number of other points whose neighbour list it appears in. That is its degree in the k-NN graph. In enough dimensions, that count starts predicting something else: whether the node sits on the shortest paths between regions.
This was measured, not asserted. In 2010, working over 50 real data sets and over i.i.d. uniform data, Radovanović and colleagues tracked each node's k-occurrence count against its betweenness centrality in the graph. In i.i.d. uniform data the Spearman correlation between the two rises from 0.311 at d = 3, to 0.539 at d = 20, to 0.647 at d = 100. Over the same uniform data the sample skewness of N10 under Euclidean distance runs 0.121, 1.541 and 5.445 at d = 3, 20 and 100. The neighbour-count distribution grows a long right tail. The points in that tail move onto the shortest paths.
Across the 50 real data sets, the correlation between that betweenness measure and the skewness of N10 is 0.548. Their reading of it, in the Journal of Machine Learning Research: “This indicates that real data sets which exhibit strong skewness in the distribution of N10 also tend to have strong correlation between N10 and betweenness centrality of nodes, giving hubs a broader significance for the structure of the k-NN graphs.”
The phenomenon has been re-measured since. Feldbauer and Flexer, at OFAI in Vienna, ran it over 50 public machine learning data sets in 2019: “Hubness is typically measured as the skewness of the k-occurrence distribution”.
So a high-degree node is not merely popular. In enough dimensions it is structurally central, and the traffic between regions runs through it. Building the graph converts a metric into edges. That conversion can reveal local organization. It can also introduce shortcuts, disconnected islands, and density artifacts.
The graph is a second model layered on top of the metric.
Visual
From observations to a weighted neighborhood graph
Each stage changes which local relationships become available to downstream methods. The first two stages already carry an approximation that is easy to forget.
At scale, the k-nearest-neighbour graph a pipeline builds is not the exact one. NN-Descent is how it usually gets built, and the 2011 paper from Princeton that introduced it says in its abstract what that costs: “We have shown with a variety of datasets and similarity measures that the proposed method typically converges to above 90% recall with each point comparing only to several percent of the whole dataset on average.” The same paper puts the empirical cost at “the empirical cost is around O(n1.14) for all datasets we experimented with”.
Above 90% recall is not 100%. And this is not a niche option. UMAP's own paper says the search for the k nearest neighbours “can be performed via any nearest neighbour or approximate nearest neighbour search algorithm”, and that the UMAP implementation prefers nearest neighbor descent. So the edges handed to the embedding are approximately, not exactly, each point's k nearest neighbours. That is settled before any of the weighting and inspection choices in the later stages are made.
1. Compute candidate relations
Use a distance, similarity, or domain rule to compare observations.
2. Select edges
Keep k nearest neighbors, all points within a radius, or a mutual-neighbor subset.
3. Weight connections
Apply binary links, inverse distance, kernels, or learned affinities.
4. Inspect topology
Measure components, degree distribution, bridges, hubs, and isolated points.
5. Feed the graph forward
Use the graph for spectral clustering, manifold learning, community detection, or diagnostics.
Edge selection and weighting determine the topology that algorithms will see.
Comparison
Three common neighborhood constructions
The right graph balances local coverage, density variation, and computational cost. The radius family is the one whose threshold has a documented history, and that history is instructive about how such thresholds get set.
DBSCAN's density parameter was set by fiat in 1996, and its authors said so in the section on choosing Eps and MinPts: “our experiments indicate that the k-dist graphs for k > 4 do not significantly differ from the 4-dist graph and, furthermore, they need considerably more computation. Therefore, we eliminate the parameter MinPts by setting it to 4 for all databases (for 2-dimensional data).” That parenthesis is the whole warning. It is also the part that travelled least well.
Twenty-one years later the same authors, now writing with Erich Schubert, revisited the heuristic and pointed instead to a value that scales: Sander et al. “suggest setting it to twice the dataset dimensionality, i.e., minPts = 2 · dim”. On the radius itself they add that “The way DBSCAN is designed, ε should be chosen as small as possible.”
A threshold that reflects an absolute neighbourhood scale inherits the dimension it was measured in. It inherits the scaling of the representation too.
k-nearest-neighbor graph
Each point connects to a fixed number of nearby points.
- Maintains degree in sparse regions
- Can bridge distant low-density areas
- May be directed before symmetrization
- Requires choosing k
Radius graph
Points connect when distance falls below a fixed threshold.
- Reflects absolute neighborhood scale
- Produces variable degree
- Can isolate sparse regions
- Is sensitive to scaling and density variation
Mutual-neighbor graph
An edge remains only when both points rank each other highly.
- Reduces one-sided hub connections
- Can improve local precision
- May fragment legitimate structure
- Needs connectivity checks
Steps
Qualify a neighborhood graph for downstream use
Treat building the graph as an auditable preprocessing stage. Perturbing the neighbour count is not a hygiene ritual. The authors of a mainstream tool document exactly what it changes.
UMAP's own paper, in its section on hyper-parameters, warns: “With smaller n values the manifold tends to be broken into many small connected components (care needs to be taken with the spectral embedding for initialization in such cases).” That initialisation is defined in the paper's own Algorithm 4. It takes the 1-skeleton of the graph as a weighted adjacency matrix and returns eigenvectors of its normalised Laplacian. So the neighbour count sets the number of connected components, and the components set the starting layout.
The same dependence turns up independently in a 2021 study by Wang and colleagues in the Journal of Machine Learning Research: “t-SNE uses random values, UMAP applies spectral embedding (Shi and Malik, 1997), and TriMap first runs PCA”.
Varying k, the radius, the bandwidth and the scaling is therefore a test of something specific: whether the component structure survives a defensible change of parameter. Everything initialised from that structure rides on the answer.
1. Compare graph families
Build kNN, radius, and mutual variants under the same representation.
2. Examine components
Identify fragmentation, giant components, isolated points, and suspicious bridges.
3. Review edge examples
Sample strong, weak, cross-region, and high-degree connections with domain experts.
4. Perturb parameters
Vary k, radius, bandwidth, and scaling to observe topological stability.
5. Record downstream sensitivity
Measure whether clustering or embeddings change when plausible graph choices change.
Example
Graph diagnostics that change the analysis
A graph should be inspected as an object before it becomes hidden inside another algorithm. How badly connectivity can be misread is measurable.
A widely used community-detection algorithm returns groups that are not connected inside the graph it was given. The 2019 paper in Scientific Reports that reported this is blunt about the scale of it: “In our experimental analysis, we observe that up to 25% of the communities are badly connected and up to 16% are disconnected.” Its authors then introduced the Leiden algorithm, with a proof that its communities are guaranteed to be connected.
- Connected components: Louvain returned up to 16% disconnected communities in those experiments. Even after the Leiden guarantee, an independent 2024 evaluation over 13 graphs from the SuiteSparse Matrix Collection still measured fractions of disconnected communities as large as 1.5×10⁻² for one widely used Leiden implementation. Hundreds of tiny components may equally indicate an overly strict radius, or genuinely separate populations. Count them before interpreting them.
- Degree distribution: A long tail can reveal hubs, duplicated records, generic embeddings, or dense subpopulations. The skewness of the k-occurrence distribution is the standard summary of that tail; for i.i.d. uniform data it ran 0.121, 1.541 and 5.445 at d = 3, 20 and 100.
- Bridge review: A few edges connecting major regions deserve manual inspection, because they can dominate spectral structure. The betweenness correlation of 0.647 at d = 100 says that in high dimensions those bridges are disproportionately the high-degree nodes.
- Mutual-neighbor retention: Comparing ordinary and mutual kNN graphs shows whether one-sided matches drive the topology.
- Edge perturbation: Rebuilding the graph after feature noise or resampling tests whether connectivity depends on fragile comparisons. It also tests which approximate edges happened to be found, since NN-Descent converges to above 90% recall rather than to the exact neighbour set.
Key idea
A Gaussian kernel does not choose its own scale
Affinity weights often use an expression that decays with squared distance. The bandwidth determines whether most edges look equally strong, nearly zero, or meaningfully graded. A global bandwidth can misrepresent data with varying density. Local scaling, mutual graphs, or density-aware methods may be more appropriate, but each introduces new assumptions.
The single width can also be removed. Zelnik-Manor and Perona replaced it with a local one in 2004, giving every point its own scale, set by the distance to its Kth neighbor. Across their synthetic and image experiments they “used a single value of K = 7”. One constant replaced a tuned parameter.
Kernel scale is a structural hyperparameter, not a cosmetic smoothing knob.
Connectivity is a constructed property
A similarity graph can expose local structure that coordinate-space algorithms miss. It can also amplify hubs, bridges, and scale mistakes. Spectral clustering, UMAP, and several density methods will rely on these relationships, and their output cannot be more trustworthy than the graph assumptions they inherit.
One usable rule for k comes from von Luxburg's spectral clustering tutorial. For n points drawn from a density with connected support, the kNN and mutual kNN graphs “will be connected if we choose k on the order of log(n)”. She notes that the result holds only in the limit. It is a starting point, not a setting.
How much a peer-reviewed conclusion can rest on one inherited graph default is on the record. Becht et al. had reported in Nature Biotechnology that UMAP preserved global structure better than t-SNE. Kobak and Linderman answered in the same journal in 2021: “this alleged superiority of UMAP can be entirely attributed to different choices of initialization in the implementations used by Becht et al.” The t-SNE implementations started from random values. The UMAP implementation started from Laplacian eigenmaps, the spectral embedding of the neighbour graph. Once informative initialisation is used, the two preserve global structure similarly well.
The same conclusion came out of a separate set of experiments, run by Wang and colleagues and published in the Journal of Machine Learning Research that year: “we found that the initialization has a much larger influence on the success rate than simply faster convergence and stability.”
The comparison was never between two methods. It was between two graph-derived defaults.
Validate the graph before interpreting the geometry built from it.
Key takeaways
- A neighborhood graph adds edge-selection assumptions to the underlying metric, and at scale the edges are approximate: NN-Descent converges to above 90% recall, not to the exact k nearest neighbours.
- kNN, radius, and mutual graphs behave differently across density regimes, and a radius threshold inherits the dimension it was tuned in — DBSCAN's MinPts = 4 was stated for 2-dimensional data and later replaced by minPts = 2 · dim.
- Components, degree, hubs, bridges, and isolates should be inspected directly: Louvain returned up to 25% badly connected and up to 16% disconnected communities in the experiments that motivated Leiden.
- Affinity bandwidth controls the effective scale of weighted relationships; Zelnik-Manor and Perona removed the global width by giving each point the distance to its Kth neighbor, with K = 7 throughout.
- Graph topology should remain credible across plausible parameter changes, because smaller neighbour counts break the manifold into many small connected components and those components seed the spectral initialisation.
- Downstream spectral and manifold methods inherit every graph construction choice — enough that a published result comparing UMAP and t-SNE was attributed entirely to differing initialisations.