fuzzyclust.viz.FuzzySammon#

class fuzzyclust.viz.FuzzySammon(n_components=2, max_iter=100, alpha=0.4, init='pca', tol=1e-06, backtracking=True, max_backtracks=10, m=None, weight_exponent=None, random_state=None)[source]#

Bases: BaseEstimator

Fuzzy Sammon mapping (FUZZSAM) of a fitted fuzzy clustering.

Classical Sammon mapping preserves the \(N(N-1)/2\) Euclidean inter-point distances of the data and therefore (i) is expensive for large \(N\) and (ii) ignores the distance measure of the clustering algorithm (the adaptive norms of GK/GG, or any non-point prototype). FUZZSAM instead preserves only the \(N\times c\) distances between the samples and the cluster prototypes, measured by the clustering algorithm itself, weighted by the memberships. In the plane every cluster is a single point \(\mathbf{z}_i\) and the geometry around it is Euclidean, so a cluster whose prototype fits the data well appears as a compact, roughly circular group, whatever its shape in the original space.

Parameters:
n_componentsint, default=2

Dimension \(q\) of the embedding.

max_iterint, default=100

Maximum number of iterations.

alphafloat, default=0.4

Step size of the pseudo-Newton update (0.3-0.4 recommended).

init{“pca”, “random”} or ndarray of shape (n_samples, n_components), default=”pca”

Initial configuration of the projected data: principal component scores of X (requires X), uniform random points in \([-0.5,0.5]^q\), or an explicit matrix (e.g. the result of Sammon, as in the MATLAB demo).

tolfloat, default=1e-6

Stop when the relative decrease of \(E_\text{fuzz}\) is below tol.

backtrackingbool, default=True

Safeguard of the Newton step as in Sammon: clip outlying displacements and halve the step (at most max_backtracks times) when it would increase \(E_\text{fuzz}\).

max_backtracksint, default=10
mfloat or None, default=None

Fuzziness exponent used for the weights and the recomputed memberships. None takes estimator.m (2.0 if the estimator has no m).

weight_exponentfloat or None, default=None

Exponent of the membership weights \(\mu_{ik}^{w}\) in the cost and in the projected-center formula. None uses \(w=m\) (FUZZSAM of Abonyi & Babuška 2004 and of the MATLAB toolbox); 1.0 gives the first variant of Kovács & Abonyi (2002), which weighted with \(\mu_{ik}\) itself.

random_stateint, RandomState instance or None, default=None

Seed for init="random".

Attributes:
embedding_ndarray of shape (n_samples, n_components)

Projected data \(\mathbf{y}_k\).

embedded_centers_ndarray of shape (n_clusters, n_components)

Projected cluster centers \(\mathbf{z}_i\).

stress_float

Final value of \(E_\text{fuzz}\).

stress_history_ndarray of shape (n_iter_,)
n_iter_int
membership_ndarray of shape (n_samples, n_clusters)

The partition that was mapped (copied from the estimator).

distances_ndarray of shape (n_samples, n_clusters)

The prototype distances \(d_{ik}\) that were mapped.

m_float

Fuzziness exponent actually used.

Notes

FUZZSAM minimizes

\[E_\text{fuzz} = \sum_{i=1}^{c}\sum_{k=1}^{N}\mu_{ik}^m \left(d(\mathbf{x}_k,\mathbf{v}_i) - d^*_{ik}\right)^2,\qquad d^*_{ik}=\|\mathbf{y}_k-\mathbf{z}_i\|,\]

where \(d(\mathbf{x}_k,\mathbf{v}_i)\) is the distance of the clustering algorithm (estimator.transform(X): Euclidean for FCM, Mahalanobis-type for GK, the exponential distance of GG, …). The projected points are moved by the Sammon-type diagonal Newton step

