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:
BaseFuzzyClustererFuzzy 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_shape
tupleofint, default=(5, 5) Nodes per grid axis; the number of clusters is
prod(grid_shape)and the map dimension \(s\) islen(grid_shape)(1, 2 or 3).- m
float, default=2.0 Fuzziness exponent \(m>1\).
- regularization
float, default=1.0 Smoothness weight \(\vartheta\geq 0\).
0recovers plain FCM withprod(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.- tol
float, default=1e-4 - max_iter
int, default=300 - init{“pca”, “random”, “kmeans++”}
orndarray, 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 inBaseFuzzyClusterer.- n_init
int, default=1 Number of random restarts (only meaningful for
init="random"or"kmeans++"); the run with the lowest final objective is kept.- random_state
int,RandomStateinstanceorNone, default=None - verbose
int, default=0
- grid_shape
- Attributes:
- cluster_centers_
ndarrayofshape(n_nodes,n_features) Prototypes \(\mathbf{v}_i\) (node
ihas grid coordinatesgrid_positions_[i]).- membership_
ndarrayofshape(n_samples,n_nodes) - labels_
ndarrayofshape(n_samples,) Best-matching node of every sample.
- distances_
ndarrayofshape(n_samples,n_nodes) - grid_positions_
ndarrayofshape(n_nodes,s) Integer grid coordinates of the nodes.
- regularization_matrix_
ndarrayofshape(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.
- cluster_centers_
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:
- planes
ndarrayofshape(n_features, *grid_shape)
- planes
Examples using fuzzyclust.viz.FuzzySOM#
Fuzzy self-organizing map: ordered prototypes by regularized FCM