annotate toolboxes/MIRtoolbox1.3.2/somtoolbox/som_vis_coords.m @ 0:cc4b1211e677 tip

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