%SOM_DEMO2 Basic usage of the SOM Toolbox. % Contributed to SOM Toolbox 2.0, February 11th, 2000 by Juha Vesanto % http://www.cis.hut.fi/projects/somtoolbox/ % Version 1.0beta juuso 071197 % Version 2.0beta juuso 070200 clf reset; figure(gcf) echo on clc % ========================================================== % SOM_DEMO2 - BASIC USAGE OF SOM TOOLBOX % ========================================================== % som_data_struct - Create a data struct. % som_read_data - Read data from file. % % som_normalize - Normalize data. % som_denormalize - Denormalize data. % % som_make - Initialize and train the map. % % som_show - Visualize map. % som_show_add - Add markers on som_show visualization. % som_grid - Visualization with free coordinates. % % som_autolabel - Give labels to map. % som_hits - Calculate hit histogram for the map. % BASIC USAGE OF THE SOM TOOLBOX % The basic usage of the SOM Toolbox proceeds like this: % 1. construct data set % 2. normalize it % 3. train the map % 4. visualize map % 5. analyse results % The four first items are - if default options are used - very % simple operations, each executable with a single command. For % the last, several different kinds of functions are provided in % the Toolbox, but as the needs of analysis vary, a general default % function or procedure does not exist. pause % Strike any key to construct data... clc % STEP 1: CONSTRUCT DATA % ====================== % The SOM Toolbox has a special struct, called data struct, which % is used to group information regarding the data set in one % place. % Here, a data struct is created using function SOM_DATA_STRUCT. % First argument is the data matrix itself, then is the name % given to the data set, and the names of the components % (variables) in the data matrix. D = rand(1000,3); % 1000 samples from unit cube sData = som_data_struct(D,'name','unit cube','comp_names',{'x','y','z'}); % Another option is to read the data directly from an ASCII file. % Here, the IRIS data set is loaded from a file (please make sure % the file can be found from the current path): try, sDiris = som_read_data('iris.data'); catch echo off warning('File ''iris.data'' not found. Using simulated data instead.') D = randn(50,4); D(:,1) = D(:,1)+5; D(:,2) = D(:,2)+3.5; D(:,3) = D(:,3)/2+1.5; D(:,4) = D(:,4)/2+0.3; D(find(D(:)<=0)) = 0.01; D2 = randn(100,4); D2(:,2) = sort(D2(:,2)); D2(:,1) = D2(:,1)+6.5; D2(:,2) = D2(:,2)+2.8; D2(:,3) = D2(:,3)+5; D2(:,4) = D2(:,4)/2+1.5; D2(find(D2(:)<=0)) = 0.01; sDiris = som_data_struct([D; D2],'name','iris (simulated)',... 'comp_names',{'SepalL','SepalW','PetalL','PetalW'}); sDiris = som_label(sDiris,'add',[1:50]','Setosa'); sDiris = som_label(sDiris,'add',[51:100]','Versicolor'); sDiris = som_label(sDiris,'add',[101:150]','Virginica'); echo on end % Here are the histograms and scatter plots of the four variables. echo off k=1; for i=1:4, for j=1:4, if i==j, subplot(4,4,k); hist(sDiris.data(:,i)); title(sDiris.comp_names{i}) elseif i