comparison toolboxes/MIRtoolbox1.3.2/somtoolbox/som_vis_coords.m @ 0:e9a9cd732c1e tip

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