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