fuzzyclust.viz.grid_laplacian#

fuzzyclust.viz.grid_laplacian(grid_shape, order=2)[source]#

Regularization matrix \(\mathbf{L}=\mathbf{G}^T\mathbf{G}\) of a rectangular grid.

The prototypes \(\mathbf{v}_i\) of a fuzzy SOM sit on the nodes of a regular grid in \(s\) dimensions. Smoothness of the map is measured by finite differences of the prototypes along every grid axis: with order=2 the rows of \(\mathbf{G}\) are the second-order differences \(\mathbf{v}_{i-1}-2\mathbf{v}_i+\mathbf{v}_{i+1}\) at every interior node (Abonyi, Migály & Szeifert), with order=1 the first-order differences \(\mathbf{v}_{i+1}-\mathbf{v}_i\) of every pair of adjacent nodes (the “smoothly distributed FCM” of Pascual-Marqui et al., 2001). The penalty \(\vartheta\,\mathrm{tr}(\mathbf{V}^T\mathbf{L}\mathbf{V})\) is then \(\vartheta\sum\|\text{difference}\|^2\).

Parameters:
grid_shapetuple of int

Number of nodes along every grid axis, e.g. (5, 5).

order{1, 2}, default=2

Order of the difference operator.

Returns:
Lndarray of shape (n_nodes, n_nodes)

Symmetric positive semi-definite regularization matrix.

positionsndarray of shape (n_nodes, len(grid_shape))

Integer grid coordinates of the nodes (C order, node i is positions[i]).

Examples

>>> from fuzzyclust.viz import grid_laplacian
>>> L, pos = grid_laplacian((5,), order=2)
>>> L.astype(int)
array([[ 1, -2,  1,  0,  0],
       [-2,  5, -4,  1,  0],
       [ 1, -4,  6, -4,  1],
       [ 0,  1, -4,  5, -2],
       [ 0,  0,  1, -2,  1]])