fuzzyclust.graph.geodesic_distances#
- fuzzyclust.graph.geodesic_distances(X, n_neighbors=10, radius=None, connect_components=True, bridge_penalty=1.0, method='auto')[source]#
Graph (geodesic) distances between all pairs of samples, Isomap style.
The geodesic distance along the manifold the data lie on is approximated by the length of the shortest path in a neighborhood graph whose edges are weighted by Euclidean distances (Tenenbaum, de Silva and Langford, 2000); the approximation converges to the true geodesic as the sampling density grows (Bernstein et al., 2000).
- Parameters:
- Xarray_like
ofshape(n_samples,n_features) - n_neighbors
intorNone, default=10 - radius
floatorNone, default=None See
neighbors_graph().- connect_componentsbool, default=True
If the graph falls apart into several components, link them through their closest pairs of points so that all distances are finite. With
Falsethe distances between components areinf.- bridge_penalty
float, default=1.0 Length added to every bridge, as a multiple of the largest finite geodesic distance of the unconnected graph. With the default a path that crosses a bridge is always longer than any path inside a component, so that the components keep their identity in the clustering although all distances are finite;
0gives the plain Euclidean bridge.- method
str, default=”auto” Shortest-path algorithm of
scipy.sparse.csgraph.shortest_path().
- Xarray_like
- Returns:
- result
sklearn.utils.Bunch distances– geodesic distance matrix(n_samples, n_samples);graph– the (possibly connected) neighborhood graph (CSR);n_components– number of connected components of the raw graph;component_labels– component of every sample in the raw graph;bridges– the added bridge edges(n_bridges, 2).
- result
Examples
>>> from fuzzyclust.datasets import make_rings >>> from fuzzyclust.graph import geodesic_distances >>> X, _ = make_rings(random_state=0) >>> geo = geodesic_distances(X, n_neighbors=6) >>> geo.n_components, geo.distances.shape, bool(np.isfinite(geo.distances).all()) (2, (300, 300), True)
Examples using fuzzyclust.graph.geodesic_distances#
Geodesic paths, the S-curve, and clustering of the Isomap projection