function slide=demolvq1 % This is a slideshow file for use with playshow.m and makeshow.m % To see it run, type 'playshow demolvq1', % Copyright (c) 1992-1998 by The MathWorks, Inc. % $Revision: 1.10 $ $Date: 1998/06/11 16:23:43 $ if nargout<1, playshow demolvq1 else %========== Slide 1 ========== slide(1).code={ 'slideData=nnslides(''start'',slideData,''Pattern Classification with a Learning Vector Quantization'');' }; slide(1).text={ 'NEWLVQ - Creates a LVQ network.', 'TRAIN - Trains a neural network.', 'SIM - Simulates a neural network.', '', 'An LVQ network is trained to classify input vectors according to given targets'}; %========== Slide 2 ========== slide(2).code={ 'slideData=nnslides(''blank'',slideData);', 'P = [-3 -2 -2 0 0 0 0 +2 +2 +3; 0 +1 -1 +2 +1 -1 -2 +1 -1 0];', ' C = [1 1 1 2 2 2 2 1 1 1];', 'T = ind2vec(C);' }; slide(2).text={ 'Here are 10 2-element example input vectors.', '>> P = [-3 -2 -2 0 0 0 0 +2 +2 +3;', ' 0 +1 -1 +2 +1 -1 -2 +1 -1 0];', 'Here are the classes these vectors fall into.', '>> C = [1 1 1 2 2 2 2 1 1 1];', 'These classes can be transformed into vectors to be used as targets for the LVQ network.', '>> T = ind2vec(C);', ''}; %========== Slide 3 ========== slide(3).code={ 'slideData=nnslides(''axes'',slideData);', 'colormap(hsv)', 'plotvec(P,C)', 'title(''Input Vectors'');', 'xlabel(''P(1)'');', 'ylabel(''P(2)'');', '' }; slide(3).text={ 'Here the data points are plotted.', '>> colormap(hsv)', '>> plotvec(P,C)', '>> title(''Input Vectors''); xlabel(''P(1)''); ylabel(''P(2)'');', 'Red = class 1, Cyan = class 2. The LVQ network represents clusters of vectors with hidden neurons, and groups the clusters with output neurons to form the desired classes.', '', ''}; %========== Slide 4 ========== slide(4).code={ 'net = newlvq(minmax(P),4,[.6 .4],0.1);', '' }; slide(4).text={ 'NEWLVQ creates an LVQ layer and here takes four arguments:', '>> net = newlvq(minmax(P),4,[.6 .4],0.1);', '1) Rx2 matrix of min and max values for R input elements', '2) number of hidden neurons', '3) element vector of typical class percentages', '4) learning rate', ''}; %========== Slide 5 ========== slide(5).code={ 'cla;', 'plotvec(P,C)', 'hold on', 'W1=net.IW{1};', 'plot(W1(1,1),W1(1,2),''ow'')', 'title(''Input/Weight Vectors'');', 'xlabel(''P(1), W(1)'');', 'ylabel(''P(2), W(3)'');', 'hold off;' }; slide(5).text={ 'The competitive neuron weight vectors are plotted as follows:', '>> hold on', '>> W=net.IW{1};', '>> plot(W(1,1),W(1,2),''ow'')', '>> title(''Input/Weight Vectors'');', '>> xlabel(''P(1), W(1)''); ylabel(''P(2), W(3)'');', ''}; %========== Slide 6 ========== slide(6).code={ 'slideData=nnslides(''lock'',slideData);', 'cla;', 'plotvec(P,C);', 'hold on;', 'net.trainParam.epochs=150;', 'net.trainParam.show=Inf;', 'net=train(net,P,T);', 'plotvec(net.IW{1}'',vec2ind(net.LW{2}),''o'');', 'slideData=nnslides(''unlock'',slideData);' }; slide(6).text={ 'To train the network, first override the default number of epochs:', '>> net.trainParam.epochs=150;', 'Then begin training. It may take several seconds, so please wait:', '>> net=train(net,P,T);', 'Replot the input vectors ''+'' and the competitive neurons'' weight vectors ''o''.', 'Red = class 1, Cyan = class 2.', '>> plotvec(P,C); hold on;', '>> plotvec(net.IW{1}'',vec2ind(net.LW{2}),''o'');'}; %========== Slide 7 ========== slide(7).code={ 'p = [0.2; 1];', 'a = vec2ind(sim(net,p));', '' }; slide(7).text={ 'Now use the LVQ network as a classifier, where each neuron corresponds to a different category. Present the input vector [0.2; 1].', '', '>> p = [0.2; 1];', '>> a = vec2ind(sim(net,p))', 'a =', ' 2', 'Red = class 1, Cyan = class 2.', ''}; end