fuzzyclust.viz.FuzzySOM#

class fuzzyclust.viz.FuzzySOM(grid_shape=(5, 5), m=2.0, regularization=1.0, difference_order=2, tol=0.0001, max_iter=300, init='pca', n_init=1, random_state=None, verbose=0)[source]#

Bases: BaseFuzzyClusterer

Fuzzy self-organizing map: regularized fuzzy c-means on a grid.

The cluster prototypes are the nodes of a low-dimensional (usually 2-D) grid. A smoothness penalty on the prototypes of neighboring nodes is added to the FCM functional, so that the fitted prototypes form an ordered, topology-preserving map of the data, as in Kohonen’s SOM, while the partition stays fuzzy and the objective is minimized exactly by alternating optimization. The map (U-matrix, component planes, hit histogram) is a visualization of high-dimensional data in its own right.

Parameters:
grid_shapetuple of int, default=(5, 5)

Nodes per grid axis; the number of clusters is prod(grid_shape) and the map dimension \(s\) is len(grid_shape) (1, 2 or 3).

mfloat, default=2.0

Fuzziness exponent \(m>1\).

regularizationfloat, default=1.0

Smoothness weight \(\vartheta\geq 0\). 0 recovers plain FCM with prod(grid_shape) clusters (unordered prototypes); larger values pull neighboring prototypes toward a smooth (locally linear) arrangement.

difference_order{1, 2}, default=2

Finite-difference operator of the penalty, see grid_laplacian(). Second-order differences (default) penalize curvature of the map and leave a linear grid unpenalised; first-order differences penalize the length of grid edges and contract the map toward the data center.

tolfloat, default=1e-4
max_iterint, default=300
init{“pca”, “random”, “kmeans++”} or ndarray, default=”pca”

"pca" places the grid regularly in the subspace of the first \(s\) principal components (as in the paper), which already gives an ordered start. Other options as in BaseFuzzyClusterer.

n_initint, default=1

Number of random restarts (only meaningful for init="random" or "kmeans++"); the run with the lowest final objective is kept.

random_stateint, RandomState instance or None, default=None
verboseint, default=0
Attributes:
cluster_centers_ndarray of shape (n_nodes, n_features)

Prototypes \(\mathbf{v}_i\) (node i has grid coordinates grid_positions_[i]).

membership_ndarray of shape (n_samples, n_nodes)
labels_ndarray of shape (n_samples,)

Best-matching node of every sample.

distances_ndarray of shape (n_samples, n_nodes)
grid_positions_ndarray of shape (n_nodes, s)

Integer grid coordinates of the nodes.

regularization_matrix_ndarray of shape (n_nodes, n_nodes)

The matrix \(\mathbf{L}\).

n_clusters_int

Number of nodes.

objective_, objective_history_, n_iter_

See BaseFuzzyClusterer; the objective includes the penalty term.

Notes

The algorithm minimizes the regularized c-means functional

\[J(\mathbf{X};\mathbf{U},\mathbf{V}) = \sum_{i=1}^{c}\sum_{k=1}^{N} \mu_{ik}^m\|\mathbf{x}_k-\mathbf{v}_i\|^2 + \vartheta\,\mathrm{tr}\!\left(\mathbf{V}^T\mathbf{L}\mathbf{V}\right), \qquad \mathbf{L}=\mathbf{G}^T\mathbf{G},\]

where the rows of \(\mathbf{G}\) are finite differences of the prototypes along the grid axes, so that \(\mathrm{tr}(\mathbf{V}^T\mathbf{L}\mathbf{V})\approx \sum_i\|\partial^2\mathbf{v}_i/\partial\mathbf{x}^2\|^2\) approximates the integrated curvature of the map. The membership update is that of FCM. For fixed \(\mathbf{U}\) the prototypes are coupled through \(\mathbf{L}\): setting the gradient to zero gives the linear system

\[\mathbf{v}_i\sum_{k=1}^{N}\mu_{ik}^m + \vartheta\sum_{j=1}^{c}L_{ij}\mathbf{v}_j = \sum_{k=1}^{N}\mu_{ik}^m\mathbf{x}_k,\qquad i=1,\dots,c,\]

i.e. \((\mathrm{diag}(\textstyle\sum_k\mu_{ik}^m)+\vartheta\mathbf{L})\mathbf{V} = (\mathbf{U}^m)\mathbf{X}\), which is solved exactly in every iteration (the paper iterates its row-wise form, eq. (12), whose fixed point this is). With \(\vartheta=0\) the system decouples into the FCM center formula.

References

[1]

J. Abonyi, S. Migály, F. Szeifert, “Fuzzy self-organizing map based on regularized fuzzy c-means clustering”, in: Advances in Soft Computing - Engineering Design and Manufacturing, Springer, 2003.

[2]

T. Kohonen, “The self-organizing map”, Proc. IEEE 78(9), 1464-1480, 1990.

[3]

R. D. Pascual-Marqui, A. D. Pascual-Montano, K. Kochi, J. M. Carazo, “Smoothly distributed fuzzy c-means: a new self-organizing map”, Pattern Recognition 34, 2395-2402, 2001.

Examples

>>> from fuzzyclust.datasets import make_fuzzy_blobs
>>> from fuzzyclust.viz import FuzzySOM
>>> X, _ = make_fuzzy_blobs(n_clusters=3, n_features=4, random_state=0)
>>> som = FuzzySOM(grid_shape=(4, 4), regularization=0.5, random_state=0).fit(X)
>>> som.cluster_centers_.shape, som.u_matrix().shape
((16, 4), (4, 4))
component_planes()[source]#

Prototype coordinates arranged on the grid, one plane per feature.

Returns:
planesndarray of shape (n_features, *grid_shape)
hits(X=None)[source]#

Fuzzy hit histogram \(h_i=\sum_k\mu_{ik}\) on the grid (training data or X).

neighbor_distance()[source]#

Mean prototype distance over all grid edges (a scalar “roughness” of the map).

u_matrix()[source]#

Unified distance matrix: mean distance of every node’s prototype to its grid neighbors.

Large values mark “walls” between groups of similar prototypes, so cluster borders of the data appear as ridges on the map.

Returns:
umatndarray of shape grid_shape

Examples using fuzzyclust.viz.FuzzySOM#

Fuzzy self-organizing map: ordered prototypes by regularized FCM

Fuzzy self-organizing map: ordered prototypes by regularized FCM