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