fuzzyclust.graph.GeodesicFCM#
- class fuzzyclust.graph.GeodesicFCM(n_clusters=3, n_neighbors=10, radius=None, connect_components=True, bridge_penalty=1.0, m=2.0, tol=0.0001, max_iter=100, init='kmeans++', n_init=1, random_state=None, verbose=0)[source]#
Bases:
BaseFuzzyClustererGeodesic-distance-based fuzzy c-medoid clustering (Feil and Abonyi, Algorithm II).
Point prototypes with the Euclidean distance assume convex, roughly spherical groups. When the data lie on a curved low-dimensional manifold (spiral arms, moons, rings), two points that are close in Euclidean distance may be far apart along the manifold. This algorithm measures the distance between samples and prototypes with the geodesic distance – the shortest path in a \(k\)-nearest-neighbor graph – and restricts the prototypes to be data points (medoids), so that they lie on the manifold and the geodesic distance to them is defined.
- Parameters:
- n_clusters
int, default=3 Number of clusters \(c\).
- n_neighbors
int, default=10 Number of neighbors \(k\) of the graph. Too small a value disconnects the manifold, too large a value “short-circuits” it (edges jump between arms). The paper’s spiral needs \(k\le4\) to keep the two arms apart.
- radius
floatorNone, default=None Use an \(\varepsilon\)-neighborhood graph instead of \(k\) neighbors.
- connect_componentsbool, default=True
Join disconnected components through their closest points, so that every geodesic distance is finite (see
geodesic_distances()). WithFalsethe samples of a component without medoid share their membership uniformly, and clusters never span components.- bridge_penalty
float, default=1.0 Extra length of the bridges, as a multiple of the largest finite geodesic distance;
0gives plain Euclidean bridges. The penalty is right when the components are the clusters (rings, moons): it keeps them apart although all distances are finite. Whenn_neighborsis too small and the components are fragments of one manifold (n_components_far aboven_clusters), a plain bridge re-joins the fragments at their natural junctions and works better.- m
float, default=2.0 Fuzziness exponent \(m>1\).
- tol
float, default=1e-4 - max_iter
int, default=100 - init{“kmeans++”, “random”}
orarray_likeofint, default=”kmeans++” "kmeans++"is the D2-weighted seeding on geodesic distances,"random"picks \(c\) random samples as initial medoids (the paper’s “arbitrary” start); an integer array gives the initial medoid indices. The seeding is the default because a medoid can hardly migrate across a penalized bridge during the iterations: a random start that puts every medoid into one graph component leaves the other components without a prototype.- n_init
int, default=1 Random restarts; the run with the lowest \(J\) is kept.
- random_state
int,RandomStateinstanceorNone, default=None - verbose
int, default=0
- n_clusters
- Attributes:
- medoid_indices_
ndarrayofshape(n_clusters,) Row indices of the medoids in the training data.
- cluster_centers_
ndarrayofshape(n_clusters,n_features) The medoids
X[medoid_indices_].- membership_
ndarrayofshape(n_samples,n_clusters) - labels_
ndarrayofshape(n_samples,) - geodesic_distances_
ndarrayofshape(n_samples,n_samples) Geodesic distance matrix of the training data (
infbetween components whenconnect_components=False).- neighbors_graph_
scipy.sparse.csr_matrix The neighborhood graph used (after connecting components).
- n_components_
int Number of connected components of the raw neighborhood graph.
- component_labels_
ndarrayofshape(n_samples,) - bridge_edges_
ndarrayofshape(n_bridges, 2) Edges added to connect the components.
- distances_, objective_, objective_history_, n_iter_
See
BaseFuzzyClusterer.
- medoid_indices_
Notes
The objective is the c-means functional with geodesic distances \(d_g\),
\[J = \sum_{i=1}^{c}\sum_{k=1}^{N}\mu_{ik}^m\, d_g(\mathbf{x}_k,\mathbf{v}_i)^2, \qquad \mathbf{v}_i\in\{\mathbf{x}_1,\dots,\mathbf{x}_N\},\]alternating the FCM membership formula (with \(d_g\))
\[\mu_{ik} = \frac{1}{\sum_{j=1}^{c}\big(d_g(\mathbf{x}_k,\mathbf{v}_i)/ d_g(\mathbf{x}_k,\mathbf{v}_j)\big)^{2/(m-1)}}\]and the medoid update
\[\mathbf{v}_i = \mathbf{x}_j,\qquad j = \argmin_{l}\sum_{k=1}^{N}\mu_{ik}^m\, d_g(\mathbf{x}_k,\mathbf{x}_l)^2 ,\]i.e. every sample is tried as a medoid, which costs \(O(cN^2)\) per iteration (the paper mentions sampling schemes such as CLARA for large \(N\)). The geodesic distance matrix is dense, \(O(N^2)\) memory.
New samples. The geodesic distance of a point outside the training set is not defined.
predict_proba()uses the nearest training sample as a proxy: the distance of a new point to a medoid is the Euclidean distance to its nearest training neighbor plus that neighbor’s geodesic distance to the medoid. This is exact for training points and a reasonable approximation close to the manifold.References
[1]B. Feil, J. Abonyi, “Geodesic distance based fuzzy clustering”, in: Soft Computing in Industrial Applications, Advances in Soft Computing 39, Springer, 50–59, 2007.
[2]J. B. Tenenbaum, V. de Silva, J. C. Langford, “A global geometric framework for nonlinear dimensionality reduction”, Science 290, 2319–2323, 2000.
[3]Kaufman, P. J. Rousseeuw, “Finding Groups in Data”, Wiley, 1990.
Examples
>>> from fuzzyclust.graph import GeodesicFCM >>> from fuzzyclust.datasets import make_curved_manifold >>> X, y = make_curved_manifold(n_samples=300, random_state=0) >>> geo = GeodesicFCM(n_clusters=2, n_neighbors=5, random_state=0).fit(X) >>> geo.medoid_indices_.shape, geo.geodesic_distances_.shape ((2,), (300, 300))
Examples using fuzzyclust.graph.GeodesicFCM#
Geodesic-distance-based fuzzy clustering versus fuzzy c-means
Geodesic paths, the S-curve, and clustering of the Isomap projection