fuzzyclust.viz.Sammon#

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

Bases: TransformerMixin, BaseEstimator

Sammon’s nonlinear mapping to a low-dimensional space.

Sammon mapping is a multidimensional-scaling method: it looks for \(N\) points \(\mathbf{y}_k\in\mathbb{R}^q\) whose pairwise Euclidean distances \(d^*_{kl}\) reproduce the pairwise distances \(d_{kl}=\|\mathbf{x}_k-\mathbf{x}_l\|\) of the original \(n\)-dimensional data as closely as possible. In contrast to PCA, which preserves variance, the mapping preserves distances, which is the quantity clustering algorithms work with.

Parameters:
n_componentsint, default=2

Dimension \(q\) of the embedding.

max_iterint, default=100

Maximum number of iterations of the pseudo-Newton descent.

alphafloat, default=0.3

Step size (“magic factor”) of the update, Sammon recommends 0.3-0.4. Larger values converge faster but may oscillate.

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

Initial configuration. "pca" starts from the principal component scores (deterministic and usually close to the optimum), "random" from uniform noise in \([-0.5, 0.5]^q\) (MATLAB toolbox behavior).

tolfloat, default=1e-6

Stop when the relative decrease of the stress between two iterations falls below tol.

backtrackingbool, default=True

Safeguard the update: displacements longer than 30 times the median displacement are clipped, and the step is halved (at most max_backtracks times) whenever it would increase the stress. Sammon’s diagonal Newton step divides by the curvature, which can be arbitrarily small for single points and then throws them far away; the safeguard makes the stress history (almost always) monotone at the cost of one extra distance evaluation per halving. With False the raw update of the original algorithm is used.

max_backtracksint, default=10
random_stateint, RandomState instance or None, default=None

Seed for init="random".

Attributes:
embedding_ndarray of shape (n_samples, n_components)

The projected points \(\mathbf{y}_k\) (centered at the origin).

stress_float

Final Sammon stress \(E\), see sammon_stress().

stress_history_ndarray of shape (n_iter_,)

\(E\) after every iteration.

n_iter_int
n_features_in_int

Notes

The stress

\[E = \frac{1}{\lambda}\sum_{k<l}\frac{(d_{kl}-d^*_{kl})^2}{d_{kl}},\qquad \lambda=\sum_{k<l}d_{kl},\]

is minimized in the \(Nq\) coordinates \(y_{kl}\) by the diagonal Newton step proposed by Sammon,

\[y_{kl}(t+1) = y_{kl}(t) - \alpha\, \frac{\partial E/\partial y_{kl}}{\left|\partial^2 E/\partial y_{kl}^2\right|},\]

with

\[\begin{split}\frac{\partial E}{\partial y_{kl}} &= -\frac{2}{\lambda}\sum_{j\neq k} \frac{d_{kj}-d^*_{kj}}{d_{kj}d^*_{kj}}\,(y_{kl}-y_{jl}),\\ \frac{\partial^2 E}{\partial y_{kl}^2} &= -\frac{2}{\lambda}\sum_{j\neq k} \frac{1}{d_{kj}d^*_{kj}}\left[(d_{kj}-d^*_{kj}) - \frac{(y_{kl}-y_{jl})^2}{d^*_{kj}}\left(1+\frac{d_{kj}-d^*_{kj}}{d^*_{kj}}\right)\right].\end{split}\]

All points are updated simultaneously and the configuration is re-centered after every step; by default the step is halved when it would increase the stress (backtracking). Every iteration needs the \(N(N-1)/2\) pairwise distances of the current configuration, which makes the method expensive for large \(N\); this motivates the fuzzy Sammon mapping (FuzzySammon). The stress surface has local minima, so different initializations may give different maps.

Projecting new samples is not defined for Sammon mapping (the whole optimization would have to be repeated), hence transform raises NotImplementedError; use fit_transform().

References

[1]

J. W. Sammon Jr., “A nonlinear mapping for data structure analysis”, IEEE Transactions on Computers C-18(5), 401-409, 1969.

[2]

J. Mao, A. K. Jain, “Artificial neural networks for feature extraction and multivariate data projection”, IEEE Transactions on Neural Networks 6(2), 296-317, 1995.

Examples

>>> from fuzzyclust.datasets import make_fuzzy_blobs
>>> from fuzzyclust.viz import Sammon
>>> X, _ = make_fuzzy_blobs(n_clusters=3, n_features=5, random_state=0)
>>> sam = Sammon(n_components=2, max_iter=50, random_state=0)
>>> Y = sam.fit_transform(X)
>>> Y.shape, sam.stress_ < 0.1
((300, 2), True)
fit(X, y=None)[source]#

Compute the embedding of X.

Parameters:
Xarray_like of shape (n_samples, n_features)
yIgnored
Returns:
selfobject
fit_transform(X, y=None)[source]#

Fit the mapping and return the embedding (n_samples, n_components).

transform(X)[source]#

Not available: Sammon mapping has no out-of-sample extension (raises NotImplementedError).

Examples using fuzzyclust.viz.Sammon#

PCA versus Sammon mapping: preserving variance or distances

PCA versus Sammon mapping: preserving variance or distances

Fuzzy Sammon mapping: projecting clusters, not just data

Fuzzy Sammon mapping: projecting clusters, not just data