Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Need a specific example of U-Matrix in Self Organizing Map

I'm trying to develop an application using SOM in analyzing data. However, after finishing training, I cannot find a way to visualize the result. I know that U-Matrix is one of the method but I cannot understand it properly. Hence, I'm asking for a specific and detail example how to construct U-Matrix.

I also read an answer at U-matrix and self organizing maps but it only refers to 1 row map, how about 3x3 map? I know that for 3x3 map:

m(1) m(2) m(3)
m(4) m(5) m(6)
m(7) m(8) m(9)

a 5x5 matrix must me created:

u(1)   u(1,2)     u(2)   u(2,3)     u(3)
u(1,4) u(1,2,4,5) u(2,5) u(2,3,5,6) u(3,6)
u(4)   u(4,5)     u(5)   u(5,6)     u(6)
u(4,7) u(4,5,7,8) u(5,8) u(5,6,8,9) u(6,9)
u(7)   u(7,8)     u(8)   u(8,9)     u(9)

but I don't know how to calculate u-weight u(1,2,4,5), u(2,3,5,6), u(4,5,7,8) and u(5,6,8,9).

Finally, after constructing U-Matrix, is there any way to visualize it using color, e.g. heat map?

Thank you very much for your time.

Cheers

like image 215
Long Thai Avatar asked Jun 26 '11 17:06

Long Thai


2 Answers

I don't know if you are still interested in this but I found this link http://www.uni-marburg.de/fb12/datenbionik/pdf/pubs/1990/UltschSiemon90 which explains very speciffically how to calculate the U-matrix. Hope it helps.

By the way, the site were I found the link has several resources referring to SOMs I leave it here in case anyone is interested: http://www.ifs.tuwien.ac.at/dm/somtoolbox/visualisations.html

like image 198
Ludecan Avatar answered Jan 02 '23 20:01

Ludecan


The essential idea of a Kohonen map is that the data points are mapped to a lattice, which is often a 2D rectangular grid.

In the simplest implementations, the lattice is initialized by creating a 3D array with these dimensions:

width * height * number_features

This is the U-matrix.

Width and height are chosen by the user; number_features is just the number of features (columns or fields) in your data.

Intuitively this is just creating a 2D grid of dimensions w * h (e.g., if w = 10 and h = 10 then your lattice has 100 cells), then into each cell, placing a random 1D array (sometimes called "reference tuples") whose size and values are constrained by your data.

The reference tuples are also referred to as weights.

How is the U-matrix rendered?

In my example below, the data is comprised of rgb tuples, so the reference tuples have length of three and each of the three values must lie between 0 and 255).

It's with this 3D array ("lattice") that you begin the main iterative loop The algorithm iteratively positions each data point so that it is closest to others similar to it.

If you plot it over time (iteration number) then you can visualize cluster formation.

The plotting tool i use for this is the brilliant Python library, Matplotlib, which plots the lattice directly, just by passing it into the imshow function.

Below are eight snapshots of the progress of a SOM algorithm, from initialization to 700 iterations. The newly initialized (iteration_count = 0) lattice is rendered in the top left panel; the result from the final iteration, in the bottom right panel.

Alternatively, you can use a lower-level imaging library (in Python, e.g., PIL) and transfer the reference tuples onto the 2D grid, one at a time:

for y in range(h):
    for x in range(w):
        img.putpixel( (x, y), (
            SOM.Umatrix[y, x, 0], 
            SOM.Umatrix[y, x, 1], 
            SOM.Umatrix[y, x, 2]) 
        )

Here img is an instance of PIL's Image class. Here the image is created by iterating over the grid one pixel at a time; for each pixel, putpixel is called on img three times, the three calls of course corresponding to the three values in an rgb tuple.

Image1Image2

like image 20
doug Avatar answered Jan 02 '23 18:01

doug