⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 demop1.html

📁 神经网络学习过程的实例程序
💻 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">Classification with a 2-input Perceptron</p><p xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd">A 2-input hard limit neuron is trained to classify 5 input vectors into twocategories.</p><p xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd">Copyright 1992-2002 The MathWorks, Inc.$Revision: 1.16 $  $Date: 2002/03/29 19:36:11 $</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">Each of the five column vectors in P defines a 2-element input vectors and arow vector T defines the vector's target categories.  We can plot thesevectors with PLOTPV.</p><pre xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd" style="position: relative; left:30px">P = [ -0.5 -0.5 +0.3 -0.1;  <span style="color:blue">...</span>      -0.5 +0.5 -0.5 +1.0];T = [1 1 0 0];plotpv(P,T);</pre><img xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd" src="demop1_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 perceptron must properly classify the 5 input vectors in P into the twocategories defined by T.  Perceptrons have HARDLIM neurons.  These neurons arecapable of separating an input space with a straight line into two categories(0 and 1).</p><p xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd">NEWP creates a network object and configures it as a perceptron. The firstargument specifies the expected ranges of two inputs.  The second determinesthat there is only one neuron in the layer.</p><pre xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd" style="position: relative; left:30px">net = newp([-1 1;-1 1],1);</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">The input vectors are replotted with the neuron's initial attempt atclassification.</p><p xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd">The initial weights are set to zero, so any input gives the same output andthe classification line does not even appear on the plot.  Fear not... we aregoing to train it!</p><pre xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd" style="position: relative; left:30px">plotpv(P,T);plotpc(net.IW{1},net.b{1});</pre><img xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd" src="demop1_img04.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">ADAPT returns a new network object that performs as a better classifier, thenetwork output, and the error.</p><pre xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd" style="position: relative; left:30px">net.adaptParam.passes = 3;net = adapt(net,P,T);plotpc(net.IW{1},net.b{1});</pre><img xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd" src="demop1_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">Now SIM is used to classify any other input vector, like [0.7; 1.2]. A plot ofthis new point with the original training set shows how the network performs.To distinguish it from the training set, color it red.</p><pre xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd" style="position: relative; left:30px">p = [0.7; 1.2];a = sim(net,p);plotpv(p,a);point = findobj(gca,<span style="color:#B20000">'type'</span>,<span style="color:#B20000">'line'</span>);set(point,<span style="color:#B20000">'Color'</span>,<span style="color:#B20000">'red'</span>);</pre><img xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd" src="demop1_img06.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">Turn on "hold" so the previous plot is not erased and plot the training setand the classification line.</p><p xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd">The perceptron correctly classified our new point (in red) as category "zero"(represented by a circle) and not a "one" (represented by a plus).</p><pre xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd" style="position: relative; left:30px">hold on;plotpv(P,T);plotpc(net.IW{1},net.b{1});hold off;</pre><img xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd" src="demop1_img07.gif"><originalCode xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd" code="%% Classification with a 2-input Perceptron&#xA;% A 2-input hard limit neuron is trained to classify 5 input vectors into two&#xA;% categories.&#xA;%&#xA;% Copyright 1992-2002 The MathWorks, Inc.&#xA;% $Revision: 1.16 $  $Date: 2002/03/29 19:36:11 $&#xA;&#xA;%%&#xA;% Each of the five column vectors in P defines a 2-element input vectors and a&#xA;% row vector T defines the vector's target categories.  We can plot these&#xA;% vectors with PLOTPV.&#xA;&#xA;P = [ -0.5 -0.5 +0.3 -0.1;  ...&#xA;      -0.5 +0.5 -0.5 +1.0];&#xA;T = [1 1 0 0];&#xA;plotpv(P,T);&#xA;&#xA;%%&#xA;% The perceptron must properly classify the 5 input vectors in P into the two&#xA;% categories defined by T.  Perceptrons have HARDLIM neurons.  These neurons are&#xA;% capable of separating an input space with a straight line into two categories&#xA;% (0 and 1).&#xA;%&#xA;% NEWP creates a network object and configures it as a perceptron. The first&#xA;% argument specifies the expected ranges of two inputs.  The second determines&#xA;% that there is only one neuron in the layer.&#xA;&#xA;net = newp([-1 1;-1 1],1);&#xA;&#xA;%%&#xA;% The input vectors are replotted with the neuron's initial attempt at&#xA;% classification.&#xA;%&#xA;% The initial weights are set to zero, so any input gives the same output and&#xA;% the classification line does not even appear on the plot.  Fear not... we are&#xA;% going to train it!&#xA;&#xA;plotpv(P,T);&#xA;plotpc(net.IW{1},net.b{1});&#xA;&#xA;%%&#xA;% ADAPT returns a new network object that performs as a better classifier, the&#xA;% network output, and the error.&#xA;&#xA;net.adaptParam.passes = 3;&#xA;net = adapt(net,P,T);&#xA;plotpc(net.IW{1},net.b{1});&#xA;&#xA;%%&#xA;% Now SIM is used to classify any other input vector, like [0.7; 1.2]. A plot of&#xA;% this new point with the original training set shows how the network performs.&#xA;% To distinguish it from the training set, color it red.&#xA;&#xA;p = [0.7; 1.2];&#xA;a = sim(net,p);&#xA;plotpv(p,a);&#xA;point = findobj(gca,'type','line');&#xA;set(point,'Color','red');&#xA;&#xA;%%&#xA;% Turn on &#34;hold&#34; so the previous plot is not erased and plot the training set&#xA;% and the classification line.&#xA;%&#xA;% The perceptron correctly classified our new point (in red) as category &#34;zero&#34;&#xA;% (represented by a circle) and not a &#34;one&#34; (represented by a plus).&#xA;&#xA;hold on;&#xA;plotpv(P,T);&#xA;plotpc(net.IW{1},net.b{1});&#xA;hold off;&#xA;"></originalCode>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -