Daniel@0: function som_info(sS,level) Daniel@0: Daniel@0: %SOM_INFO Displays information on the given SOM Toolbox struct. Daniel@0: % Daniel@0: % som_info(sS,[level]) Daniel@0: % Daniel@0: % som_info(sMap); Daniel@0: % som_info(sData,3); Daniel@0: % som_info({sMap,sData}); Daniel@0: % som_info(sMap.comp_norm{2}); Daniel@0: % Daniel@0: % Input and output arguments ([]'s are optional): Daniel@0: % sS (struct) SOM Toolbox struct Daniel@0: % (cell array of structs) several structs in a cell array Daniel@0: % [level] (scalar) detail level (1-4), default = 1 Daniel@0: % Daniel@0: % For more help, try 'type som_info' or check out online documentation. Daniel@0: % See also SOM_SET. Daniel@0: Daniel@0: %%%%%%%%%%%%% DETAILED DESCRIPTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Daniel@0: % Daniel@0: % som_info Daniel@0: % Daniel@0: % PURPOSE Daniel@0: % Daniel@0: % Display information of the given SOM Toolbox struct(s). Daniel@0: % Daniel@0: % SYNTAX Daniel@0: % Daniel@0: % som_info(sM) Daniel@0: % som_info({sM,sD}) Daniel@0: % som_info(...,level) Daniel@0: % Daniel@0: % DESCRIPTION Daniel@0: % Daniel@0: % Display the contents of the given SOM Toolbox struct(s). Information Daniel@0: % of several structs can be shown if the structs are given in a cell Daniel@0: % array. The level of detail can be varied with the second argument. Daniel@0: % The number of different levels varies between structs. For map and Daniel@0: % data structs, not only the fields, but also some statistics of the Daniel@0: % vectors ('.data' and '.codebook' fields) is displayed. Daniel@0: % Daniel@0: % map struct Daniel@0: % level 1: name, dimension, topology, dimension, neigborhood function, Daniel@0: % mask and training status Daniel@0: % level 2: ..., training history Daniel@0: % level 3: ..., vector component names, statistics and normalization status Daniel@0: % level 4: ..., vector component normalizations Daniel@0: % Daniel@0: % data struct: Daniel@0: % level 1: name, dimension, data set completeness statistics Daniel@0: % level 2: ..., vector component names, statistics and normalization status Daniel@0: % level 3: ..., vector component normalizations Daniel@0: % level 4: ..., label statistics Daniel@0: % Daniel@0: % topology struct: Daniel@0: % level 1: all fields Daniel@0: % Daniel@0: % train struct: Daniel@0: % level 1: all fields Daniel@0: % Daniel@0: % normalization struct: Daniel@0: % level 1: method, status Daniel@0: % level 2: ..., parameters Daniel@0: % Daniel@0: % REQUIRED INPUT ARGUMENTS Daniel@0: % Daniel@0: % sS (struct) SOM Toolbox struct Daniel@0: % (cell array of structs) several structs in a cell array Daniel@0: % Daniel@0: % OPTIONAL INPUT ARGUMENTS Daniel@0: % Daniel@0: % level (scalar) detail level (1-4), default = 1 Daniel@0: % Daniel@0: % EXAMPLES Daniel@0: % Daniel@0: % som_info(sM) Daniel@0: % som_info(sM,4) Daniel@0: % som_info(sM.trainhist) Daniel@0: % som_info(sM.comp_norm{3}) Daniel@0: % Daniel@0: % SEE ALSO Daniel@0: % Daniel@0: % som_set Set fields and create SOM Toolbox structs. Daniel@0: Daniel@0: % Copyright (c) 1999-2000 by the SOM toolbox programming team. Daniel@0: % http://www.cis.hut.fi/projects/somtoolbox/ Daniel@0: Daniel@0: % Version 1.0beta ecco 110997 Daniel@0: % Version 2.0beta juuso 101199 Daniel@0: Daniel@0: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Daniel@0: %% check arguments Daniel@0: Daniel@0: error(nargchk(1, 2, nargin)) % check no. of input args is correct Daniel@0: Daniel@0: if ~isstruct(sS), Daniel@0: if ~iscell(sS) | ~isstruct(sS{1}), Daniel@0: error('Invalid first input argument.') Daniel@0: end Daniel@0: csS = sS; Daniel@0: else Daniel@0: l = length(sS); Daniel@0: csS = cell(l,1); Daniel@0: for i=1:l, csS{i} = sS(i); end Daniel@0: end Daniel@0: Daniel@0: if nargin<2 | isempty(level) | isnan(level), level = 1; end Daniel@0: Daniel@0: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Daniel@0: %% print struct information Daniel@0: Daniel@0: for c=1:length(csS), Daniel@0: sS = csS{c}; Daniel@0: fprintf(1,'\n'); Daniel@0: Daniel@0: switch sS.type, Daniel@0: case 'som_map', Daniel@0: mdim = length(sS.topol.msize); Daniel@0: [munits dim] = size(sS.codebook); Daniel@0: t = length(sS.trainhist); Daniel@0: if t==0, st='uninitialized'; Daniel@0: elseif t==1, st = 'initialized'; Daniel@0: else st = sprintf('initialized, trained %d times',t-1); Daniel@0: end Daniel@0: Daniel@0: % level 1 Daniel@0: fprintf(1,'Struct type : %s\n', sS.type); Daniel@0: fprintf(1,'Map name : %s\n', sS.name); Daniel@0: fprintf(1,'Input dimension : %d\n', dim); Daniel@0: fprintf(1,'Map grid size : '); Daniel@0: for i = 1:mdim - 1, fprintf(1,'%d x ',sS.topol.msize(i)); end Daniel@0: fprintf(1,'%d\n', sS.topol.msize(mdim)); Daniel@0: fprintf(1,'Lattice type (rect/hexa) : %s\n', sS.topol.lattice); Daniel@0: fprintf(1,'Shape (sheet/cyl/toroid) : %s\n', sS.topol.shape); Daniel@0: fprintf(1,'Neighborhood type : %s\n', sS.neigh); Daniel@0: fprintf(1,'Mask : '); Daniel@0: if dim, Daniel@0: for i = 1:dim-1, fprintf(1,'%d ',sS.mask(i)); end; Daniel@0: fprintf(1,'%d\n',sS.mask(dim)); Daniel@0: else fprintf(1,'\n'); Daniel@0: end Daniel@0: fprintf(1,'Training status : %s\n', st); Daniel@0: Daniel@0: % level 1, Daniel@0: status = cell(dim,1); Daniel@0: for i=1:dim, Daniel@0: n = length(sS.comp_norm{i}); Daniel@0: if n, Daniel@0: uninit = strcmp('uninit',{sS.comp_norm{i}.status}); Daniel@0: done = strcmp('done',{sS.comp_norm{i}.status}); Daniel@0: undone = strcmp('undone',{sS.comp_norm{i}.status}); Daniel@0: if sum(uninit)==n, status{i} = 'none'; Daniel@0: elseif sum(done)==n, status{i} = 'done'; Daniel@0: elseif sum(undone)==n, status{i} = 'undone'; Daniel@0: else status{i} = 'partial'; Daniel@0: end Daniel@0: else status{i} = 'no normalization'; end Daniel@0: end Daniel@0: if level>1, Daniel@0: fprintf(1,'\nVector components\n'); Daniel@0: M = sS.codebook; Daniel@0: fprintf(1,' # name mask min mean max std normalization\n'); Daniel@0: fprintf(1,' --- ------------ ---- ------ ------ ------ ------ -------------\n'); Daniel@0: for i = 1:dim, Daniel@0: fprintf(1,' %-3d %-12s %-4.2f %6.2g %6.2g %6.2g %6.2g %s\n', ... Daniel@0: i,sS.comp_names{i}, sS.mask(i), ... Daniel@0: min(M(:,i)),mean(M(:,i)),max(M(:,i)),std(M(:,i)),status{i}); Daniel@0: end Daniel@0: end Daniel@0: Daniel@0: % level 3 Daniel@0: if level>2, Daniel@0: fprintf(1,'\nVector component normalizations\n'); Daniel@0: fprintf(1,' # name method (i=uninit,u=undone,d=done)\n'); Daniel@0: fprintf(1,' --- ------------ ---------------------------------------\n'); Daniel@0: for i=1:dim, Daniel@0: fprintf(1,' %-3d %-12s ',i,sS.comp_names{i}); Daniel@0: n = length(sS.comp_norm{i}); Daniel@0: for j=1:n, Daniel@0: m = sS.comp_norm{i}(j).method; Daniel@0: s = sS.comp_norm{i}(j).status; Daniel@0: if strcmp(s,'uninit'), c='i'; Daniel@0: elseif strcmp(s,'undone'), c='u'; Daniel@0: else c='d'; Daniel@0: end Daniel@0: fprintf(1,'%s[%s] ',m,c); Daniel@0: end Daniel@0: fprintf(1,'\n'); Daniel@0: end Daniel@0: end Daniel@0: Daniel@0: % level 4 Daniel@0: if level>3, Daniel@0: fprintf(1,'\nTraining history\n'); Daniel@0: fprintf(1,'Algorithm Data Trainlen Neigh.f. Radius Alpha (type) Date\n'); Daniel@0: fprintf(1,'--------- ------------- -------- -------- ---------- -------------- --------------------\n'); Daniel@0: for i=1:t, Daniel@0: sT = sS.trainhist(i); Daniel@0: fprintf(1,'%8s %13s %8d %8s %4.2f->%4.2f %5.3f (%6s) %s\n',... Daniel@0: sT.algorithm,sT.data_name,sT.trainlen,... Daniel@0: sT.neigh,sT.radius_ini,sT.radius_fin,sT.alpha_ini,sT.alpha_type,sT.time); Daniel@0: %for j = 1:length(sT.mask)-1, fprintf(1,'%d ',sT.mask(j)); end; Daniel@0: %if ~isempty(sT.mask), fprintf(1,'%d\n',sT.mask(end)); else fprintf(1,'\n'); end Daniel@0: end Daniel@0: end Daniel@0: Daniel@0: case 'som_data', Daniel@0: Daniel@0: [dlen dim] = size(sS.data); Daniel@0: if dlen*dim Daniel@0: if dim>1, ind = find(~isnan(sum(sS.data,2))); Daniel@0: else ind = find(~isnan(sS.data)); Daniel@0: end Daniel@0: else ind = []; end Daniel@0: complete = size(sS.data(ind,:),1); Daniel@0: partial = dlen - complete; Daniel@0: values = prod(size(sS.data)); Daniel@0: missing = sum(sum(isnan(sS.data))); Daniel@0: Daniel@0: % level 1 Daniel@0: fprintf(1,'Struct type : %s\n', sS.type); Daniel@0: fprintf(1,'Data name : %s\n', sS.name); Daniel@0: fprintf(1,'Vector dimension : %d\n', dim); Daniel@0: fprintf(1,'Number of data vectors : %d\n', dlen); Daniel@0: fprintf(1,'Complete data vectors : %d\n', complete); Daniel@0: fprintf(1,'Partial data vectors : %d\n', partial); Daniel@0: if values, r = floor(100 * (values - missing) / values); else r = 0; end Daniel@0: fprintf(1,'Complete values : %d of %d (%d%%)\n', ... Daniel@0: values-missing, values, r); Daniel@0: Daniel@0: % level 2, Daniel@0: status = cell(dim,1); Daniel@0: for i=1:dim, Daniel@0: n = length(sS.comp_norm{i}); Daniel@0: if n, Daniel@0: uninit = strcmp('uninit',{sS.comp_norm{i}.status}); Daniel@0: done = strcmp('done',{sS.comp_norm{i}.status}); Daniel@0: undone = strcmp('undone',{sS.comp_norm{i}.status}); Daniel@0: if sum(uninit)==n, status{i} = 'none'; Daniel@0: elseif sum(done)==n, status{i} = 'done'; Daniel@0: elseif sum(undone)==n, status{i} = 'undone'; Daniel@0: else status{i} = 'partial'; Daniel@0: end Daniel@0: else status{i} = 'no normalization'; end Daniel@0: end Daniel@0: if level>1, Daniel@0: fprintf(1,'\nVector components\n'); Daniel@0: D = sS.data; Daniel@0: fprintf(1,' # name min mean max std missing normalization\n'); Daniel@0: fprintf(1,' --- ------------ ------ ------ ------ ------ ----------- -------------\n'); Daniel@0: for i = 1:dim, Daniel@0: known = find(~isnan(D(:,i))); Daniel@0: miss = dlen-length(known); Daniel@0: switch length(known), Daniel@0: case 0, mi = NaN; me = NaN; ma = NaN; st = NaN; Daniel@0: case 1, mi = D(known,i); me = mi; ma = mi; st = 0; Daniel@0: otherwise, Daniel@0: mi = min(D(known,i)); ma = max(D(known,i)); Daniel@0: me = mean(D(known,i)); st = std(D(known,i)); Daniel@0: end Daniel@0: fprintf(1,' %-3d %-12s %6.2g %6.2g %6.2g %6.2g %5d (%2d%%) %s\n', ... Daniel@0: i,sS.comp_names{i},mi,me,ma,st,miss,floor(100*miss/dlen),status{i}); Daniel@0: end Daniel@0: end Daniel@0: Daniel@0: % level 3 Daniel@0: if level>2, Daniel@0: fprintf(1,'\nVector component normalizations\n'); Daniel@0: fprintf(1,' # name method (i=uninit,u=undone,d=done)\n'); Daniel@0: fprintf(1,' --- ------------ ---------------------------------------\n'); Daniel@0: for i=1:dim, Daniel@0: fprintf(1,' %-3d %-12s ',i,sS.comp_names{i}); Daniel@0: n = length(sS.comp_norm{i}); Daniel@0: for j=1:n, Daniel@0: m = sS.comp_norm{i}(j).method; Daniel@0: s = sS.comp_norm{i}(j).status; Daniel@0: if strcmp(s,'uninit'), c='i'; Daniel@0: elseif strcmp(s,'undone'), c='u'; Daniel@0: else c='d'; Daniel@0: end Daniel@0: fprintf(1,'%s[%s] ',m,c); Daniel@0: end Daniel@0: fprintf(1,'\n'); Daniel@0: end Daniel@0: end Daniel@0: Daniel@0: % level 4 Daniel@0: if level>3, Daniel@0: m = size(sS.labels,2); Daniel@0: fprintf(1,'\nLabels\n'); Daniel@0: if isempty(sS.label_names), Daniel@0: labs = {''}; freq = 0; Daniel@0: for i=1:dlen*m, Daniel@0: l = sS.labels{i}; Daniel@0: if isempty(l), freq(1) = freq(1)+1; Daniel@0: else Daniel@0: k = find(strcmp(labs,l)); Daniel@0: if isempty(k), labs{end+1} = l; freq(end+1) = 1; Daniel@0: else freq(k)=freq(k)+1; Daniel@0: end Daniel@0: end Daniel@0: end Daniel@0: emp = freq(1); Daniel@0: uni = length(freq)-1; Daniel@0: if uni>0, tot = sum(freq(2:end)); else tot = 0; end Daniel@0: fprintf(1,' Total: %d\n Empty: %d\n Unique: %d\n',tot,emp,uni); Daniel@0: else Daniel@0: for j=1:m, Daniel@0: labs = {''}; freq = 0; Daniel@0: for i=1:dlen, Daniel@0: l = sS.labels{i,j}; Daniel@0: if isempty(l), freq(1) = freq(1)+1; Daniel@0: else Daniel@0: k = find(strcmp(labs,l)); Daniel@0: if isempty(k), labs{end+1} = l; freq(end+1) = 1; Daniel@0: else freq(k)=freq(k)+1; Daniel@0: end Daniel@0: end Daniel@0: end Daniel@0: emp = freq(1); Daniel@0: uni = length(freq)-1; Daniel@0: if uni>0, tot = sum(freq(2:end)); else tot = 0; end Daniel@0: fprintf(1,' [%s] Total / empty / unique: %d / %d / %d\n', ... Daniel@0: sS.label_names{j},tot,emp,uni); Daniel@0: end Daniel@0: end Daniel@0: end Daniel@0: Daniel@0: case 'som_topol', Daniel@0: Daniel@0: mdim = length(sS.msize); Daniel@0: Daniel@0: % level 1 Daniel@0: fprintf(1,'Struct type : %s\n',sS.type); Daniel@0: fprintf(1,'Map grid size : '); Daniel@0: for i = 1:mdim - 1, fprintf(1,'%d x ',sS.msize(i)); end Daniel@0: fprintf(1,'%d\n', sS.msize(mdim)); Daniel@0: fprintf(1,'Lattice type (rect/hexa) : %s\n', sS.lattice); Daniel@0: fprintf(1,'Shape (sheet/cyl/toroid) : %s\n', sS.shape); Daniel@0: Daniel@0: case 'som_train', Daniel@0: Daniel@0: % level 1 Daniel@0: fprintf(1,'Struct type : %s\n',sS.type); Daniel@0: fprintf(1,'Training algorithm : %s\n',sS.algorithm); Daniel@0: fprintf(1,'Training data : %s\n',sS.data_name); Daniel@0: fprintf(1,'Neighborhood function : %s\n',sS.neigh); Daniel@0: fprintf(1,'Mask : '); Daniel@0: dim = length(sS.mask); Daniel@0: if dim, Daniel@0: for i = 1:dim-1, fprintf(1,'%d ',sS.mask(i)); end; Daniel@0: fprintf(1,'%d\n',sS.mask(end)); Daniel@0: else fprintf(1,'\n'); end Daniel@0: fprintf(1,'Initial radius : %-6.1f\n',sS.radius_ini); Daniel@0: fprintf(1,'Final radius : %-6.1f\n',sS.radius_fin); Daniel@0: fprintf(1,'Initial learning rate (alpha) : %-6.1f\n',sS.alpha_ini); Daniel@0: fprintf(1,'Alpha function type (linear/inv) : %s\n',sS.alpha_type); Daniel@0: fprintf(1,'Training length : %d\n',sS.trainlen); Daniel@0: fprintf(1,'When training was done : %s\n',sS.time); Daniel@0: Daniel@0: case 'som_norm', Daniel@0: Daniel@0: % level 1 Daniel@0: fprintf(1,'Struct type : %s\n',sS.type); Daniel@0: fprintf(1,'Normalization method : %s\n',sS.method); Daniel@0: fprintf(1,'Status : %s\n',sS.status); Daniel@0: Daniel@0: % level 2 Daniel@0: if level>1, Daniel@0: fprintf(1,'Parameters:\n'); Daniel@0: sS.params Daniel@0: end Daniel@0: Daniel@0: case 'som_grid', Daniel@0: Daniel@0: % level 1 Daniel@0: fprintf(1,'Struct type : %s\n',sS.type); Daniel@0: if ischar(sS.neigh), Daniel@0: fprintf(1,'Connections : [%d %d], %s, %s\n',... Daniel@0: sS.msize(1),sS.msize(2),sS.neigh,sS.shape); Daniel@0: else Daniel@0: fprintf(1,'Connections : [%d %d] %d lines\n',... Daniel@0: sS.msize(1),sS.msize(2),sum(sS.neigh)); Daniel@0: end Daniel@0: fprintf(1,'Line : %s\n',sS.line); Daniel@0: if length(sS.marker)==1, Daniel@0: fprintf(1,'Marker : %s\n',sS.marker); Daniel@0: else Daniel@0: fprintf(1,'Marker : varies\n'); Daniel@0: end Daniel@0: fprintf(1,'Surf : '); Daniel@0: if isempty(sS.surf), fprintf(1,'off\n'); else fprintf(1,'on\n'); end Daniel@0: fprintf(1,'Labels : '); Daniel@0: if isempty(sS.label), fprintf(1,'off\n'); Daniel@0: else fprintf(1,'on (%d)\n',sS.labelsize); end Daniel@0: Daniel@0: end Daniel@0: Daniel@0: fprintf(1,'\n'); Daniel@0: end Daniel@0: Daniel@0: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%