graphclust.graphs#

Graphs built from data: neighborhood graphs, spanning trees and graph distances.

Every function returns a symmetric scipy.sparse.csr_matrix whose entry \((i,j)\) is the Euclidean length of the edge between samples \(\mathbf{x}_i\) and \(\mathbf{x}_j\) (zero means “no edge”). This is the format of scipy.sparse.csgraph, so shortest paths, connected components and spanning trees can be computed directly; to_networkx() converts the result for community detection or drawing.

The proximity graphs form the classical chain

\[\mathrm{NNG}\subseteq\mathrm{MST}\subseteq\mathrm{RNG}\subseteq \mathrm{GG}\subseteq\mathrm{DT},\]

which neighborhood_chain() verifies on a data set.

Neighborhood graphs, spanning trees, shared neighbors and geodesic distances.

Functions#

competitive_hebbian_graph(X, nodes)

Induced Delaunay triangulation by competitive Hebbian learning (Martinetz 1993).

connect_components(points, adjacency)

Join the connected components of a graph by its shortest inter-component edges.

delaunay_graph(X)

Delaunay triangulation as a graph (practical up to about six dimensions).

edges_of(A)

Undirected edge list (edges, weights) of a symmetric sparse graph (each edge once, i < j).

epsilon_graph(X, eps)

\(\varepsilon\)-neighborhood graph: samples closer than eps are linked.

gabriel_graph(X)

Gabriel graph: \(\mathbf{x}_i,\mathbf{x}_j\) are linked when the ball with diameter \(\overline{\mathbf{x}_i\mathbf{x}_j}\) contains no other sample.

geodesic_distances(graph, *[, points, connect])

All-pairs shortest-path (graph, geodesic) distances with Dijkstra's algorithm.

knn_graph(X[, k, metric])

Symmetric \(k\)-nearest-neighbor graph.

knn_indices(X, k[, metric])

Indices and distances of the k nearest neighbors of every sample (the sample itself excluded).

minimum_spanning_tree([X, graph])

Euclidean minimal spanning tree (symmetric) of the samples or of a given weighted graph.

mutual_knn_graph(X[, k, metric])

Mutual \(k\)-nearest-neighbor graph: an edge only if each sample is among the other's neighbors.

nearest_neighbor_graph(X)

Nearest neighbor graph (NNG): every sample is linked to its single nearest neighbor.

neighborhood_chain(X)

Edge counts of NNG, MST, RNG, Gabriel graph and Delaunay triangulation, and whether each is contained in the next (for 2-D or 3-D data).

relative_neighborhood_graph(X)

Relative neighborhood graph (Toussaint): \(\mathbf{x}_i,\mathbf{x}_j\) are linked when no third sample is closer to both of them than they are to each other.

shared_neighbor_counts(X[, k, include_self])

Number of shared \(k\)-nearest neighbors \(m_{ij}=|A_i\cap A_j|\) for every pair.

to_networkx(A[, positions])

Convert a sparse adjacency matrix to a networkx.Graph (edge attribute weight).