\[y_{kl} \leftarrow y_{kl} - \alpha\, \frac{\partial E_\text{fuzz}/\partial y_{kl}}{|\partial^2 E_\text{fuzz}/\partial y_{kl}^2|},\quad \frac{\partial E_\text{fuzz}}{\partial y_{kl}} = -2\sum_{i=1}^{c}\mu_{ik}^m \frac{d_{ik}-d^*_{ik}}{d^*_{ik}}(y_{kl}-z_{il}),\]
\[\frac{\partial^2 E_\text{fuzz}}{\partial y_{kl}^2} = -2\sum_{i=1}^{c} \frac{\mu_{ik}^m}{d^*_{ik}}\left[(d_{ik}-d^*_{ik}) -\frac{(y_{kl}-z_{il})^2}{d^*_{ik}}\left(1+\frac{d_{ik}-d^*_{ik}}{d^*_{ik}}\right)\right],\]

and after every sweep the projected centers are recomputed as the membership-weighted means \(\mathbf{z}_i=\sum_k\mu_{ik}^m\mathbf{y}_k/\sum_k\mu_{ik}^m\). Only \(N c\) distances are needed per iteration instead of \(N(N-1)/2\). The quality of the map is judged with projection_quality().

References

[1]

A. Kovács, J. Abonyi, “Visualization of fuzzy clustering results by modified Sammon mapping”, Proc. 3rd Int. Symp. of Hungarian Researchers on Computational Intelligence, 177-188, 2002.

[2]

J. Abonyi, R. Babuška, “FUZZSAM - visualization of fuzzy clustering results by modified Sammon mapping”, Proc. IEEE Int. Conf. on Fuzzy Systems (FUZZ-IEEE), 2004.

[3]

B. Feil, B. Balasko, J. Abonyi, “Visualization of fuzzy clusters by fuzzy Sammon mapping projection: application to the analysis of phase space trajectories”, Soft Computing 11, 479-488, 2007.

Examples

>>> from fuzzyclust import GK
>>> from fuzzyclust.datasets import make_fuzzy_blobs
>>> from fuzzyclust.viz import FuzzySammon
>>> X, _ = make_fuzzy_blobs(n_clusters=3, n_features=5, random_state=0)
>>> gk = GK(n_clusters=3, random_state=0).fit(X)
>>> fs = FuzzySammon(max_iter=50).fit(gk, X)
>>> fs.embedding_.shape, fs.embedded_centers_.shape
((300, 2), (3, 2))
fit(estimator=None, X=None, *, membership=None, distances=None)[source]#

Map the result of a fuzzy clustering to n_components dimensions.

Parameters:
estimatorfitted fuzzyclust clusterer, optional

Provides the memberships (predict_proba/membership_), the algorithm-specific distances (transform/distances_) and m.

Xarray_like of shape (n_samples, n_features), optional

The clustered data. Needed for init="pca"; when given together with estimator the memberships and distances are re-evaluated on it (so any data set the estimator can score may be mapped).

membershiparray_like of shape (n_samples, n_clusters), optional

Partition \(\mathbf{U}^T\) (alternative to estimator).

distancesarray_like of shape (n_samples, n_clusters), optional

Prototype distances \(d_{ik}\) (alternative to estimator).

Returns:
selfobject
fit_transform(estimator=None, X=None, *, membership=None, distances=None)[source]#

Fit and return the embedding (n_samples, n_components).

quality(X=None)[source]#

Projection quality measures P, F, F_star (and E if X is given).

See projection_quality().

recomputed_membership()[source]#

Memberships \(\mathbf{U}^*\) implied by the plot (FCM formula on the projected distances).

Examples using fuzzyclust.viz.FuzzySammon#

Fuzzy Sammon mapping: projecting clusters, not just data

Fuzzy Sammon mapping: projecting clusters, not just data

Visual validation of the number of clusters with FUZZSAM

Visual validation of the number of clusters with FUZZSAM

State-space reconstruction and prediction of a chaotic time series

State-space reconstruction and prediction of a chaotic time series