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