annotate toolboxes/MIRtoolbox1.3.2/somtoolbox/som_info.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 som_info(sS,level)
wolffd@0 2
wolffd@0 3 %SOM_INFO Displays information on the given SOM Toolbox struct.
wolffd@0 4 %
wolffd@0 5 % som_info(sS,[level])
wolffd@0 6 %
wolffd@0 7 % som_info(sMap);
wolffd@0 8 % som_info(sData,3);
wolffd@0 9 % som_info({sMap,sData});
wolffd@0 10 % som_info(sMap.comp_norm{2});
wolffd@0 11 %
wolffd@0 12 % Input and output arguments ([]'s are optional):
wolffd@0 13 % sS (struct) SOM Toolbox struct
wolffd@0 14 % (cell array of structs) several structs in a cell array
wolffd@0 15 % [level] (scalar) detail level (1-4), default = 1
wolffd@0 16 %
wolffd@0 17 % For more help, try 'type som_info' or check out online documentation.
wolffd@0 18 % See also SOM_SET.
wolffd@0 19
wolffd@0 20 %%%%%%%%%%%%% DETAILED DESCRIPTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
wolffd@0 21 %
wolffd@0 22 % som_info
wolffd@0 23 %
wolffd@0 24 % PURPOSE
wolffd@0 25 %
wolffd@0 26 % Display information of the given SOM Toolbox struct(s).
wolffd@0 27 %
wolffd@0 28 % SYNTAX
wolffd@0 29 %
wolffd@0 30 % som_info(sM)
wolffd@0 31 % som_info({sM,sD})
wolffd@0 32 % som_info(...,level)
wolffd@0 33 %
wolffd@0 34 % DESCRIPTION
wolffd@0 35 %
wolffd@0 36 % Display the contents of the given SOM Toolbox struct(s). Information
wolffd@0 37 % of several structs can be shown if the structs are given in a cell
wolffd@0 38 % array. The level of detail can be varied with the second argument.
wolffd@0 39 % The number of different levels varies between structs. For map and
wolffd@0 40 % data structs, not only the fields, but also some statistics of the
wolffd@0 41 % vectors ('.data' and '.codebook' fields) is displayed.
wolffd@0 42 %
wolffd@0 43 % map struct
wolffd@0 44 % level 1: name, dimension, topology, dimension, neigborhood function,
wolffd@0 45 % mask and training status
wolffd@0 46 % level 2: ..., training history
wolffd@0 47 % level 3: ..., vector component names, statistics and normalization status
wolffd@0 48 % level 4: ..., vector component normalizations
wolffd@0 49 %
wolffd@0 50 % data struct:
wolffd@0 51 % level 1: name, dimension, data set completeness statistics
wolffd@0 52 % level 2: ..., vector component names, statistics and normalization status
wolffd@0 53 % level 3: ..., vector component normalizations
wolffd@0 54 % level 4: ..., label statistics
wolffd@0 55 %
wolffd@0 56 % topology struct:
wolffd@0 57 % level 1: all fields
wolffd@0 58 %
wolffd@0 59 % train struct:
wolffd@0 60 % level 1: all fields
wolffd@0 61 %
wolffd@0 62 % normalization struct:
wolffd@0 63 % level 1: method, status
wolffd@0 64 % level 2: ..., parameters
wolffd@0 65 %
wolffd@0 66 % REQUIRED INPUT ARGUMENTS
wolffd@0 67 %
wolffd@0 68 % sS (struct) SOM Toolbox struct
wolffd@0 69 % (cell array of structs) several structs in a cell array
wolffd@0 70 %
wolffd@0 71 % OPTIONAL INPUT ARGUMENTS
wolffd@0 72 %
wolffd@0 73 % level (scalar) detail level (1-4), default = 1
wolffd@0 74 %
wolffd@0 75 % EXAMPLES
wolffd@0 76 %
wolffd@0 77 % som_info(sM)
wolffd@0 78 % som_info(sM,4)
wolffd@0 79 % som_info(sM.trainhist)
wolffd@0 80 % som_info(sM.comp_norm{3})
wolffd@0 81 %
wolffd@0 82 % SEE ALSO
wolffd@0 83 %
wolffd@0 84 % som_set Set fields and create SOM Toolbox structs.
wolffd@0 85
wolffd@0 86 % Copyright (c) 1999-2000 by the SOM toolbox programming team.
wolffd@0 87 % http://www.cis.hut.fi/projects/somtoolbox/
wolffd@0 88
wolffd@0 89 % Version 1.0beta ecco 110997
wolffd@0 90 % Version 2.0beta juuso 101199
wolffd@0 91
wolffd@0 92 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
wolffd@0 93 %% check arguments
wolffd@0 94
wolffd@0 95 error(nargchk(1, 2, nargin)) % check no. of input args is correct
wolffd@0 96
wolffd@0 97 if ~isstruct(sS),
wolffd@0 98 if ~iscell(sS) | ~isstruct(sS{1}),
wolffd@0 99 error('Invalid first input argument.')
wolffd@0 100 end
wolffd@0 101 csS = sS;
wolffd@0 102 else
wolffd@0 103 l = length(sS);
wolffd@0 104 csS = cell(l,1);
wolffd@0 105 for i=1:l, csS{i} = sS(i); end
wolffd@0 106 end
wolffd@0 107
wolffd@0 108 if nargin<2 | isempty(level) | isnan(level), level = 1; end
wolffd@0 109
wolffd@0 110 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
wolffd@0 111 %% print struct information
wolffd@0 112
wolffd@0 113 for c=1:length(csS),
wolffd@0 114 sS = csS{c};
wolffd@0 115 fprintf(1,'\n');
wolffd@0 116
wolffd@0 117 switch sS.type,
wolffd@0 118 case 'som_map',
wolffd@0 119 mdim = length(sS.topol.msize);
wolffd@0 120 [munits dim] = size(sS.codebook);
wolffd@0 121 t = length(sS.trainhist);
wolffd@0 122 if t==0, st='uninitialized';
wolffd@0 123 elseif t==1, st = 'initialized';
wolffd@0 124 else st = sprintf('initialized, trained %d times',t-1);
wolffd@0 125 end
wolffd@0 126
wolffd@0 127 % level 1
wolffd@0 128 fprintf(1,'Struct type : %s\n', sS.type);
wolffd@0 129 fprintf(1,'Map name : %s\n', sS.name);
wolffd@0 130 fprintf(1,'Input dimension : %d\n', dim);
wolffd@0 131 fprintf(1,'Map grid size : ');
wolffd@0 132 for i = 1:mdim - 1, fprintf(1,'%d x ',sS.topol.msize(i)); end
wolffd@0 133 fprintf(1,'%d\n', sS.topol.msize(mdim));
wolffd@0 134 fprintf(1,'Lattice type (rect/hexa) : %s\n', sS.topol.lattice);
wolffd@0 135 fprintf(1,'Shape (sheet/cyl/toroid) : %s\n', sS.topol.shape);
wolffd@0 136 fprintf(1,'Neighborhood type : %s\n', sS.neigh);
wolffd@0 137 fprintf(1,'Mask : ');
wolffd@0 138 if dim,
wolffd@0 139 for i = 1:dim-1, fprintf(1,'%d ',sS.mask(i)); end;
wolffd@0 140 fprintf(1,'%d\n',sS.mask(dim));
wolffd@0 141 else fprintf(1,'\n');
wolffd@0 142 end
wolffd@0 143 fprintf(1,'Training status : %s\n', st);
wolffd@0 144
wolffd@0 145 % level 1,
wolffd@0 146 status = cell(dim,1);
wolffd@0 147 for i=1:dim,
wolffd@0 148 n = length(sS.comp_norm{i});
wolffd@0 149 if n,
wolffd@0 150 uninit = strcmp('uninit',{sS.comp_norm{i}.status});
wolffd@0 151 done = strcmp('done',{sS.comp_norm{i}.status});
wolffd@0 152 undone = strcmp('undone',{sS.comp_norm{i}.status});
wolffd@0 153 if sum(uninit)==n, status{i} = 'none';
wolffd@0 154 elseif sum(done)==n, status{i} = 'done';
wolffd@0 155 elseif sum(undone)==n, status{i} = 'undone';
wolffd@0 156 else status{i} = 'partial';
wolffd@0 157 end
wolffd@0 158 else status{i} = 'no normalization'; end
wolffd@0 159 end
wolffd@0 160 if level>1,
wolffd@0 161 fprintf(1,'\nVector components\n');
wolffd@0 162 M = sS.codebook;
wolffd@0 163 fprintf(1,' # name mask min mean max std normalization\n');
wolffd@0 164 fprintf(1,' --- ------------ ---- ------ ------ ------ ------ -------------\n');
wolffd@0 165 for i = 1:dim,
wolffd@0 166 fprintf(1,' %-3d %-12s %-4.2f %6.2g %6.2g %6.2g %6.2g %s\n', ...
wolffd@0 167 i,sS.comp_names{i}, sS.mask(i), ...
wolffd@0 168 min(M(:,i)),mean(M(:,i)),max(M(:,i)),std(M(:,i)),status{i});
wolffd@0 169 end
wolffd@0 170 end
wolffd@0 171
wolffd@0 172 % level 3
wolffd@0 173 if level>2,
wolffd@0 174 fprintf(1,'\nVector component normalizations\n');
wolffd@0 175 fprintf(1,' # name method (i=uninit,u=undone,d=done)\n');
wolffd@0 176 fprintf(1,' --- ------------ ---------------------------------------\n');
wolffd@0 177 for i=1:dim,
wolffd@0 178 fprintf(1,' %-3d %-12s ',i,sS.comp_names{i});
wolffd@0 179 n = length(sS.comp_norm{i});
wolffd@0 180 for j=1:n,
wolffd@0 181 m = sS.comp_norm{i}(j).method;
wolffd@0 182 s = sS.comp_norm{i}(j).status;
wolffd@0 183 if strcmp(s,'uninit'), c='i';
wolffd@0 184 elseif strcmp(s,'undone'), c='u';
wolffd@0 185 else c='d';
wolffd@0 186 end
wolffd@0 187 fprintf(1,'%s[%s] ',m,c);
wolffd@0 188 end
wolffd@0 189 fprintf(1,'\n');
wolffd@0 190 end
wolffd@0 191 end
wolffd@0 192
wolffd@0 193 % level 4
wolffd@0 194 if level>3,
wolffd@0 195 fprintf(1,'\nTraining history\n');
wolffd@0 196 fprintf(1,'Algorithm Data Trainlen Neigh.f. Radius Alpha (type) Date\n');
wolffd@0 197 fprintf(1,'--------- ------------- -------- -------- ---------- -------------- --------------------\n');
wolffd@0 198 for i=1:t,
wolffd@0 199 sT = sS.trainhist(i);
wolffd@0 200 fprintf(1,'%8s %13s %8d %8s %4.2f->%4.2f %5.3f (%6s) %s\n',...
wolffd@0 201 sT.algorithm,sT.data_name,sT.trainlen,...
wolffd@0 202 sT.neigh,sT.radius_ini,sT.radius_fin,sT.alpha_ini,sT.alpha_type,sT.time);
wolffd@0 203 %for j = 1:length(sT.mask)-1, fprintf(1,'%d ',sT.mask(j)); end;
wolffd@0 204 %if ~isempty(sT.mask), fprintf(1,'%d\n',sT.mask(end)); else fprintf(1,'\n'); end
wolffd@0 205 end
wolffd@0 206 end
wolffd@0 207
wolffd@0 208 case 'som_data',
wolffd@0 209
wolffd@0 210 [dlen dim] = size(sS.data);
wolffd@0 211 if dlen*dim
wolffd@0 212 if dim>1, ind = find(~isnan(sum(sS.data,2)));
wolffd@0 213 else ind = find(~isnan(sS.data));
wolffd@0 214 end
wolffd@0 215 else ind = []; end
wolffd@0 216 complete = size(sS.data(ind,:),1);
wolffd@0 217 partial = dlen - complete;
wolffd@0 218 values = prod(size(sS.data));
wolffd@0 219 missing = sum(sum(isnan(sS.data)));
wolffd@0 220
wolffd@0 221 % level 1
wolffd@0 222 fprintf(1,'Struct type : %s\n', sS.type);
wolffd@0 223 fprintf(1,'Data name : %s\n', sS.name);
wolffd@0 224 fprintf(1,'Vector dimension : %d\n', dim);
wolffd@0 225 fprintf(1,'Number of data vectors : %d\n', dlen);
wolffd@0 226 fprintf(1,'Complete data vectors : %d\n', complete);
wolffd@0 227 fprintf(1,'Partial data vectors : %d\n', partial);
wolffd@0 228 if values, r = floor(100 * (values - missing) / values); else r = 0; end
wolffd@0 229 fprintf(1,'Complete values : %d of %d (%d%%)\n', ...
wolffd@0 230 values-missing, values, r);
wolffd@0 231
wolffd@0 232 % level 2,
wolffd@0 233 status = cell(dim,1);
wolffd@0 234 for i=1:dim,
wolffd@0 235 n = length(sS.comp_norm{i});
wolffd@0 236 if n,
wolffd@0 237 uninit = strcmp('uninit',{sS.comp_norm{i}.status});
wolffd@0 238 done = strcmp('done',{sS.comp_norm{i}.status});
wolffd@0 239 undone = strcmp('undone',{sS.comp_norm{i}.status});
wolffd@0 240 if sum(uninit)==n, status{i} = 'none';
wolffd@0 241 elseif sum(done)==n, status{i} = 'done';
wolffd@0 242 elseif sum(undone)==n, status{i} = 'undone';
wolffd@0 243 else status{i} = 'partial';
wolffd@0 244 end
wolffd@0 245 else status{i} = 'no normalization'; end
wolffd@0 246 end
wolffd@0 247 if level>1,
wolffd@0 248 fprintf(1,'\nVector components\n');
wolffd@0 249 D = sS.data;
wolffd@0 250 fprintf(1,' # name min mean max std missing normalization\n');
wolffd@0 251 fprintf(1,' --- ------------ ------ ------ ------ ------ ----------- -------------\n');
wolffd@0 252 for i = 1:dim,
wolffd@0 253 known = find(~isnan(D(:,i)));
wolffd@0 254 miss = dlen-length(known);
wolffd@0 255 switch length(known),
wolffd@0 256 case 0, mi = NaN; me = NaN; ma = NaN; st = NaN;
wolffd@0 257 case 1, mi = D(known,i); me = mi; ma = mi; st = 0;
wolffd@0 258 otherwise,
wolffd@0 259 mi = min(D(known,i)); ma = max(D(known,i));
wolffd@0 260 me = mean(D(known,i)); st = std(D(known,i));
wolffd@0 261 end
wolffd@0 262 fprintf(1,' %-3d %-12s %6.2g %6.2g %6.2g %6.2g %5d (%2d%%) %s\n', ...
wolffd@0 263 i,sS.comp_names{i},mi,me,ma,st,miss,floor(100*miss/dlen),status{i});
wolffd@0 264 end
wolffd@0 265 end
wolffd@0 266
wolffd@0 267 % level 3
wolffd@0 268 if level>2,
wolffd@0 269 fprintf(1,'\nVector component normalizations\n');
wolffd@0 270 fprintf(1,' # name method (i=uninit,u=undone,d=done)\n');
wolffd@0 271 fprintf(1,' --- ------------ ---------------------------------------\n');
wolffd@0 272 for i=1:dim,
wolffd@0 273 fprintf(1,' %-3d %-12s ',i,sS.comp_names{i});
wolffd@0 274 n = length(sS.comp_norm{i});
wolffd@0 275 for j=1:n,
wolffd@0 276 m = sS.comp_norm{i}(j).method;
wolffd@0 277 s = sS.comp_norm{i}(j).status;
wolffd@0 278 if strcmp(s,'uninit'), c='i';
wolffd@0 279 elseif strcmp(s,'undone'), c='u';
wolffd@0 280 else c='d';
wolffd@0 281 end
wolffd@0 282 fprintf(1,'%s[%s] ',m,c);
wolffd@0 283 end
wolffd@0 284 fprintf(1,'\n');
wolffd@0 285 end
wolffd@0 286 end
wolffd@0 287
wolffd@0 288 % level 4
wolffd@0 289 if level>3,
wolffd@0 290 m = size(sS.labels,2);
wolffd@0 291 fprintf(1,'\nLabels\n');
wolffd@0 292 if isempty(sS.label_names),
wolffd@0 293 labs = {''}; freq = 0;
wolffd@0 294 for i=1:dlen*m,
wolffd@0 295 l = sS.labels{i};
wolffd@0 296 if isempty(l), freq(1) = freq(1)+1;
wolffd@0 297 else
wolffd@0 298 k = find(strcmp(labs,l));
wolffd@0 299 if isempty(k), labs{end+1} = l; freq(end+1) = 1;
wolffd@0 300 else freq(k)=freq(k)+1;
wolffd@0 301 end
wolffd@0 302 end
wolffd@0 303 end
wolffd@0 304 emp = freq(1);
wolffd@0 305 uni = length(freq)-1;
wolffd@0 306 if uni>0, tot = sum(freq(2:end)); else tot = 0; end
wolffd@0 307 fprintf(1,' Total: %d\n Empty: %d\n Unique: %d\n',tot,emp,uni);
wolffd@0 308 else
wolffd@0 309 for j=1:m,
wolffd@0 310 labs = {''}; freq = 0;
wolffd@0 311 for i=1:dlen,
wolffd@0 312 l = sS.labels{i,j};
wolffd@0 313 if isempty(l), freq(1) = freq(1)+1;
wolffd@0 314 else
wolffd@0 315 k = find(strcmp(labs,l));
wolffd@0 316 if isempty(k), labs{end+1} = l; freq(end+1) = 1;
wolffd@0 317 else freq(k)=freq(k)+1;
wolffd@0 318 end
wolffd@0 319 end
wolffd@0 320 end
wolffd@0 321 emp = freq(1);
wolffd@0 322 uni = length(freq)-1;
wolffd@0 323 if uni>0, tot = sum(freq(2:end)); else tot = 0; end
wolffd@0 324 fprintf(1,' [%s] Total / empty / unique: %d / %d / %d\n', ...
wolffd@0 325 sS.label_names{j},tot,emp,uni);
wolffd@0 326 end
wolffd@0 327 end
wolffd@0 328 end
wolffd@0 329
wolffd@0 330 case 'som_topol',
wolffd@0 331
wolffd@0 332 mdim = length(sS.msize);
wolffd@0 333
wolffd@0 334 % level 1
wolffd@0 335 fprintf(1,'Struct type : %s\n',sS.type);
wolffd@0 336 fprintf(1,'Map grid size : ');
wolffd@0 337 for i = 1:mdim - 1, fprintf(1,'%d x ',sS.msize(i)); end
wolffd@0 338 fprintf(1,'%d\n', sS.msize(mdim));
wolffd@0 339 fprintf(1,'Lattice type (rect/hexa) : %s\n', sS.lattice);
wolffd@0 340 fprintf(1,'Shape (sheet/cyl/toroid) : %s\n', sS.shape);
wolffd@0 341
wolffd@0 342 case 'som_train',
wolffd@0 343
wolffd@0 344 % level 1
wolffd@0 345 fprintf(1,'Struct type : %s\n',sS.type);
wolffd@0 346 fprintf(1,'Training algorithm : %s\n',sS.algorithm);
wolffd@0 347 fprintf(1,'Training data : %s\n',sS.data_name);
wolffd@0 348 fprintf(1,'Neighborhood function : %s\n',sS.neigh);
wolffd@0 349 fprintf(1,'Mask : ');
wolffd@0 350 dim = length(sS.mask);
wolffd@0 351 if dim,
wolffd@0 352 for i = 1:dim-1, fprintf(1,'%d ',sS.mask(i)); end;
wolffd@0 353 fprintf(1,'%d\n',sS.mask(end));
wolffd@0 354 else fprintf(1,'\n'); end
wolffd@0 355 fprintf(1,'Initial radius : %-6.1f\n',sS.radius_ini);
wolffd@0 356 fprintf(1,'Final radius : %-6.1f\n',sS.radius_fin);
wolffd@0 357 fprintf(1,'Initial learning rate (alpha) : %-6.1f\n',sS.alpha_ini);
wolffd@0 358 fprintf(1,'Alpha function type (linear/inv) : %s\n',sS.alpha_type);
wolffd@0 359 fprintf(1,'Training length : %d\n',sS.trainlen);
wolffd@0 360 fprintf(1,'When training was done : %s\n',sS.time);
wolffd@0 361
wolffd@0 362 case 'som_norm',
wolffd@0 363
wolffd@0 364 % level 1
wolffd@0 365 fprintf(1,'Struct type : %s\n',sS.type);
wolffd@0 366 fprintf(1,'Normalization method : %s\n',sS.method);
wolffd@0 367 fprintf(1,'Status : %s\n',sS.status);
wolffd@0 368
wolffd@0 369 % level 2
wolffd@0 370 if level>1,
wolffd@0 371 fprintf(1,'Parameters:\n');
wolffd@0 372 sS.params
wolffd@0 373 end
wolffd@0 374
wolffd@0 375 case 'som_grid',
wolffd@0 376
wolffd@0 377 % level 1
wolffd@0 378 fprintf(1,'Struct type : %s\n',sS.type);
wolffd@0 379 if ischar(sS.neigh),
wolffd@0 380 fprintf(1,'Connections : [%d %d], %s, %s\n',...
wolffd@0 381 sS.msize(1),sS.msize(2),sS.neigh,sS.shape);
wolffd@0 382 else
wolffd@0 383 fprintf(1,'Connections : [%d %d] %d lines\n',...
wolffd@0 384 sS.msize(1),sS.msize(2),sum(sS.neigh));
wolffd@0 385 end
wolffd@0 386 fprintf(1,'Line : %s\n',sS.line);
wolffd@0 387 if length(sS.marker)==1,
wolffd@0 388 fprintf(1,'Marker : %s\n',sS.marker);
wolffd@0 389 else
wolffd@0 390 fprintf(1,'Marker : varies\n');
wolffd@0 391 end
wolffd@0 392 fprintf(1,'Surf : ');
wolffd@0 393 if isempty(sS.surf), fprintf(1,'off\n'); else fprintf(1,'on\n'); end
wolffd@0 394 fprintf(1,'Labels : ');
wolffd@0 395 if isempty(sS.label), fprintf(1,'off\n');
wolffd@0 396 else fprintf(1,'on (%d)\n',sS.labelsize); end
wolffd@0 397
wolffd@0 398 end
wolffd@0 399
wolffd@0 400 fprintf(1,'\n');
wolffd@0 401 end
wolffd@0 402
wolffd@0 403 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%