📄 demosm1.html
字号:
<!--This HTML is auto-generated from an m-file.Your changes will be overwritten.--><p xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd" style="color:#990000; font-weight:bold; font-size:x-large">A One-dimensional Self-organizing Map</p><p xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd">Neurons in a 2-D layer learn to represent different regions of the input spacewhere input vectors occur. In addition, neighboring neurons learn to respondto similar inputs, thus the layer learns the topology of the presented inputspace.</p><p xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd">Copyright 1992-2002 The MathWorks, Inc.$Revision: 1.20 $ $Date: 2002/03/29 19:36:03 $</p><p xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd" style="color:#990000; font-weight:bold; font-size:medium; page-break-before: auto;"><a name=""></a></p><p xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd">Here 100 data points are created on the unit circle.</p><p xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd">A competitive network will be used to classify these points into naturalclasses.</p><pre xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd" style="position: relative; left:30px">angles = 0:0.5*pi/99:0.5*pi;P = [sin(angles); cos(angles)];plot(P(1,:),P(2,:),<span style="color:#B20000">'+r'</span>)</pre><img xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd" src="demosm1_img02.gif"><p xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd" style="color:#990000; font-weight:bold; font-size:medium; page-break-before: auto;"><a name=""></a></p><p xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd">The map will be a 1-dimensional layer of 10 neurons.</p><p xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd">The first argument specifies two inputs, each with a range of 0 to 1. Thesecond determines the network is one dimensional with 10 neurons.</p><pre xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd" style="position: relative; left:30px">net = newsom([0 1;0 1],[10]);</pre><p xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd" style="color:#990000; font-weight:bold; font-size:medium; page-break-before: auto;"><a name=""></a></p><p xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd">Specify the network is to be trained for 10 epochs and use TRAIN to train thenetwork on the input data P:</p><pre xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd" style="position: relative; left:30px">net.trainParam.epochs = 10;net = train(net,P);</pre><pre xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd" style="color:gray; font-style:italic;">TRAINR, Epoch 0/10TRAINR, Epoch 10/10TRAINR, Maximum epoch reached.</pre><p xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd" style="color:#990000; font-weight:bold; font-size:medium; page-break-before: auto;"><a name=""></a></p><p xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd">Now plot the trained network with PLOTSOM.</p><p xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd">The red dots are the neuron's weight vectors, and the blue lines connect eachpair within a distance of 1.</p><pre xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd" style="position: relative; left:30px">plotsom(net.iw{1,1},net.layers{1}.distances)</pre><img xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd" src="demosm1_img05.gif"><p xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd" style="color:#990000; font-weight:bold; font-size:medium; page-break-before: auto;"><a name=""></a></p><p xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd">The map can now be used to classify inputs, like [1; 0]:</p><p xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd">Either neuron 1 or 10 should have an output of 1, as the above input vectorwas at one end of the presented input space. The first pair of numbersindicate the neuron, and the single number indicates its output.</p><pre xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd" style="position: relative; left:30px">p = [1;0];a = sim(net,p)</pre><pre xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd" style="color:gray; font-style:italic;">a = (1,1) 1</pre><originalCode xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd" code="%% A One-dimensional Self-organizing Map
% Neurons in a 2-D layer learn to represent different regions of the input space
% where input vectors occur. In addition, neighboring neurons learn to respond
% to similar inputs, thus the layer learns the topology of the presented input
% space.
%
% Copyright 1992-2002 The MathWorks, Inc.
% $Revision: 1.20 $ $Date: 2002/03/29 19:36:03 $

%%
% Here 100 data points are created on the unit circle.
%
% A competitive network will be used to classify these points into natural
% classes.

angles = 0:0.5*pi/99:0.5*pi;
P = [sin(angles); cos(angles)];
plot(P(1,:),P(2,:),'+r')

%%
% The map will be a 1-dimensional layer of 10 neurons.
%
% The first argument specifies two inputs, each with a range of 0 to 1. The
% second determines the network is one dimensional with 10 neurons.

net = newsom([0 1;0 1],[10]);

%%
% Specify the network is to be trained for 10 epochs and use TRAIN to train the
% network on the input data P:

net.trainParam.epochs = 10;
net = train(net,P);

%%
% Now plot the trained network with PLOTSOM.
% 
% The red dots are the neuron's weight vectors, and the blue lines connect each
% pair within a distance of 1.

plotsom(net.iw{1,1},net.layers{1}.distances)

%%
% The map can now be used to classify inputs, like [1; 0]:
%
% Either neuron 1 or 10 should have an output of 1, as the above input vector
% was at one end of the presented input space. The first pair of numbers
% indicate the neuron, and the single number indicates its output.

p = [1;0];
a = sim(net,p)
"></originalCode>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -