annotate toolboxes/MIRtoolbox1.3.2/somtoolbox/som_plotplane.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 h=som_plotplane(varargin)
Daniel@0 2
Daniel@0 3 %SOM_PLOTPLANE Visualize the map prototype vectors as line graphs
Daniel@0 4 %
Daniel@0 5 % h=som_plotplane(lattice, msize, data, [color], [scaling], [pos])
Daniel@0 6 % h=som_plotplane(topol, data, [color], [scaling], [pos])
Daniel@0 7 %
Daniel@0 8 % som_plotplane('hexa',[5 5], rand(25,4), jet(25))
Daniel@0 9 % som_plotplane(sM, sM.codebook)
Daniel@0 10 %
Daniel@0 11 % Input and output arguments ([]'s are optional)
Daniel@0 12 % lattice (string) grid 'hexa' or 'rect'
Daniel@0 13 % msize (vector) size 1x2, defines the grid size
Daniel@0 14 % (matrix) size Mx2, defines explicit coordinates: in
Daniel@0 15 % this case the first argument does not matter
Daniel@0 16 % topol (struct) map or topology struct
Daniel@0 17 % data (matrix) Mxd matrix, M=prod(msize)
Daniel@0 18 % [color] (matrix) size Mx3, gives an individual color for each graph
Daniel@0 19 % (string) ColorSpec gives the same color for each
Daniel@0 20 % graph, default is 'k' (black)
Daniel@0 21 % [scaling] (string) 'on' or 'off', default is 'on'
Daniel@0 22 % [pos] (vector) 1x2 vector that determines translation.
Daniel@0 23 % Default is no translation.
Daniel@0 24 %
Daniel@0 25 % h (vector) the object handles for the LINE objects
Daniel@0 26 %
Daniel@0 27 % If scaling is set on, the data will be linearly scaled in each
Daniel@0 28 % unit so that min and max values span from lower to upper edge
Daniel@0 29 % in each unit. If scaling is 'off', the proper scaling is left to
Daniel@0 30 % the user: values in range [-.5,.5] will be plotted within the limits of the
Daniel@0 31 % unit while values exceeding this range will be out of the unit.
Daniel@0 32 % Axis are set as in SOM_CPLANE.
Daniel@0 33 %
Daniel@0 34 % For more help, try 'type som_plotplane' or check out online documentation.
Daniel@0 35 % See also SOM_PLANE, SOM_PIEPLANE, SOM_BARPLANE
Daniel@0 36
Daniel@0 37 %%%%%%%%%%%%% DETAILED DESCRIPTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Daniel@0 38 %
Daniel@0 39 % som_plotplane
Daniel@0 40 %
Daniel@0 41 % PURPOSE
Daniel@0 42 %
Daniel@0 43 % Visualizes the map prototype vectors as line graph
Daniel@0 44 %
Daniel@0 45 % SYNTAX
Daniel@0 46 %
Daniel@0 47 % h = som_plotplane(topol, data)
Daniel@0 48 % h = som_plotplane(lattice, msize, data)
Daniel@0 49 % h = som_plotplane(..., color)
Daniel@0 50 % h = som_plotplane(..., color, scaling)
Daniel@0 51 % h = som_plotplane(..., color, scaling, pos)
Daniel@0 52 %
Daniel@0 53 % DESCRIPTION
Daniel@0 54 %
Daniel@0 55 % Visualizes the map prototype vectors as line graph
Daniel@0 56 %
Daniel@0 57 % KNOWN BUGS
Daniel@0 58 %
Daniel@0 59 % It is not possible to specify explicit coordinates for map
Daniel@0 60 % consistig of just one unit as then the msize is interpreted as
Daniel@0 61 % map size.
Daniel@0 62 %
Daniel@0 63 % FEATURES
Daniel@0 64 %
Daniel@0 65 % - the colors are fixed: changing colormap in the figure (see
Daniel@0 66 % COLORMAP) will not affect the coloring of the plots
Daniel@0 67 %
Daniel@0 68 % REQUIRED INPUT ARGUMENTS
Daniel@0 69 %
Daniel@0 70 % lattice The basic topology
Daniel@0 71 %
Daniel@0 72 % (string) 'hexa' or 'rect' positions the plots according to hexagonal or
Daniel@0 73 % rectangular map lattice.
Daniel@0 74 %
Daniel@0 75 % msize The size of the map grid
Daniel@0 76 %
Daniel@0 77 % (vector) [n1 n2] vector defines the map size (height n1 units, width n2
Daniel@0 78 % units, total M=n1 x n2 units). The units will be placed to their
Daniel@0 79 % topological locations in order to form a uniform hexagonal or
Daniel@0 80 % rectangular grid.
Daniel@0 81 % (matrix) Mx2 matrix defines arbitary coordinates for the M units.
Daniel@0 82 % In this case the argument 'lattice' has no effect.
Daniel@0 83 %
Daniel@0 84 % topol Topology of the map grid
Daniel@0 85 %
Daniel@0 86 % (struct) map or topology struct from which the topology is taken
Daniel@0 87 %
Daniel@0 88 % data The data to be visualized
Daniel@0 89 %
Daniel@0 90 % (matrix) Mxd matrix of data vectors.
Daniel@0 91 %
Daniel@0 92 % OPTIONAL INPUT ARGUMENTS
Daniel@0 93 %
Daniel@0 94 % If unspecified or given empty values ('' or []), default values
Daniel@0 95 % will be used for optional input arguments.
Daniel@0 96 %
Daniel@0 97 % color The color of the plots
Daniel@0 98 %
Daniel@0 99 % (string) Matlab's ColorSpec (see help plot) string gives the same color
Daniel@0 100 % for each line.
Daniel@0 101 %
Daniel@0 102 % (matrix) Mx3 matrix assigns an RGB color determined by the Nth row of
Daniel@0 103 % the matrix to the Nth plot.
Daniel@0 104 %
Daniel@0 105 % (vector) 1x3 RGB vector gives the same color for each line.
Daniel@0 106 %
Daniel@0 107 % scaling The data scaling mode
Daniel@0 108 %
Daniel@0 109 % (string) 'on or 'off': if scaling is set on, the data will be
Daniel@0 110 % linearly scaled in each unit so that min and max values span from
Daniel@0 111 % lower to upper edge in each unit. If scaling is 'off', the proper
Daniel@0 112 % scaling is left to the user: values in range [-.5,.5] will be plotted
Daniel@0 113 % within the limits of the unit while values exceeding this
Daniel@0 114 % range will be out of the unit.
Daniel@0 115 %
Daniel@0 116 % pos Position of the origin
Daniel@0 117 %
Daniel@0 118 % (vector) This is meant for drawing the plane in arbitary location in a
Daniel@0 119 % figure. Note the operation: if this argument is given, the
Daniel@0 120 % axis limits setting part in the routine is skipped and the limits
Daniel@0 121 % setting will be left to be done by MATLAB's
Daniel@0 122 % defaults. By default no translation is done.
Daniel@0 123 %
Daniel@0 124 % OUTPUT ARGUMENTS
Daniel@0 125 %
Daniel@0 126 % h (scalar) Handle to the created patch object
Daniel@0 127 %
Daniel@0 128 % OBJECT TAG
Daniel@0 129 %
Daniel@0 130 % Object property 'Tag' is set to 'planePlot'.
Daniel@0 131 %
Daniel@0 132 % EXAMPLES
Daniel@0 133 %
Daniel@0 134 % %%% Create the data and make a map
Daniel@0 135 %
Daniel@0 136 % data=rand(1000,20); map=som_make(data);
Daniel@0 137 %
Daniel@0 138 % %%% Create a 'gray' colormap that has 64 levels
Daniel@0 139 %
Daniel@0 140 % color_map=gray(64);
Daniel@0 141 %
Daniel@0 142 % %%% Draw plots using red color
Daniel@0 143 %
Daniel@0 144 % som_plotplane(map, map.codebook,'r');
Daniel@0 145 %
Daniel@0 146 % %%% Calculate hits on the map and calculate colors so that
Daniel@0 147 % black = min. number of hits and white = max. number of hits
Daniel@0 148 %
Daniel@0 149 % hit=som_hits(map,data); color=som_normcolor(hit(:),color_map);
Daniel@0 150 %
Daniel@0 151 % %%% Draw plots again. Now the gray level indicates the number of hits to
Daniel@0 152 % each node
Daniel@0 153 %
Daniel@0 154 % som_plotplane(map, map.codebook, color);
Daniel@0 155 %
Daniel@0 156 % SEE ALSO
Daniel@0 157 %
Daniel@0 158 % som_cplane Visualize a 2D component plane, u-matrix or color plane
Daniel@0 159 % som_barplane Visualize the map prototype vectors as bar diagrams.
Daniel@0 160 % som_pieplane Visualize the map prototype vectors as pie charts
Daniel@0 161
Daniel@0 162 % Copyright (c) 1999-2000 by the SOM toolbox programming team.
Daniel@0 163 % http://www.cis.hut.fi/projects/somtoolbox/
Daniel@0 164
Daniel@0 165 % Version 2.0beta Johan 160799 juuso 151199 070600
Daniel@0 166
Daniel@0 167 %%% Init & Check arguments %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Daniel@0 168
Daniel@0 169 [nargin, lattice, msize, data, color, scaling, pos] = vis_planeGetArgs(varargin{:});
Daniel@0 170 error(nargchk(3, 5, nargin)); % check no. of input args is correct
Daniel@0 171
Daniel@0 172 s=0.8; % size of plot
Daniel@0 173
Daniel@0 174 if nargin < 6 | isempty(pos)
Daniel@0 175 pos=NaN;
Daniel@0 176 end
Daniel@0 177
Daniel@0 178 if nargin < 5 | isempty(scaling)
Daniel@0 179 scaling='on';
Daniel@0 180 elseif ~vis_valuetype(scaling,{'string'}) | ...
Daniel@0 181 ~any(strcmp(scaling,{'on','off'})),
Daniel@0 182 error('Scaling should be string ''on'' or ''off''.');
Daniel@0 183 end
Daniel@0 184
Daniel@0 185 l=size(data,2);
Daniel@0 186
Daniel@0 187 if ~isnumeric(msize) | ndims(msize) ~= 2 | size(msize,2)~=2,
Daniel@0 188 error('msize has to be 1x2 grid size vector or a Nx2 coordinate matrix.');
Daniel@0 189 elseif size(msize,1) == 1,
Daniel@0 190 xdim=msize(2);
Daniel@0 191 ydim=msize(1);
Daniel@0 192 N=xdim*ydim;
Daniel@0 193 y=repmat(repmat([1:ydim]',xdim,1),1,l);
Daniel@0 194 x=reshape(repmat([1:xdim],ydim*l,1),l,N)';
Daniel@0 195 else
Daniel@0 196 x=repmat(msize(:,1),1,l);y=repmat(msize(:,2),1,l);
Daniel@0 197 N=size(msize,1);
Daniel@0 198 lattice='rect';
Daniel@0 199 if isnan(pos),
Daniel@0 200 pos=[0 0];
Daniel@0 201 end
Daniel@0 202 end
Daniel@0 203
Daniel@0 204 switch lattice
Daniel@0 205 case {'hexa', 'rect'}
Daniel@0 206 ;
Daniel@0 207 otherwise
Daniel@0 208 error(['Lattice' lattice ' not implemented!']);
Daniel@0 209 end
Daniel@0 210
Daniel@0 211 if ~isnumeric(data) | size(data,1) ~= N
Daniel@0 212 error('Data matrix is invalid or has wrong size!');
Daniel@0 213 end
Daniel@0 214
Daniel@0 215 if nargin < 4 | isempty(color),
Daniel@0 216 color='k';
Daniel@0 217 elseif vis_valuetype(color, {'colorstyle',[N 3]}),
Daniel@0 218 if ischar(color) & strcmp(color,'none'),
Daniel@0 219 error('Colorstyle ''none'' not allowed in som_plotplane.');
Daniel@0 220 end
Daniel@0 221 elseif vis_valuetype(color,{'1x3rgb'})
Daniel@0 222 ;
Daniel@0 223 elseif ~vis_valuetype(color,{'nx3rgb',[N 3]},'all'),
Daniel@0 224 error('The color matrix has wrong size or contains invalid RGB values or colorstyle.');
Daniel@0 225 end
Daniel@0 226
Daniel@0 227 [linesx, linesy]=vis_line(data,scaling);
Daniel@0 228
Daniel@0 229 %%%% Action %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Daniel@0 230
Daniel@0 231 % Making the lattice.
Daniel@0 232 % Command view([0 90]) shows the map in 2D properly oriented
Daniel@0 233
Daniel@0 234 switch lattice
Daniel@0 235 case 'hexa'
Daniel@0 236 t=find(rem(y(:,1),2)); % move even rows by .5
Daniel@0 237 x(t,:)=x(t,:)-.5;
Daniel@0 238 x=(x./s+linesx).*s+.5; y=(y./s+linesy).*s; % scale with s
Daniel@0 239 case 'rect'
Daniel@0 240 x=(x./s+linesx).*s; y=(y./s+linesy).*s; % scale with s
Daniel@0 241 end
Daniel@0 242
Daniel@0 243 %% Draw the map! ...
Daniel@0 244
Daniel@0 245 h_=plot(x',y');
Daniel@0 246
Daniel@0 247 if size(color,1) == 1
Daniel@0 248 set(h_,'Color',color);
Daniel@0 249 else
Daniel@0 250 for i=1:N,
Daniel@0 251 set(h_(i,:),'Color',color(i,:));
Daniel@0 252 end
Daniel@0 253 end
Daniel@0 254
Daniel@0 255 if ~isnan(pos)
Daniel@0 256 x=x+pos(1);y=y+pos(2); % move upper left corner
Daniel@0 257 end % to pos(1),pos(2)
Daniel@0 258
Daniel@0 259 %% Set axes properties
Daniel@0 260
Daniel@0 261 ax=gca;
Daniel@0 262 vis_PlaneAxisProperties(ax, lattice, msize, pos);
Daniel@0 263
Daniel@0 264 %%% Build output %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Daniel@0 265
Daniel@0 266 set(h_,'Tag','planePlot'); % tag the lineobject
Daniel@0 267
Daniel@0 268 if nargout>0, h=h_; end % Set h only,
Daniel@0 269 % if there really is output
Daniel@0 270
Daniel@0 271 %% Subfuntion %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Daniel@0 272
Daniel@0 273 function [x,y]=vis_line(data, scaling)
Daniel@0 274
Daniel@0 275 s=size(data);
Daniel@0 276 % normalization between [0,1] if scaling is on
Daniel@0 277 if strcmp(scaling,'on')
Daniel@0 278 mn=repmat(min(data,[],2),1,s(2));
Daniel@0 279 mx=repmat(max(data,[],2),1,s(2));
Daniel@0 280 y=-((data-mn)./(mx-mn))+.5;
Daniel@0 281 else % -sign is beacuse we do axis ij
Daniel@0 282 y=-data;
Daniel@0 283 end
Daniel@0 284
Daniel@0 285 x=repmat(linspace(-.5, .5, size(data,2)), size(data,1),1);