annotate toolboxes/MIRtoolbox1.3.2/somtoolbox/som_plotplane.m @ 0:e9a9cd732c1e tip

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