annotate toolboxes/MIRtoolbox1.3.2/somtoolbox/som_show.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_show(sMap, varargin)
wolffd@0 2
wolffd@0 3 % SOM_SHOW Basic SOM visualizations: component planes, u-matrix etc.
wolffd@0 4 %
wolffd@0 5 % h = som_show(sMap, ['argID', value, ...])
wolffd@0 6 %
wolffd@0 7 % som_show(sMap);
wolffd@0 8 % som_show(sMap,'bar','none');
wolffd@0 9 % som_show(sMap,'comp',[1:3],'umat','all');
wolffd@0 10 % som_show(sMap,'comp',[1 2],'umat',{[1 2],'1,2 only'},'comp',[3:6]);
wolffd@0 11 % som_show(sMap,'size',m,'bar','vert','edge','off');
wolffd@0 12 %
wolffd@0 13 % Input and output arguments ([]'s are optional):
wolffd@0 14 % sMap (struct) map struct
wolffd@0 15 % [argID, (string) Additional parameters are given as argID, value
wolffd@0 16 % value] (varies) pairs. See below for list of valid IDs and values.
wolffd@0 17 %
wolffd@0 18 % h (struct) struct with the following fields:
wolffd@0 19 % .plane (vector) handles to the axes objecets (subplots)
wolffd@0 20 % .colorbar (vector) handles to the colorbars. Colorbars for empty
wolffd@0 21 % grids & RGB color planes do not exist: the
wolffd@0 22 % value for them in the vector is -1.
wolffd@0 23 % .label (vector) handles to the axis labels
wolffd@0 24 %
wolffd@0 25 % Here are the valid argument IDs and corresponding values. M is
wolffd@0 26 % the number of map units
wolffd@0 27 % 'comp' Which component planes to draw, title is
wolffd@0 28 % the name of the component (from sMap.comp_names)
wolffd@0 29 % (vector) a vector of component indices
wolffd@0 30 % (string) 'all' (or '' or []) for all components
wolffd@0 31 % 'compi' as 'comp' but uses interpolated shading
wolffd@0 32 % 'umat' Show u-matrix calculated using specified
wolffd@0 33 % components
wolffd@0 34 % (vector) a vector of component indeces
wolffd@0 35 % (string) 'all' (or '' or []) to use all components
wolffd@0 36 % (cell) of form {v, str} uses v as the vector, and put
wolffd@0 37 % str as title instead of the default 'U-matrix'
wolffd@0 38 % 'umati' as 'umat' but uses interpolated shading of colors
wolffd@0 39 % 'empty' (string) Make an empty plane using given string as title
wolffd@0 40 % 'color' Set arbitrary unit colors explicitly
wolffd@0 41 % (matrix) size Mx1 or Mx3, Mx1 matrix uses indexed
wolffd@0 42 % coloring; Mx3 matrix (RGB triples as rows)
wolffd@0 43 % defines fixed unit colors
wolffd@0 44 % (cell) of from {color, str}. 'color' is the Mx1
wolffd@0 45 % or Mx3 RGB triple matrix and 'str' is title
wolffd@0 46 % string
wolffd@0 47 % 'colori' as 'color' but uses interpolated shading of colors
wolffd@0 48 % 'norm' (string) 'n' or 'd': Whether to show normalized 'n' or
wolffd@0 49 % denormalized 'd' data values on the
wolffd@0 50 % colorbar. By default denormalized values are used.
wolffd@0 51 % 'bar' (string) Colorbar direction: 'horiz', 'vert' (default)
wolffd@0 52 % or 'none'
wolffd@0 53 % 'size' size of the units
wolffd@0 54 % (scalar) same size for each unit, default is 1
wolffd@0 55 % (vector) size Mx1, individual size for each unit
wolffd@0 56 % 'edge' (string) Unit edges on component planes 'on'
wolffd@0 57 % (default) or 'off'
wolffd@0 58 % 'footnote' (string) Footnote string, sMap.name by default
wolffd@0 59 % 'colormap' (matrix) user defined colormap
wolffd@0 60 % 'subplots' (vector) size 1 x 2, the number of subplots in y- and
wolffd@0 61 % and x-directions (as in SUBPLOT command)
wolffd@0 62 %
wolffd@0 63 % If identifiers 'comp', 'compi', 'umat', 'umati', 'color', 'colori'
wolffd@0 64 % or 'empty' are not specified at all, e.g. som_show(sMap) or
wolffd@0 65 % som_show(sMap,'bar','none'), the U-matrix and all component planes
wolffd@0 66 % are shown.
wolffd@0 67 %
wolffd@0 68 % For more help, try 'type som_show' or check out online documentation.
wolffd@0 69 % See also SOM_SHOW_ADD, SOM_SHOW_CLEAR, SOM_UMAT, SOM_CPLANE, SOM_GRID.
wolffd@0 70
wolffd@0 71 %%%%%%%%%%%% DETAILED DESCRIPTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
wolffd@0 72 %
wolffd@0 73 % som_show
wolffd@0 74 %
wolffd@0 75 % PURPOSE
wolffd@0 76 %
wolffd@0 77 % Shows basic visualizations of SOM: component planes, unified distance
wolffd@0 78 % matrices as well as empty planes and fixed color planes.
wolffd@0 79 %
wolffd@0 80 % SYNTAX
wolffd@0 81 %
wolffd@0 82 % h = som_show(sMap)
wolffd@0 83 % h = som_show(sMap, 'argID', value, ...)
wolffd@0 84 %
wolffd@0 85 % DESCRIPTION
wolffd@0 86 %
wolffd@0 87 % This function is used for basic visualization of the SOM. Four
wolffd@0 88 % kinds of SOM planes can be shown:
wolffd@0 89 %
wolffd@0 90 % 1. U-matrix (see SOM_UMAT) which shows clustering structure of
wolffd@0 91 % the SOM. Either all or just part of the components can
wolffd@0 92 % be used in calculating the U-matrix.
wolffd@0 93 % 2. component planes: each component plane shows the values of
wolffd@0 94 % one variable in each map unit
wolffd@0 95 % 3. an empty plane which may be used as a base for, e.g., hit
wolffd@0 96 % histogram visualization or labeling (see SOM_SHOW_ADD)
wolffd@0 97 % 4. a fixed or indexed color representation for showing color coding or
wolffd@0 98 % clustering
wolffd@0 99 %
wolffd@0 100 % The component planes and u-matrices may have colorbars showing the
wolffd@0 101 % scale for the variable. The scale shows by default the values that
wolffd@0 102 % variables have in the map struct. It may be changed to show the
wolffd@0 103 % original data values (estimated by SOM_DENORMALIZE). In this case a
wolffd@0 104 % small 'd' appears below the colorbar. The orientation of these
wolffd@0 105 % colorbars may be changed, or they can be removed.
wolffd@0 106 %
wolffd@0 107 % By default the u-matrix - calculated using all variables - and all
wolffd@0 108 % component planes are shown. This is achieved by giving command
wolffd@0 109 % som_show(sMap) without any further arguments
wolffd@0 110 %
wolffd@0 111 % REQUIRED INPUT ARGUMENTS
wolffd@0 112 %
wolffd@0 113 % sMap (struct) Map to be shown. If only this argument is
wolffd@0 114 % specified, the function draws first the u-matrix
wolffd@0 115 % calculated using all the variables followed by all
wolffd@0 116 % the component planes.
wolffd@0 117 %
wolffd@0 118 % OPTIONAL INPUT ARGUMENTS
wolffd@0 119 %
wolffd@0 120 % (M is the number of map units)
wolffd@0 121 %
wolffd@0 122 % Optional arguments must be given as 'argID',value -pairs
wolffd@0 123 %
wolffd@0 124 % 'comp' Defines the variabels to be shown as component planes.
wolffd@0 125 % (vector) 1xN or Nx1 vector with integer positive numbers ranging
wolffd@0 126 % from 1 to the number of variables in the map codebook
wolffd@0 127 % (dim). This vector determines the variables to be show
wolffd@0 128 % as component planes and their order. Note that the same
wolffd@0 129 % component plane (the same variable index) is allowed to
wolffd@0 130 % occur several times.
wolffd@0 131 % (string) 'all' or '' or []. This uses all variables, that is, it's
wolffd@0 132 % the same that using value [1:dim] where dim is the
wolffd@0 133 % number of variables in the codebook.
wolffd@0 134 %
wolffd@0 135 % 'compi' Same as 'comp' but uses a Gouraud shaded color plane
wolffd@0 136 % (made using SOM_GRID function) instead of the cell-like
wolffd@0 137 % visualization of 'comp' (made using SOM_CPLANE). Note
wolffd@0 138 % that the color interpolation doesn't work strictly
wolffd@0 139 % correctly on 'hexa' grid, as it uses rectangular grid
wolffd@0 140 % (see SURF).
wolffd@0 141 %
wolffd@0 142 % 'umat' Show U-matrix: value defines the variables to be used
wolffd@0 143 % for calculating a u-matrix.
wolffd@0 144 % (vector) as in 'comps'. However, multiple occurences of the
wolffd@0 145 % same variable (same variable index) are ignored.
wolffd@0 146 % (string) 'all' or '' or []. This uses all variables, that is,
wolffd@0 147 % is the same as using value [1:dim] where dim is the
wolffd@0 148 % number of variables in the codebook.
wolffd@0 149 % (cell) of form {v, str} where v is a valid index vector for 'umat'
wolffd@0 150 % (see above) and str is a string that is used as a title
wolffd@0 151 % for the u-matrix instead of the default title
wolffd@0 152 % 'U-matrix'. This may be useful if several u-matrices
wolffd@0 153 % are shown in the same figure.
wolffd@0 154 %
wolffd@0 155 % 'umati' Same as 'umat' but uses shaded color plane (see 'compi').
wolffd@0 156 %
wolffd@0 157 % 'empty' Show an empty plane (patch edges only)
wolffd@0 158 % (string) value is used as title
wolffd@0 159 %
wolffd@0 160 % 'color' Define fixed RGB colors for the map units
wolffd@0 161 % (matrix) a Mx3 matrix of RGB triples as rows
wolffd@0 162 % (vector) a Mx1 vector of any values: sets indexed coloring using
wolffd@0 163 % the current colormap (as SURF does)
wolffd@0 164 % (matrix) a Mx3xN matrix of RGB triples as rows. This gives N
wolffd@0 165 % color planes.
wolffd@0 166 % (matrix) a Mx1xN matrix of any values: sets indexed coloring using
wolffd@0 167 % the current colormap (as SURF does). This gives N
wolffd@0 168 % color planes.
wolffd@0 169 % (cell) of form {rgb, str} where rgb is a Mx3 (xN) matrix of RGB
wolffd@0 170 % triples as rows and str is a string that is used as
wolffd@0 171 % title(s).
wolffd@0 172 % (cell) of form {v, str} where v is a Mx1(xN) matrix of values
wolffd@0 173 % and str is a string that is used as title(s).
wolffd@0 174 %
wolffd@0 175 % 'colori' Same as 'color' but uses shaded color plane (see 'compi').
wolffd@0 176 %
wolffd@0 177 % 'norm' Defines whether to use normalized or denormalized
wolffd@0 178 % values in the colorbar. If denormalized values are
wolffd@0 179 % used, they are acquired from SOM_DENORMALIZE function
wolffd@0 180 % using sMap.comp_norm field.
wolffd@0 181 % (string) 'd' (default) for denormalized values and 'n' for
wolffd@0 182 % normalized values. The corresponding letter appears
wolffd@0 183 % below the colorbar.
wolffd@0 184 %
wolffd@0 185 % 'bar' Define the direction of the colorbars for component planes
wolffd@0 186 % and U-matrices or turn them completely off.
wolffd@0 187 % (string) 'vert' (default), 'horiz' or 'none'. 'vert' gives
wolffd@0 188 % vertical and 'horiz' horizontal colorbars. 'none'
wolffd@0 189 % shows no colorbars at all.
wolffd@0 190 %
wolffd@0 191 % 'size' Define sizes of the units.
wolffd@0 192 % (scalar) all units have the same size (1 by default)
wolffd@0 193 % (vector) size Mx1, each unit gets individual size scaling
wolffd@0 194 % (as in SOM_CPLANE)
wolffd@0 195 %
wolffd@0 196 % 'edge' Unit edges on component plane visualizations.
wolffd@0 197 % (string) 'on' or 'off' determines whether the unit edges on component
wolffd@0 198 % planes ('comp') are shown or not. Default is 'off'. Note that
wolffd@0 199 % U-matrix and color planes are _always_ drawn without edges.
wolffd@0 200 %
wolffd@0 201 % 'footnote' Text on the figure
wolffd@0 202 % (string) is printed as a movable text object on the figure
wolffd@0 203 % where it may be moved using mouse. Default value is the
wolffd@0 204 % string in the sMap.name field. Note: value [] gives the
wolffd@0 205 % string, but input value '' gives no footnote a all.
wolffd@0 206 % See VIS_FOOTNOTE for more information on the text object
wolffd@0 207 % and ways to change its font size.
wolffd@0 208 %
wolffd@0 209 % 'colormap' som_show ghages the colormap by default to a gray-level map
wolffd@0 210 % (matrix) This argument is used to set some other colormap.
wolffd@0 211 %
wolffd@0 212 % 'subplots' the number of subplots in y- and x-directions, as in
wolffd@0 213 % (vector) command SUBPLOT
wolffd@0 214 %
wolffd@0 215 % OUTPUT ARGUMENTS
wolffd@0 216 %
wolffd@0 217 % h (struct)
wolffd@0 218 % .plane (vector) handles to the axes objects (subplots)
wolffd@0 219 % .colorbar (vector) handles to the colorbars. Colorbars of empty
wolffd@0 220 % & color planes do not exist: the corresponding
wolffd@0 221 % value in the vector is -1
wolffd@0 222 % .label (vector) handles to the axis labels
wolffd@0 223 %
wolffd@0 224 % OBJECT TAGS
wolffd@0 225 %
wolffd@0 226 % The property field 'Tag' of the axis objects created by this function
wolffd@0 227 % are set to contain string 'Cplane' if the axis contains component plane
wolffd@0 228 % ('comp'), color plane ('color') or empty plane ('empty') and string
wolffd@0 229 % 'Uplane' if it contains a u-matrix ('umat'). The tag is set to
wolffd@0 230 % 'CplaneI' for planes created using 'compi' and 'colori', and
wolffd@0 231 % 'UplaneI' for 'umati'.
wolffd@0 232 %
wolffd@0 233 % FEATURES
wolffd@0 234 %
wolffd@0 235 % Note that when interpolated shading is used in coloring ('compi' and
wolffd@0 236 % 'colori') the standard built-in bilinear Gouraud interpolation for a
wolffd@0 237 % SURF object is used. If the lattice is hexagonal - or anything else than
wolffd@0 238 % rectangular in general - the result is not strictly what is looked
wolffd@0 239 % for, especially if the map is small.
wolffd@0 240 %
wolffd@0 241 % EXAMPLES
wolffd@0 242 %
wolffd@0 243 %% Make random data, normalize it, and give component names
wolffd@0 244 %% Make a map
wolffd@0 245 %
wolffd@0 246 % data=som_data_struct(rand(1000,3),'comp_names',{'One','Two','Three'});
wolffd@0 247 % data=som_normalize(data,'var');
wolffd@0 248 % map=som_make(data);
wolffd@0 249 %
wolffd@0 250 %% Do the basic visualization with som_show: u-matrix and all
wolffd@0 251 %% component planes
wolffd@0 252 %
wolffd@0 253 % som_show(map);
wolffd@0 254 %
wolffd@0 255 %% The values shown in the colorbar are denormalized codebook values
wolffd@0 256 %% (if denormalization is possible). To view the actual values, use
wolffd@0 257 %% the ..., 'norm', 'n' argument pair.
wolffd@0 258 %
wolffd@0 259 % som_show(map,'norm','n')
wolffd@0 260 %
wolffd@0 261 %% Something more complex:
wolffd@0 262 %% Show 1-2. Component planes 1 and 2 (variables 'One' and 'Two')
wolffd@0 263 %% 3. U-matrix that is calculated only using variables
wolffd@0 264 %% 'One' and 'Two'
wolffd@0 265 %% with title '1,2 only'
wolffd@0 266 %% 4. U-matrix that is calculated using all variables with the
wolffd@0 267 %% deafult title 'U-matrix'
wolffd@0 268 %% 5. The color code (in c) with title 'Color code'
wolffd@0 269 %% 6. Component plane 3 (variable 'Three')
wolffd@0 270 %% and use vertical colorbars and and the values
wolffd@0 271 %% But first: make a continuous color code (see som_colorcode)
wolffd@0 272 %
wolffd@0 273 % c=som_colorcode(map,'rgb1');
wolffd@0 274 %
wolffd@0 275 % som_show(map,'comp',[1 2],'umat',{1:2,'1,2 only'},'umat','all', ...
wolffd@0 276 % 'color',{c,'Color code'},'bar','vert','norm','n','comp',3)
wolffd@0 277 %
wolffd@0 278 % SEE ALSO
wolffd@0 279 %
wolffd@0 280 % som_show_add Show hits, labels and trajectories on SOM_SHOW visualization.
wolffd@0 281 % som_show_clear Clear hit marks, labels or trajectories from current figure.
wolffd@0 282 % som_umat Compute unified distance matrix of self-organizing map.
wolffd@0 283 % som_grid Visualization of a SOM grid.
wolffd@0 284 % som_cplane Visualization of component, u-matrix and color planes.
wolffd@0 285
wolffd@0 286 % Copyright (c) 1997-2000 by the SOM toolbox programming team.
wolffd@0 287 % http://www.cis.hut.fi/projects/somtoolbox/
wolffd@0 288
wolffd@0 289 % Version 1.0beta johan 100298
wolffd@0 290 % Version 2.0beta johan 201099 juuso 181199 johan 011299-100200
wolffd@0 291 % juuso 130300 190600
wolffd@0 292
wolffd@0 293 %% Check arguments %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
wolffd@0 294
wolffd@0 295 error(nargchk(1,Inf,nargin)) % check no. of input args
wolffd@0 296
wolffd@0 297 if isstruct(sMap), % check map
wolffd@0 298 [tmp,ok,tmp]=som_set(sMap);
wolffd@0 299 if all(ok) & strcmp(sMap.type,'som_map')
wolffd@0 300 ;
wolffd@0 301 else
wolffd@0 302 error('Map struct is invalid!');
wolffd@0 303 end
wolffd@0 304 else
wolffd@0 305 error('Requires a map struct!')
wolffd@0 306 end
wolffd@0 307
wolffd@0 308 munits=size(sMap.codebook,1); % numb. of map units
wolffd@0 309 d=size(sMap.codebook,2); % numb. of components
wolffd@0 310 msize=sMap.topol.msize; % size of the map
wolffd@0 311 lattice=sMap.topol.lattice; % lattice
wolffd@0 312
wolffd@0 313 if length(msize)>2
wolffd@0 314 error('This visualizes only 2D maps!')
wolffd@0 315 end
wolffd@0 316
wolffd@0 317 if rem(length(varargin),2)
wolffd@0 318 error('Mismatch in identifier-value pairs.');
wolffd@0 319 end
wolffd@0 320
wolffd@0 321 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
wolffd@0 322 % read in optional arguments
wolffd@0 323
wolffd@0 324 if isempty(varargin),
wolffd@0 325 varargin = { 'umat','all','comp','all'};
wolffd@0 326 end
wolffd@0 327
wolffd@0 328 %% check the varargin and build visualization infostrcuts
wolffd@0 329 % Vis: what kind of planes, in which order, what are the values in
wolffd@0 330 % the units
wolffd@0 331 % Vis_param: general properties
wolffd@0 332 % see subfunction
wolffd@0 333
wolffd@0 334 % The try-catch construction is here just for avoiding the
wolffd@0 335 % possible termination to happen in subfunction because an error
wolffd@0 336 % message containing subfunction line numbers etc. might be confusing, as
wolffd@0 337 % there probably is nothing wrong with the subfunction but with the
wolffd@0 338 % input. Ok, this isn't proper programming sytle...
wolffd@0 339
wolffd@0 340 try
wolffd@0 341 [Plane, General]= check_varargin(varargin, munits, d, sMap.name);
wolffd@0 342 catch
wolffd@0 343 error(lasterr);
wolffd@0 344 end
wolffd@0 345
wolffd@0 346 % Set default values for missing ones
wolffd@0 347
wolffd@0 348 % No planes at all (only general properties given in varargin):
wolffd@0 349 % set default visualization
wolffd@0 350
wolffd@0 351 if isempty(Plane)
wolffd@0 352 varargin = [varargin, { 'umat','all','comp','all'}];
wolffd@0 353 % and again we go...
wolffd@0 354 try
wolffd@0 355 [Plane, General]= check_varargin(varargin, munits, d, sMap.name);
wolffd@0 356 catch
wolffd@0 357 error(lasterr);
wolffd@0 358 end
wolffd@0 359 end
wolffd@0 360
wolffd@0 361 % set defaults for general properties
wolffd@0 362
wolffd@0 363 if isempty(General.colorbardir)
wolffd@0 364 General.colorbardir='vert';
wolffd@0 365 end
wolffd@0 366
wolffd@0 367 if isempty(General.scale)
wolffd@0 368 General.scale='denormalized';
wolffd@0 369 end
wolffd@0 370
wolffd@0 371 if isempty(General.size)
wolffd@0 372 General.size=1;
wolffd@0 373 end
wolffd@0 374
wolffd@0 375 if isempty(General.edgecolor)
wolffd@0 376 General.edgecolor='none';
wolffd@0 377 end
wolffd@0 378
wolffd@0 379 %% Action %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
wolffd@0 380
wolffd@0 381 % get rid of an annoying warning: "RGB color data not yet supported in
wolffd@0 382 % Painter's mode."
wolffd@0 383 %set(gcf, 'renderer','zbuffer');
wolffd@0 384 %% -> a much more annoying thing results: the output to PostScript is
wolffd@0 385 %% as bitmap, making the files over 6MB in size...
wolffd@0 386
wolffd@0 387 n=length(Plane); % the number of subfigures
wolffd@0 388
wolffd@0 389 % get the unique component indices
wolffd@0 390 c=General.comp(General.comp>0);
wolffd@0 391 c=setdiff(unique(c),[0 -1]);
wolffd@0 392 c=c(~isnan(c));
wolffd@0 393
wolffd@0 394 % estimate the suitable dimension for
wolffd@0 395 if isempty(General.subplots),
wolffd@0 396 y=ceil(sqrt(n)); % subplots
wolffd@0 397 x=ceil(n/y);
wolffd@0 398 else
wolffd@0 399 y = General.subplots(2);
wolffd@0 400 x = General.subplots(1);
wolffd@0 401 if y*x<n,
wolffd@0 402 error(['Given subplots grid size is too small: should be >=' num2str(n)]);
wolffd@0 403 end
wolffd@0 404 end
wolffd@0 405
wolffd@0 406 clf; % clear figure
wolffd@0 407
wolffd@0 408 for i=1:n, % main loop
wolffd@0 409 h_axes(i,1)=subplot(x,y,i); % open a new subplot
wolffd@0 410
wolffd@0 411 % Main switch: select function according to the flags set in comps
wolffd@0 412
wolffd@0 413 switch Plane{i}.mode
wolffd@0 414
wolffd@0 415 case 'comp'
wolffd@0 416 %%% Component plane
wolffd@0 417
wolffd@0 418 tmp_h=som_cplane(lattice,msize, sMap.codebook(:,General.comp(i)), ...
wolffd@0 419 General.size);
wolffd@0 420 set(tmp_h,'EdgeColor', General.edgecolor);
wolffd@0 421 set(h_axes(i),'Tag','Cplane');
wolffd@0 422 h_label(i,1)=xlabel(sMap.comp_names{General.comp(i)});
wolffd@0 423
wolffd@0 424
wolffd@0 425 case 'compi'
wolffd@0 426 %%% Component plane (interpolated shading)
wolffd@0 427
wolffd@0 428 tmp_h=som_grid(lattice, msize, 'surf', sMap.codebook(:,Plane{i}.value), ...
wolffd@0 429 'Marker', 'none', 'Line', 'none');
wolffd@0 430 set(h_axes(i),'Tag','CplaneI');
wolffd@0 431 h_label(i,1)=xlabel(sMap.comp_names(Plane{i}.value));
wolffd@0 432 vis_PlaneAxisProperties(gca,lattice,msize,NaN);
wolffd@0 433
wolffd@0 434 case 'color'
wolffd@0 435 %%% Color plane
wolffd@0 436
wolffd@0 437 tmp_h=som_cplane(lattice,msize,Plane{i}.value,General.size);
wolffd@0 438 set(tmp_h,'EdgeColor','none');
wolffd@0 439 set(h_axes(i),'Tag','Cplane');
wolffd@0 440 h_label(i,1)=xlabel(Plane{i}.name);
wolffd@0 441
wolffd@0 442
wolffd@0 443 case 'colori'
wolffd@0 444 %%% Color plane (interpolated shading)
wolffd@0 445
wolffd@0 446 tmp_h=som_grid(lattice, msize, 'surf', Plane{i}.value, 'Marker', 'none', ...
wolffd@0 447 'Line', 'none');
wolffd@0 448 set(h_axes(i),'Tag','CplaneI');
wolffd@0 449 h_label(i,1)=xlabel(Plane{i}.name);
wolffd@0 450 vis_PlaneAxisProperties(gca,lattice,msize,NaN);
wolffd@0 451
wolffd@0 452 case 'empty'
wolffd@0 453 %%% Empty plane
wolffd@0 454
wolffd@0 455 tmp_h=som_cplane(lattice,msize,'none');
wolffd@0 456 h_label(i,1)=xlabel(Plane{i}.name);
wolffd@0 457 set(h_axes(i),'Tag','Cplane');
wolffd@0 458
wolffd@0 459 case 'umat'
wolffd@0 460 %%% Umatrix
wolffd@0 461
wolffd@0 462 u=som_umat(sMap.codebook(:,Plane{i}.value),sMap.topol,'median',...
wolffd@0 463 'mask',sMap.mask(Plane{i}.value)); u=u(:);
wolffd@0 464 tmp_h=som_cplane([lattice 'U'],msize,u);
wolffd@0 465 set(tmp_h,'EdgeColor','none');
wolffd@0 466 set(h_axes(i),'Tag','Uplane');
wolffd@0 467 h_label(i,1)=xlabel(Plane{i}.name);
wolffd@0 468
wolffd@0 469 case 'umati'
wolffd@0 470 %%% Umatrix (interpolated shading)
wolffd@0 471
wolffd@0 472 u=som_umat(sMap.codebook(:,Plane{i}.value),sMap.topol,'mean',...
wolffd@0 473 'mask',sMap.mask(Plane{i}.value)); u=u(1:2:end,1:2:end);
wolffd@0 474 u=u(:);
wolffd@0 475 tmp_h=som_grid('rect', msize, 'surf', u, ...
wolffd@0 476 'Marker', 'none', 'Line', 'none', ...
wolffd@0 477 'coord', som_vis_coords(lattice,msize));
wolffd@0 478 set(h_axes(i),'Tag','UplaneI');
wolffd@0 479 h_label(i,1)=xlabel(Plane{i}.name);
wolffd@0 480 vis_PlaneAxisProperties(gca,lattice,msize,NaN);
wolffd@0 481
wolffd@0 482 otherwise
wolffd@0 483 error('INTERNAL ERROR: unknown visualization mode.');
wolffd@0 484 end
wolffd@0 485
wolffd@0 486 %%% Adjust axis ratios to optimal (only 2D!) and put the
wolffd@0 487 %%% title as close to axis as possible
wolffd@0 488
wolffd@0 489 set(h_label,'Visible','on','verticalalignment','top');
wolffd@0 490 set(gca,'plotboxaspectratio',[msize(2) msize(1) msize(1)]);
wolffd@0 491
wolffd@0 492 %%% Draw colorbars if they are turned on and the plane is umat or c-plane
wolffd@0 493
wolffd@0 494 if General.comp(i)> -1 & ~strcmp(General.colorbardir,'none'),
wolffd@0 495 h_colorbar(i,1)=colorbar(General.colorbardir); % colorbars
wolffd@0 496 else
wolffd@0 497 h_colorbar(i,1)=-1;
wolffd@0 498 General.comp(i)=-1;
wolffd@0 499 end
wolffd@0 500 end %% main loop ends
wolffd@0 501
wolffd@0 502 % Set window name
wolffd@0 503
wolffd@0 504 set(gcf,'Name',[ 'Map name: ' sMap.name]);
wolffd@0 505
wolffd@0 506 %% Set axes handles to the UserData field (for som_addxxx functions
wolffd@0 507 %% and som_recolorbar)
wolffd@0 508 %% set component indexes and normalization struct for som_recolorbar
wolffd@0 509
wolffd@0 510 SOM_SHOW.subplotorder=h_axes;
wolffd@0 511 SOM_SHOW.msize=msize;
wolffd@0 512 SOM_SHOW.lattice=lattice;
wolffd@0 513 SOM_SHOW.dim=d;
wolffd@0 514 SOM_SHOW.comps=General.comp;
wolffd@0 515 SOM_SHOW.comp_norm=sMap.comp_norm; %(General.comp(find(General.comp>0)));
wolffd@0 516
wolffd@0 517 set(gcf,'UserData', SOM_SHOW);
wolffd@0 518
wolffd@0 519 % Set text property 'interp' to 'none' in title texts
wolffd@0 520
wolffd@0 521 set(h_label,'interpreter','none');
wolffd@0 522
wolffd@0 523 h_colorbar=som_recolorbar('all', 3, General.scale); %refresh colorbars
wolffd@0 524
wolffd@0 525 % Set a movable text to lower corner pointsize 12.
wolffd@0 526
wolffd@0 527 vis_footnote(General.footnote); vis_footnote(12);
wolffd@0 528
wolffd@0 529 % set colormap
wolffd@0 530 colormap(General.colormap);
wolffd@0 531
wolffd@0 532 %% Build output %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
wolffd@0 533
wolffd@0 534 if nargout > 0
wolffd@0 535 h.plane=h_axes; h.colorbar=h_colorbar; h.label=h_label;
wolffd@0 536 end
wolffd@0 537
wolffd@0 538
wolffd@0 539 %%%%%% SUBFUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
wolffd@0 540
wolffd@0 541 function [Plane, General]=check_varargin(args, munits, dim, name)
wolffd@0 542
wolffd@0 543 % args: varargin of the main function
wolffd@0 544 % munits: number of map units
wolffd@0 545 % dim: map codebook dimension
wolffd@0 546 % name: map name
wolffd@0 547 % Define some variables (they must exist later)
wolffd@0 548
wolffd@0 549 Plane={}; % stores the visualization data for each subplot
wolffd@0 550 General.comp=[]; % information stored on SOM_SHOW figure (which component)
wolffd@0 551 General.size=[]; % unit size
wolffd@0 552 General.scale=[]; % normalization
wolffd@0 553 General.colorbardir=[]; % colorbar direction
wolffd@0 554 General.edgecolor=[]; % edge colors
wolffd@0 555 General.footnote=name; % footnote text
wolffd@0 556 General.colormap=colormap; % default colormap (used to be gray(64).^.5;)
wolffd@0 557 General.subplots=[]; % number of subplots in y- and x-directions
wolffd@0 558
wolffd@0 559 for i=1:2:length(args),
wolffd@0 560 %% Check that all argument types are strings
wolffd@0 561
wolffd@0 562 if ~ischar(args{i}),
wolffd@0 563 error('Invalid input identifier names or input argument order.');
wolffd@0 564 end
wolffd@0 565
wolffd@0 566 %% Lower/uppercase in identifier types doesn't matter:
wolffd@0 567
wolffd@0 568 identifier=lower(args{i}); % identifier (lowercase)
wolffd@0 569 value=args{i+1};
wolffd@0 570
wolffd@0 571 %%% Check first the identifiers that define planes and get values
wolffd@0 572 %%% to the visualization data struct array Plane.
wolffd@0 573 %%% (comps,compi,umat,color,empty) Note that name, value and comp_
wolffd@0 574 %%% must be specified in these cases
wolffd@0 575 %%% comp_ are collected to comp in order. This is stored to the
wolffd@0 576 %%% SOM_SHOW user property field to give information for SOM_RECOLROBAR
wolffd@0 577 %%% how to operate, i.e., which component is in which subplot:
wolffd@0 578 %%% comp(i)=0: draw colorbar, but no normalization (umat)
wolffd@0 579 %%% comp(i)=1...N: a component plane of variable comp(i)
wolffd@0 580 %%% comp(i)=-1: no colorbar (color or empty plane)
wolffd@0 581
wolffd@0 582 switch identifier
wolffd@0 583 case {'comp','compi'}
wolffd@0 584 %%% Component planes: check values & set defaults
wolffd@0 585
wolffd@0 586 if ~vis_valuetype(value,{'nx1','1xn','string'}) & ~isempty(value),
wolffd@0 587 error([ 'A vector argument or string ''all'' expected for ''' ...
wolffd@0 588 identifier '''.'])
wolffd@0 589 end
wolffd@0 590 if isempty(value)
wolffd@0 591 value=1:dim;
wolffd@0 592 elseif ischar(value),
wolffd@0 593 if ~strcmp(value,'all')
wolffd@0 594 error([ 'Only string value ''all'' is valid for ''' ...
wolffd@0 595 identifier '''.']);
wolffd@0 596 else
wolffd@0 597 value=1:dim;
wolffd@0 598 end
wolffd@0 599 else
wolffd@0 600 value=round(value);
wolffd@0 601 if min(value)<1 | max(value)>dim,
wolffd@0 602 error([ 'Component indices out of range in ''' identifier '''.'])
wolffd@0 603 end
wolffd@0 604 end
wolffd@0 605 if size(value,1)==1, value=value';end
wolffd@0 606 comp_=value;
wolffd@0 607 name=[]; % name is taken form sMap by index in main loop
wolffd@0 608
wolffd@0 609 case {'umat','umati'}
wolffd@0 610 %%% Check first the possible cell input
wolffd@0 611
wolffd@0 612 if iscell(value),
wolffd@0 613 if ndims(value) ~= 2 | any(size(value) ~= [1 2]) | ...
wolffd@0 614 ~vis_valuetype(value{2},{'string'}),
wolffd@0 615 error('Cell input for ''umat'' has to be of form {vector, string}.');
wolffd@0 616 else
wolffd@0 617 name=value{2}; value=value{1};
wolffd@0 618 end
wolffd@0 619 else
wolffd@0 620 name='U-matrix'; % no cell: default title is set
wolffd@0 621 end
wolffd@0 622 if ~vis_valuetype(value,{'nx1','1xn','string'}) & ~isempty(value),
wolffd@0 623 error('Vector, string ''all'', or cell {vector, string} expected for ''umat''.')
wolffd@0 624 end
wolffd@0 625 if isempty(value)
wolffd@0 626 value=1:dim;
wolffd@0 627 elseif ischar(value),
wolffd@0 628 if ~strcmp(value,'all')
wolffd@0 629 error('Only string value ''all'' is valid for ''umat''.')
wolffd@0 630 else
wolffd@0 631 value=1:dim;
wolffd@0 632 end
wolffd@0 633 else
wolffd@0 634 value=unique(round(value));
wolffd@0 635 end
wolffd@0 636 if min(value)<1 | max(value)>dim,
wolffd@0 637 error('Component indices out of range in ''umat''.')
wolffd@0 638 end
wolffd@0 639
wolffd@0 640 if size(value,1)==1, value=value';end
wolffd@0 641 comp_=0;
wolffd@0 642
wolffd@0 643 case 'empty'
wolffd@0 644 %%% Empty plane: check values & set defaults
wolffd@0 645
wolffd@0 646 if ~vis_valuetype(value,{'string'}),
wolffd@0 647 error('A string value for title name expected for ''empty''.');
wolffd@0 648 end
wolffd@0 649 name=value;
wolffd@0 650 comp_=-1;
wolffd@0 651
wolffd@0 652 case { 'color','colori'}
wolffd@0 653 %%% Color plane: check values & set defaults
wolffd@0 654
wolffd@0 655 % Check first the possible cell input
wolffd@0 656 if iscell(value),
wolffd@0 657 if ndims(value)~=2 | any(size(value) ~= [1 2]) | ...
wolffd@0 658 ~vis_valuetype(value{2},{'string'}),
wolffd@0 659 error([ 'Cell input for ''' identifier ...
wolffd@0 660 ''' has to be of form {M, string}.']);
wolffd@0 661 else
wolffd@0 662 name=value{2}; value=value{1};
wolffd@0 663 end
wolffd@0 664 else
wolffd@0 665 name='Color code'; % no cell: default title is set
wolffd@0 666 end
wolffd@0 667 if size(value,1)~=munits | ...
wolffd@0 668 (~vis_valuetype(value,{'nx3rgb'}) & ...
wolffd@0 669 ~vis_valuetype(value,{'nx1'}) & ...
wolffd@0 670 ~vis_valuetype(value,{'nx1xm'}) & ...
wolffd@0 671 ~vis_valuetype(value,{'nx3xdimrgb'})),
wolffd@0 672 error(['Mx3 or Mx3xN RGBmatrix, Mx1 or Mx1xN matrix, cell '...
wolffd@0 673 '{RGBmatrix, string},' ...
wolffd@0 674 ' or {matrix, string} expected for ''' identifier '''.']);
wolffd@0 675 end
wolffd@0 676
wolffd@0 677 % if colormap is fixed, we don't draw colorbar (comp_ flag is -1)
wolffd@0 678 % if colormap is indexed, we draw colorbar as in umat (comp_=0)
wolffd@0 679
wolffd@0 680 if size(value,2)==3
wolffd@0 681 comp_=-1;
wolffd@0 682 else
wolffd@0 683 comp_=0;
wolffd@0 684 end
wolffd@0 685
wolffd@0 686 %%%% The next things are general properties of the visualization---
wolffd@0 687 %%%%
wolffd@0 688 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
wolffd@0 689
wolffd@0 690 case 'size'
wolffd@0 691 %%% Unit size: check & set
wolffd@0 692
wolffd@0 693 if ~vis_valuetype(value,{'1x1',[munits 1]})
wolffd@0 694 error('A munits x 1 vector or a scalar expected for ''size''.')
wolffd@0 695 end
wolffd@0 696 if isempty(value),
wolffd@0 697 General.size=1;
wolffd@0 698 else
wolffd@0 699 General.size=value;
wolffd@0 700 end
wolffd@0 701
wolffd@0 702 case 'bar'
wolffd@0 703 %%% Colorbar existence & direction: check & set
wolffd@0 704
wolffd@0 705 if ~vis_valuetype(value,{'string'})
wolffd@0 706 error('String value expected for ''bar''.')
wolffd@0 707 elseif isempty(value)
wolffd@0 708 value='vert';
wolffd@0 709 end
wolffd@0 710 if any(strcmp(value,{'vert','horiz','none'})),
wolffd@0 711 General.colorbardir=value;
wolffd@0 712 else
wolffd@0 713 error('String ''vert'', ''horiz'' or ''none'' expected for ''bar''.');
wolffd@0 714 end
wolffd@0 715
wolffd@0 716 case 'norm'
wolffd@0 717 %%% Value normalization: check & set
wolffd@0 718
wolffd@0 719 if ~vis_valuetype(value,{'string'})
wolffd@0 720 error('String ''n'' or ''d'' expected for ''norm''.');
wolffd@0 721 elseif isempty(value)
wolffd@0 722 value='n';
wolffd@0 723 end
wolffd@0 724 if strcmp(value(1),'n'),
wolffd@0 725 General.scale='normalized';
wolffd@0 726 elseif strcmp(value(1),'d'),
wolffd@0 727 General.scale='denormalized';
wolffd@0 728 else
wolffd@0 729 error('String ''n(ormalized)'' or ''d(enormalized)'' expected for ''norm''.');
wolffd@0 730 end
wolffd@0 731
wolffd@0 732 case 'edge'
wolffd@0 733 %%% Edge on or off : check % set
wolffd@0 734
wolffd@0 735 if ~vis_valuetype(value,{'string'}) & ~isempty(value),
wolffd@0 736 error('String value expected for ''edge''.')
wolffd@0 737 elseif ~isempty(value),
wolffd@0 738 switch value
wolffd@0 739 case 'on'
wolffd@0 740 General.edgecolor='k';
wolffd@0 741 case 'off'
wolffd@0 742 General.edgecolor='none';
wolffd@0 743 otherwise
wolffd@0 744 error('String value ''on'' or ''off'' expected for ''edge''.')
wolffd@0 745 end
wolffd@0 746 end
wolffd@0 747
wolffd@0 748 case 'footnote'
wolffd@0 749 %%% Set the movable footnote text
wolffd@0 750
wolffd@0 751 if ~vis_valuetype(value,{'string'})
wolffd@0 752 if ~isempty(value),
wolffd@0 753 error('String value expected for ''footnote''.');
wolffd@0 754 else
wolffd@0 755 General.footnote=sMap.name;
wolffd@0 756 end
wolffd@0 757 else
wolffd@0 758 General.footnote=value;
wolffd@0 759 end
wolffd@0 760
wolffd@0 761 case 'colormap'
wolffd@0 762 %%% Set the colormap
wolffd@0 763 if isempty(value)
wolffd@0 764 General.colormap=gray(64).^2;
wolffd@0 765 elseif ~vis_valuetype(value,{'nx3rgb'})
wolffd@0 766 error('Colormap is invalid!');
wolffd@0 767 else
wolffd@0 768 General.colormap=value;
wolffd@0 769 end
wolffd@0 770
wolffd@0 771 case 'subplots'
wolffd@0 772 %%% set the number of subplots
wolffd@0 773 if ~vis_valuetype(value,{'1x2'}) & ~vis_valuetype(value,{'2x1'})
wolffd@0 774 error('Subplots grid size is invalid!');
wolffd@0 775 else
wolffd@0 776 General.subplots=value;
wolffd@0 777 end
wolffd@0 778
wolffd@0 779 otherwise
wolffd@0 780 %%% Unknown identifier
wolffd@0 781
wolffd@0 782 error(['Invalid argument identifier ''' identifier '''!']);
wolffd@0 783 end
wolffd@0 784
wolffd@0 785 %%% Set new entry to the Plane array if the indentifier means
wolffd@0 786 %%% making a new plane/planes
wolffd@0 787
wolffd@0 788 tail=length(Plane);
wolffd@0 789 switch identifier
wolffd@0 790 case {'comp','compi'}
wolffd@0 791 for i=1:length(value)
wolffd@0 792 Plane{tail+i}.mode=identifier;
wolffd@0 793 Plane{tail+i}.value=value(i);
wolffd@0 794 Plane{tail+i}.name=name; % not used actually
wolffd@0 795 end
wolffd@0 796 General.comp = [General.comp; comp_];
wolffd@0 797 case {'umat','umati','empty'}
wolffd@0 798 Plane{tail+1}.mode=identifier;
wolffd@0 799 Plane{tail+1}.value=value;
wolffd@0 800 Plane{tail+1}.name=name;
wolffd@0 801 General.comp = [General.comp; comp_];
wolffd@0 802 case {'color','colori'},
wolffd@0 803 for i=1:size(value,3),
wolffd@0 804 Plane{tail+i}.mode=identifier;
wolffd@0 805 Plane{tail+i}.name=[name '_' num2str(i)];
wolffd@0 806 Plane{tail+i}.value=value(:,:,i);
wolffd@0 807 General.comp = [General.comp; comp_];
wolffd@0 808 end
wolffd@0 809 if size(value,3)==1,
wolffd@0 810 Plane{tail+1}.name=name;
wolffd@0 811 end
wolffd@0 812 otherwise
wolffd@0 813 ; % do nothing
wolffd@0 814 end
wolffd@0 815 end