wolffd@0: function unit_coord=som_vis_coords(lattice, msize) wolffd@0: wolffd@0: %SOM_VIS_COORDS Unit coordinates used in visualizations. wolffd@0: % wolffd@0: % Co = som_vis_coords(lattice, msize) wolffd@0: % wolffd@0: % Co = som_vis_coords('hexa',[10 7]) wolffd@0: % Co = som_vis_coords('rectU',[10 7]) wolffd@0: % wolffd@0: % Input and output arguments: wolffd@0: % lattice (string) 'hexa', 'rect', 'hexaU' or 'rectU' wolffd@0: % msize (vector) grid size in a 1x2 vector wolffd@0: % wolffd@0: % Co (matrix) Mx2 matrix of unit coordinates, where wolffd@0: % M=prod(msize) for 'hexa' and 'rect', and wolffd@0: % M=(2*msize(1)-1)*(2*msize(2)-1) for 'hexaU' and 'rectU' wolffd@0: % wolffd@0: % This function calculates the coordinates of map units on a 'sheet' wolffd@0: % shaped map with either 'hexa' or 'rect' lattice as used in the wolffd@0: % visualizations. Note that this slightly different from the wolffd@0: % coordinates provided by SOM_UNIT_COORDS function. wolffd@0: % wolffd@0: % 'rectU' and 'hexaU' gives the coordinates of both units and the wolffd@0: % connections for u-matrix visualizations. wolffd@0: % wolffd@0: % For more help, try 'type som_vis_coords' or check out online documentation. wolffd@0: % See also SOM_UNIT_COORDS, SOM_UMAT, SOM_CPLANE, SOM_GRID. wolffd@0: wolffd@0: %%%%%%%%% DETAILED DESCRIPTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% wolffd@0: % wolffd@0: % PURPOSE wolffd@0: % wolffd@0: % Returns coordinates of the map units for map visualization wolffd@0: % wolffd@0: % SYNTAX wolffd@0: % wolffd@0: % Co = som_vis_coords(lattice, msize) wolffd@0: % wolffd@0: % DESCRIPTION wolffd@0: % wolffd@0: % This function calculates the coordinates of map units in 'hexa' and wolffd@0: % 'rect' lattices in 'sheet' shaped map for visualization purposes. It wolffd@0: % differs from SOM_UNIT_COORDS in the sense that hexagonal lattice is wolffd@0: % calculated in a "wrong" way in order to get integer coordinates for wolffd@0: % the units. Another difference is that it may be used to calculate wolffd@0: % the coordinates of units _and_ the center points of the lines wolffd@0: % connecting them (edges) by using 'hexaU' or 'rectU' for lattice. wolffd@0: % This property may be used for drawing u-matrices. wolffd@0: % wolffd@0: % The unit number 1 is set to (ij) coordinates (1,1)+shift wolffd@0: % 2 (2,1)+shift wolffd@0: % wolffd@0: % ... columnwise wolffd@0: % wolffd@0: % n-1th (n1-1,n2)+shift wolffd@0: % nth (n1,n2)+shift wolffd@0: % wolffd@0: % where grid size = [n1 n2] and shift is zero, except for wolffd@0: % the even lines of 'hexa' lattice, for which it is +0.5. wolffd@0: % wolffd@0: % For 'rectU' and 'hexaU' the unit coordinates are the same and the wolffd@0: % coordinates for connections are set according to these. In this case wolffd@0: % the ordering of the coordinates is the following: wolffd@0: % let wolffd@0: % U = som_umat(sMap); U=U(:); % make U a column vector wolffd@0: % Uc = som_vis_coords(sMap.topol.lattice, sMap.topol.msize); wolffd@0: % now the kth row of matrix Uc, i.e. Uc(k,:), contains the coordinates wolffd@0: % for value U(k). wolffd@0: % wolffd@0: % REQUIRED INPUT ARGUMENTS wolffd@0: % wolffd@0: % lattice (string) The local topology of the units: wolffd@0: % 'hexa', 'rect', 'hexaU' or 'rectU' wolffd@0: % msize (vector) size 1x2, defining the map grid size. wolffd@0: % Notice that only 2-dimensional grids wolffd@0: % are allowed. wolffd@0: % wolffd@0: % OUTPUT ARGUMENTS wolffd@0: % wolffd@0: % Co (matrix) size Mx2, giving the coordinates for each unit. wolffd@0: % M=prod(msize) for 'hexa' and 'rect', and wolffd@0: % M=(2*msize(1)-1)*(2*msize(2)-1) for 'hexaU' and 'rectU' wolffd@0: % wolffd@0: % FEATURES wolffd@0: % wolffd@0: % Only 'sheet' shaped maps are considered. If coordinates for 'toroid' wolffd@0: % or 'cyl' topologies are required, you must use SOM_UNIT_COORDS wolffd@0: % instead. wolffd@0: % wolffd@0: % EXAMPLES wolffd@0: % wolffd@0: % Though this is mainly a subroutine for visualizations it may be wolffd@0: % used, e.g., in the following manner: wolffd@0: % wolffd@0: % % This makes a hexagonal lattice, where the units are rectangular wolffd@0: % % instead of hexagons. wolffd@0: % som_cplane('rect',som_vis_coords('hexa',[10 7]),'none'); wolffd@0: % wolffd@0: % % Let's make a map and calculate a u-matrix: wolffd@0: % sM=som_make(data,'msize',[10 7],'lattice','hexa'); wolffd@0: % u=som_umat(sM); u=u(:); wolffd@0: % % Now, these produce equivalent results: wolffd@0: % som_cplane('hexaU',[10 7],u); wolffd@0: % som_cplane(vis_patch('hexa')/2,som_vis_coords('hexaU',[10 7]),u); wolffd@0: % wolffd@0: % SEE ALSO wolffd@0: % wolffd@0: % som_grid Visualization of a SOM grid wolffd@0: % som_cplane Visualize a 2D component plane, u-matrix or color plane wolffd@0: % som_barplane Visualize the map prototype vectors as bar diagrams wolffd@0: % som_plotplane Visualize the map prototype vectors as line graphs wolffd@0: % som_pieplane Visualize the map prototype vectors as pie charts wolffd@0: % som_unit_coords Locations of units on the SOM grid wolffd@0: wolffd@0: % Copyright (c) 1999-2000 by the SOM toolbox programming team. wolffd@0: % http://www.cis.hut.fi/projects/somtoolbox/ wolffd@0: wolffd@0: % Version 2.0beta Johan 201099 juuso 261199 wolffd@0: wolffd@0: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% wolffd@0: wolffd@0: if ~vis_valuetype(msize,{'1x2'}), wolffd@0: error('msize must be a 1x2 vector.') wolffd@0: end wolffd@0: wolffd@0: if vis_valuetype(lattice,{'string'}) wolffd@0: switch lattice wolffd@0: case {'hexa', 'rect'} wolffd@0: munits=prod(msize); wolffd@0: unit_coord(:,1)=reshape(repmat([1:msize(2)],msize(1),1),1,munits)'; wolffd@0: unit_coord(:,2)=repmat([1:msize(1)]',msize(2),1); wolffd@0: if strcmp(lattice,'hexa') wolffd@0: % Move even rows by .5 wolffd@0: d=rem(unit_coord(:,2),2) == 0; wolffd@0: unit_coord(d,1)=unit_coord(d,1)+.5; wolffd@0: end wolffd@0: case {'hexaU','rectU'} wolffd@0: msize=2*msize-1; munits=prod(msize); wolffd@0: unit_coord(:,1)=reshape(repmat([1:msize(2)],msize(1),1),1,munits)'; wolffd@0: unit_coord(:,2)=repmat([1:msize(1)]',msize(2),1); wolffd@0: if strcmp(lattice,'hexaU') wolffd@0: d=rem(unit_coord(:,2),2) == 0; wolffd@0: unit_coord(d,1)=unit_coord(d,1)+.5; wolffd@0: d=rem(unit_coord(:,2)+1,4) == 0; wolffd@0: unit_coord(d,1)=unit_coord(d,1)+1; wolffd@0: end wolffd@0: unit_coord=unit_coord/2+.5; wolffd@0: otherwise wolffd@0: error([ 'Unknown lattice ''' lattice '''.']); wolffd@0: end wolffd@0: else wolffd@0: error('Lattice must be a string.'); wolffd@0: end