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:
BaseEstimatorFuzzy 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_components
int, default=2 Dimension \(q\) of the embedding.
- max_iter
int, default=100 Maximum number of iterations.
- alpha
float, default=0.4 Step size of the pseudo-Newton update (0.3-0.4 recommended).
- init{“pca”, “random”}
orndarrayofshape(n_samples,n_components), default=”pca” Initial configuration of the projected data: principal component scores of
X(requiresX), uniform random points in \([-0.5,0.5]^q\), or an explicit matrix (e.g. the result ofSammon, as in the MATLAB demo).- tol
float, 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 mostmax_backtrackstimes) when it would increase \(E_\text{fuzz}\).- max_backtracks
int, default=10 - m
floatorNone, default=None Fuzziness exponent used for the weights and the recomputed memberships.
Nonetakesestimator.m(2.0 if the estimator has nom).- weight_exponent
floatorNone, default=None Exponent of the membership weights \(\mu_{ik}^{w}\) in the cost and in the projected-center formula.
Noneuses \(w=m\) (FUZZSAM of Abonyi & Babuška 2004 and of the MATLAB toolbox);1.0gives the first variant of Kovács & Abonyi (2002), which weighted with \(\mu_{ik}\) itself.- random_state
int,RandomStateinstanceorNone, default=None Seed for
init="random".
- n_components
- Attributes:
- embedding_
ndarrayofshape(n_samples,n_components) Projected data \(\mathbf{y}_k\).
- embedded_centers_
ndarrayofshape(n_clusters,n_components) Projected cluster centers \(\mathbf{z}_i\).
- stress_
float Final value of \(E_\text{fuzz}\).
- stress_history_
ndarrayofshape(n_iter_,) - n_iter_
int - membership_
ndarrayofshape(n_samples,n_clusters) The partition that was mapped (copied from the estimator).
- distances_
ndarrayofshape(n_samples,n_clusters) The prototype distances \(d_{ik}\) that were mapped.
- m_
float Fuzziness exponent actually used.
- embedding_
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_componentsdimensions.- Parameters:
- estimator
fittedfuzzyclustclusterer,optional Provides the memberships (
predict_proba/membership_), the algorithm-specific distances (transform/distances_) andm.- Xarray_like
ofshape(n_samples,n_features),optional The clustered data. Needed for
init="pca"; when given together withestimatorthe memberships and distances are re-evaluated on it (so any data set the estimator can score may be mapped).- membershiparray_like
ofshape(n_samples,n_clusters),optional Partition \(\mathbf{U}^T\) (alternative to
estimator).- distancesarray_like
ofshape(n_samples,n_clusters),optional Prototype distances \(d_{ik}\) (alternative to
estimator).
- estimator
- Returns:
- self
object
- self
- 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(andEifXis given).See
projection_quality().
Examples using fuzzyclust.viz.FuzzySammon#
Fuzzy Sammon mapping: projecting clusters, not just data
Visual validation of the number of clusters with FUZZSAM
State-space reconstruction and prediction of a chaotic time series