wolffd@0
|
1 function unit_coord=som_vis_coords(lattice, msize)
|
wolffd@0
|
2
|
wolffd@0
|
3 %SOM_VIS_COORDS Unit coordinates used in visualizations.
|
wolffd@0
|
4 %
|
wolffd@0
|
5 % Co = som_vis_coords(lattice, msize)
|
wolffd@0
|
6 %
|
wolffd@0
|
7 % Co = som_vis_coords('hexa',[10 7])
|
wolffd@0
|
8 % Co = som_vis_coords('rectU',[10 7])
|
wolffd@0
|
9 %
|
wolffd@0
|
10 % Input and output arguments:
|
wolffd@0
|
11 % lattice (string) 'hexa', 'rect', 'hexaU' or 'rectU'
|
wolffd@0
|
12 % msize (vector) grid size in a 1x2 vector
|
wolffd@0
|
13 %
|
wolffd@0
|
14 % Co (matrix) Mx2 matrix of unit coordinates, where
|
wolffd@0
|
15 % M=prod(msize) for 'hexa' and 'rect', and
|
wolffd@0
|
16 % M=(2*msize(1)-1)*(2*msize(2)-1) for 'hexaU' and 'rectU'
|
wolffd@0
|
17 %
|
wolffd@0
|
18 % This function calculates the coordinates of map units on a 'sheet'
|
wolffd@0
|
19 % shaped map with either 'hexa' or 'rect' lattice as used in the
|
wolffd@0
|
20 % visualizations. Note that this slightly different from the
|
wolffd@0
|
21 % coordinates provided by SOM_UNIT_COORDS function.
|
wolffd@0
|
22 %
|
wolffd@0
|
23 % 'rectU' and 'hexaU' gives the coordinates of both units and the
|
wolffd@0
|
24 % connections for u-matrix visualizations.
|
wolffd@0
|
25 %
|
wolffd@0
|
26 % For more help, try 'type som_vis_coords' or check out online documentation.
|
wolffd@0
|
27 % See also SOM_UNIT_COORDS, SOM_UMAT, SOM_CPLANE, SOM_GRID.
|
wolffd@0
|
28
|
wolffd@0
|
29 %%%%%%%%% DETAILED DESCRIPTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
wolffd@0
|
30 %
|
wolffd@0
|
31 % PURPOSE
|
wolffd@0
|
32 %
|
wolffd@0
|
33 % Returns coordinates of the map units for map visualization
|
wolffd@0
|
34 %
|
wolffd@0
|
35 % SYNTAX
|
wolffd@0
|
36 %
|
wolffd@0
|
37 % Co = som_vis_coords(lattice, msize)
|
wolffd@0
|
38 %
|
wolffd@0
|
39 % DESCRIPTION
|
wolffd@0
|
40 %
|
wolffd@0
|
41 % This function calculates the coordinates of map units in 'hexa' and
|
wolffd@0
|
42 % 'rect' lattices in 'sheet' shaped map for visualization purposes. It
|
wolffd@0
|
43 % differs from SOM_UNIT_COORDS in the sense that hexagonal lattice is
|
wolffd@0
|
44 % calculated in a "wrong" way in order to get integer coordinates for
|
wolffd@0
|
45 % the units. Another difference is that it may be used to calculate
|
wolffd@0
|
46 % the coordinates of units _and_ the center points of the lines
|
wolffd@0
|
47 % connecting them (edges) by using 'hexaU' or 'rectU' for lattice.
|
wolffd@0
|
48 % This property may be used for drawing u-matrices.
|
wolffd@0
|
49 %
|
wolffd@0
|
50 % The unit number 1 is set to (ij) coordinates (1,1)+shift
|
wolffd@0
|
51 % 2 (2,1)+shift
|
wolffd@0
|
52 %
|
wolffd@0
|
53 % ... columnwise
|
wolffd@0
|
54 %
|
wolffd@0
|
55 % n-1th (n1-1,n2)+shift
|
wolffd@0
|
56 % nth (n1,n2)+shift
|
wolffd@0
|
57 %
|
wolffd@0
|
58 % where grid size = [n1 n2] and shift is zero, except for
|
wolffd@0
|
59 % the even lines of 'hexa' lattice, for which it is +0.5.
|
wolffd@0
|
60 %
|
wolffd@0
|
61 % For 'rectU' and 'hexaU' the unit coordinates are the same and the
|
wolffd@0
|
62 % coordinates for connections are set according to these. In this case
|
wolffd@0
|
63 % the ordering of the coordinates is the following:
|
wolffd@0
|
64 % let
|
wolffd@0
|
65 % U = som_umat(sMap); U=U(:); % make U a column vector
|
wolffd@0
|
66 % Uc = som_vis_coords(sMap.topol.lattice, sMap.topol.msize);
|
wolffd@0
|
67 % now the kth row of matrix Uc, i.e. Uc(k,:), contains the coordinates
|
wolffd@0
|
68 % for value U(k).
|
wolffd@0
|
69 %
|
wolffd@0
|
70 % REQUIRED INPUT ARGUMENTS
|
wolffd@0
|
71 %
|
wolffd@0
|
72 % lattice (string) The local topology of the units:
|
wolffd@0
|
73 % 'hexa', 'rect', 'hexaU' or 'rectU'
|
wolffd@0
|
74 % msize (vector) size 1x2, defining the map grid size.
|
wolffd@0
|
75 % Notice that only 2-dimensional grids
|
wolffd@0
|
76 % are allowed.
|
wolffd@0
|
77 %
|
wolffd@0
|
78 % OUTPUT ARGUMENTS
|
wolffd@0
|
79 %
|
wolffd@0
|
80 % Co (matrix) size Mx2, giving the coordinates for each unit.
|
wolffd@0
|
81 % M=prod(msize) for 'hexa' and 'rect', and
|
wolffd@0
|
82 % M=(2*msize(1)-1)*(2*msize(2)-1) for 'hexaU' and 'rectU'
|
wolffd@0
|
83 %
|
wolffd@0
|
84 % FEATURES
|
wolffd@0
|
85 %
|
wolffd@0
|
86 % Only 'sheet' shaped maps are considered. If coordinates for 'toroid'
|
wolffd@0
|
87 % or 'cyl' topologies are required, you must use SOM_UNIT_COORDS
|
wolffd@0
|
88 % instead.
|
wolffd@0
|
89 %
|
wolffd@0
|
90 % EXAMPLES
|
wolffd@0
|
91 %
|
wolffd@0
|
92 % Though this is mainly a subroutine for visualizations it may be
|
wolffd@0
|
93 % used, e.g., in the following manner:
|
wolffd@0
|
94 %
|
wolffd@0
|
95 % % This makes a hexagonal lattice, where the units are rectangular
|
wolffd@0
|
96 % % instead of hexagons.
|
wolffd@0
|
97 % som_cplane('rect',som_vis_coords('hexa',[10 7]),'none');
|
wolffd@0
|
98 %
|
wolffd@0
|
99 % % Let's make a map and calculate a u-matrix:
|
wolffd@0
|
100 % sM=som_make(data,'msize',[10 7],'lattice','hexa');
|
wolffd@0
|
101 % u=som_umat(sM); u=u(:);
|
wolffd@0
|
102 % % Now, these produce equivalent results:
|
wolffd@0
|
103 % som_cplane('hexaU',[10 7],u);
|
wolffd@0
|
104 % som_cplane(vis_patch('hexa')/2,som_vis_coords('hexaU',[10 7]),u);
|
wolffd@0
|
105 %
|
wolffd@0
|
106 % SEE ALSO
|
wolffd@0
|
107 %
|
wolffd@0
|
108 % som_grid Visualization of a SOM grid
|
wolffd@0
|
109 % som_cplane Visualize a 2D component plane, u-matrix or color plane
|
wolffd@0
|
110 % som_barplane Visualize the map prototype vectors as bar diagrams
|
wolffd@0
|
111 % som_plotplane Visualize the map prototype vectors as line graphs
|
wolffd@0
|
112 % som_pieplane Visualize the map prototype vectors as pie charts
|
wolffd@0
|
113 % som_unit_coords Locations of units on the SOM grid
|
wolffd@0
|
114
|
wolffd@0
|
115 % Copyright (c) 1999-2000 by the SOM toolbox programming team.
|
wolffd@0
|
116 % http://www.cis.hut.fi/projects/somtoolbox/
|
wolffd@0
|
117
|
wolffd@0
|
118 % Version 2.0beta Johan 201099 juuso 261199
|
wolffd@0
|
119
|
wolffd@0
|
120 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
wolffd@0
|
121
|
wolffd@0
|
122 if ~vis_valuetype(msize,{'1x2'}),
|
wolffd@0
|
123 error('msize must be a 1x2 vector.')
|
wolffd@0
|
124 end
|
wolffd@0
|
125
|
wolffd@0
|
126 if vis_valuetype(lattice,{'string'})
|
wolffd@0
|
127 switch lattice
|
wolffd@0
|
128 case {'hexa', 'rect'}
|
wolffd@0
|
129 munits=prod(msize);
|
wolffd@0
|
130 unit_coord(:,1)=reshape(repmat([1:msize(2)],msize(1),1),1,munits)';
|
wolffd@0
|
131 unit_coord(:,2)=repmat([1:msize(1)]',msize(2),1);
|
wolffd@0
|
132 if strcmp(lattice,'hexa')
|
wolffd@0
|
133 % Move even rows by .5
|
wolffd@0
|
134 d=rem(unit_coord(:,2),2) == 0;
|
wolffd@0
|
135 unit_coord(d,1)=unit_coord(d,1)+.5;
|
wolffd@0
|
136 end
|
wolffd@0
|
137 case {'hexaU','rectU'}
|
wolffd@0
|
138 msize=2*msize-1; munits=prod(msize);
|
wolffd@0
|
139 unit_coord(:,1)=reshape(repmat([1:msize(2)],msize(1),1),1,munits)';
|
wolffd@0
|
140 unit_coord(:,2)=repmat([1:msize(1)]',msize(2),1);
|
wolffd@0
|
141 if strcmp(lattice,'hexaU')
|
wolffd@0
|
142 d=rem(unit_coord(:,2),2) == 0;
|
wolffd@0
|
143 unit_coord(d,1)=unit_coord(d,1)+.5;
|
wolffd@0
|
144 d=rem(unit_coord(:,2)+1,4) == 0;
|
wolffd@0
|
145 unit_coord(d,1)=unit_coord(d,1)+1;
|
wolffd@0
|
146 end
|
wolffd@0
|
147 unit_coord=unit_coord/2+.5;
|
wolffd@0
|
148 otherwise
|
wolffd@0
|
149 error([ 'Unknown lattice ''' lattice '''.']);
|
wolffd@0
|
150 end
|
wolffd@0
|
151 else
|
wolffd@0
|
152 error('Lattice must be a string.');
|
wolffd@0
|
153 end
|