fuzzyclust.graph.neighbors_graph#

fuzzyclust.graph.neighbors_graph(X, n_neighbors=10, radius=None)[source]#

Symmetric \(k\)-nearest-neighbor (or \(\varepsilon\)-radius) graph with Euclidean weights.

Two samples are linked when either one is among the \(k\) nearest neighbors of the other (\(k\)-Isomap) or when they are closer than radius (\(\varepsilon\)-Isomap). A sample is never its own neighbor; coincident samples are linked by an edge of length EPS so that a zero weight never means “no edge”.

Parameters:
Xarray_like of shape (n_samples, n_features)
n_neighborsint or None, default=10

Number of neighbors \(k\). Ignored when radius is given.

radiusfloat or None, default=None

Connect all pairs closer than radius.

Returns:
Gscipy.sparse.csr_matrix of shape (n_samples, n_samples)

Symmetric adjacency with the Euclidean distances as weights (a structurally missing entry means “no edge”).

Examples

>>> import numpy as np
>>> from fuzzyclust.graph import neighbors_graph
>>> X = np.c_[np.arange(5.0), np.zeros(5)]
>>> G = neighbors_graph(X, n_neighbors=1)
>>> G.nnz, float(G.max())
(8, 1.0)