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