SOM Toolbox Online documentation http://www.cis.hut.fi/projects/somtoolbox/

som_grid

Purpose

  To visualize the SOM grid in various ways 

Syntax

Description

 The SOM can be defined as a set of units (neurons) and their
 topological relations.  This function is used to visualize these in
 various ways. The units may be drawn using different markers and
 colors, in different sizes and in different locations in 2D or
 3D. However the topological neighborhood is limited to be
 2-dimensional. The connections between these units may be drawn using
 lines having different thicknesses and colors. Labeling text may be
 plotted on the units. It is possible also to draw a surface between
 the units. The surface coloring is either indexed (one value per
 unit) or fixed RGB (a 1x3 RGB triple per unit).

Required input arguments

 Note: M is the number of map units.

 The first (or first two) argument may have various different types of values

   1. sGrid   (struct) som_grid struct (the output of this function)

     The struct initiates the visualization. The argID-value -pairs
     are used to alter the initiation.

   Following argument types may be used to give the topology for the grid

   2. sTopol  (struct) som_topol struct 
   3. sMap    (struct) som_map struct (only topology matters)
   4. {lattice, msize} or {lattice, msize, sheet} (cell array) 
       - lattice must be 'hexa' or 'rect'
       - msize must be a 1x2 vector
       - shape (if specified) must be string 'sheet', 'cyl' or 'toroid'
         If shape is not given it is 'sheet' by default.
   5. lattice (string or matrix) AND msize (1x2 vector) as two separate arguments
       - lattice may be string 'rect' or 'hexa' or a connection matrix
         (see SOM_CONNECTION) to define a free topology. This connection
         matrix is of size MxM and its element i,j (i

Optional input arguments

  Note: M is the number of map units.

  Here is a list of the valid arguments IDs and the associated
  values (identifiers are case insensitive):

  'Coord'     Unit coordinates
              This defines the coordinates of the units. Default: the
              topological coordinates (calculated as in function
              SOM_VIS_COORDS and SOM_CPLANE). If the topology is free
              (lattice is a connection matrix) this argument is obligatory!
     (matrix) size Mx2 of 2D coordinates for each unit
     (matrix) size Mx3 of 3D coordinates for each unit

 'Marker'       Unit markers, default is 'o'.
     (string) 'o','+','x','*','v','^','<','>','h','s','d', 'p','.', or 'none'
              give the same marker for each unit. 
     (cell array) of size Mx1 of previous strings gives individual 
              markers for each unit.

 'MarkerSize'   Size (pt) of unit markers, default is 6 (pt).
     (scalar) gives the same size for every unit.  
     (matrix) Mx1 gives an individual size for each unit marker.  

  'MarkerColor' Unit marker colors, default is 'k'
     (ColorSpec) gives the same color each unit. 
     (matrix) Mx3 of RGB triples gives individual color for each unit
              Note that indexed coloring - like in SOM_CPLANE - is
              not possible. If indexed coloring is needed, you can
              use SOM_NORMCOLOR to calculate RGB colors that
              emulate indexed coloring. However, the colors for the
              units are fixed, so changing colormap will not
              change the colors.

  'Line'        Line type, default is '-'.
     (string) '-',':','--' or '-.' or 'none'. Only one linetype in
              grid is allowed.  

  'LineWidth'   Width of the topological connection lines (edges)  
     (scalar) gives the same width for each line. Default is 0.5.
     (matrix) MxM sparse (or full) matrix gives individual width for 
              each connection. The element (i,j), i= i are ignored in
              order to avoid ambiguous situations if the matrix would be 
              non-symmetric. The "connections to oneself" is not drawn. 

              Line width zero is valid and causes the line to disappear.

  'LineColor'   Color of connection lines, default is [0.9 0.9 0.9].
     (ColorSpec) gives the same color for each line
     (matrix) MxMx3 matrix of RGB triples gives individual width for 
              each connection. The element (i,j,:), i= i are ignored in order to avoid ambiguous situations 
              if the matrix was non-symmetric. The "connections to oneself"
              is not drawn. 


  'Label'       Labels for units, default is [].
     (empty)  [] means no labels.
     (char array) of size Mx1. Element (i,:) has the label for unit i.     
     (cell array) of size MxL consisting of sets of labels. Element {i,:} 
              contains the labeling for unit i. 
               In case of multiple labels, the labels for one unit are shown 
               in one column centered at that unit.

   'LabelSize'   Text size of labels (points), default is 10.
     (scalar) Default is 10.

   'LabelColor'  Color of labels, default is 'c' (cyan).
     (ColorSpec) gives the same color for each label string 'xor'
                 sets the colors automatically so that they differ
                 from the background (using Matlab's built-in xor-color feature.)

  'Surf'         Surface between nodes, default is [].
     (empty)  [] gives no surface
     (vector) Mx1 gives an indexed interpolated color surface between 
              units using the actual colormap.
     (matrix) Mx3 matrix of RGB triples gives a interpolated color surface 
              between units using fixed RGB colors.

              Note that the interpolation is done using Matlab's built-in
              color interpolation for SURF objects.

Output arguments

  sGrid    (struct) with fields S.msize, S.shape, S.lattice, S.coord, S.marker, 
                    S.markersize, S.markercolor, S.line, S.linewidth, S.linecolor,
                    S.surf, S.label, S.labelsize, S.labelcolor

  m        (matrix) handels to LINE objects (unit markers) 

  l        (matrix) handles to LINE objects (lines connecting the units)

  t        (matrix) handles to TEXT objects (labels)

  s        (scalar) handle  to SURF object  (surface between units)

Examples

 % Make map of size 15x10 on random data:

    map=som_make(rand(1000,4),'msize',[15 10], 'lattice', 'hexa');

 % Draw the grid using two frist varable values as coordinates
 % and store the sGrid struct in varable S:

    S=som_grid(map, 'coord', map.codebook(:,[1 2]))

 %Define some things: 
 %
 % Create a cell array of size 150x1 that divides map in to two label classes
 % 'circles' and 'squares'

    L(1:75,1)='o'; L(76:150,1)='s'; L = cellstr(L);

 % Create a coloring according to the 3rd variable according to current
 % colormap: 

    C = som_normcolor(map.codebook(:,3));

 % Change the visualization: use black lines, unit markers in M and unit
 % color in C, and set unit size to 10:

    S=som_grid(S, 'linecolor', 'k', 'marker', L, 'MarkerColor',C, ...
     'MarkerSize', 10);

 % Do a new visualization, use indexed color surface calcualted from the
 % first variable, coordinates according to the lattice (default) but 
 % no markers nor lines:

    S=som_grid(map,'line','none','marker','none','surf',map.codebook(:,1));

 % Set coordinates according to three last varables

    som_grid(S,'coord',map.codebook(:,2:4));

 % Create a random connection matrix R1 and the usual hexagonal
 % neighborhood connection matrix R2: 

    R1=sparse(rand(150,150)>0.9); 
    R2=som_connection(map);

 % Show these connections. Note that coordinates _must_ now be given
 % explicitly: we form default topological coordinates using
 % som_unit_coords.

    som_grid(R1,map.topol.msize,'coord',som_unit_coords(map));
    som_grid(R2,map.topol.msize,'coord',som_unit_coords(map));

 % Show connections (R1 AND R2)
    som_grid(R2.*R2,map.topol.msize,'coord',som_unit_coords(map));

Object tags

  No tags are set.

See also

som_show The basic map visualization routine
som_cplane The basic component plane visualization
som_connection The basic topological connections
scatter Scatter plots
scatter3 3-dimensional scatter plots