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

📄 demohop3.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">A Three Neuron Hopfield Network</p><p xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd">A Hopfield network is designed with target stable points. The behavior of theHopfield network for different initial conditions is studied.</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:21 $</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">We would like to obtain a Hopfield network that has the two stable pointsdefined by the two target (column) vectors in T.</p><pre xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd" style="position: relative; left:30px"> T = [+1 +1; <span style="color:blue">...</span>      -1 +1; <span style="color:blue">...</span>      -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">Here is a plot where the stable points are shown at the corners.  All possiblestates of the 2-neuron Hopfield network are contained within the plotsboundaries.</p><pre xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd" style="position: relative; left:30px">axis([-1 1 -1 1 -1 1])set(gca,<span style="color:#B20000">'box'</span>,<span style="color:#B20000">'on'</span>); axis manual;  hold on;plot3(T(1,:),T(2,:),T(3,:),<span style="color:#B20000">'r*'</span>)title(<span style="color:#B20000">'Hopfield Network State Space'</span>)xlabel(<span style="color:#B20000">'a(1)'</span>);ylabel(<span style="color:#B20000">'a(2)'</span>);zlabel(<span style="color:#B20000">'a(3)'</span>);view([37.5 30]);</pre><img xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd" src="demohop3_img03.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 function NEWHOP creates Hopfield networks given the stable points T.</p><pre xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd" style="position: relative; left:30px">net = newhop(T);</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">Here we define a random starting point and simulate the Hopfield network for50 steps.  It should reach one of its stable points.</p><pre xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd" style="position: relative; left:30px">a = {rands(3,1)};[y,Pf,Af] = sim(net,{1 10},{},a);</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">We can make a plot of the Hopfield networks activity.</p><p xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd">Sure enough, the network ends up at a designed stable point in the corner.</p><pre xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd" style="position: relative; left:30px">record = [cell2mat(a) cell2mat(y)];start = cell2mat(a);hold onplot3(start(1,1),start(2,1),start(3,1),<span style="color:#B20000">'bx'</span>, <span style="color:blue">...</span>   record(1,:),record(2,:),record(3,:))</pre><img xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd" src="demohop3_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">We repeat the simulation for 25 more randomly generated initial conditions.</p><pre xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd" style="position: relative; left:30px">color = <span style="color:#B20000">'rgbmy'</span>;<span style="color:blue">for</span> i=1:25   a = {rands(3,1)};   [y,Pf,Af] = sim(net,{1 10},{},a);   record=[cell2mat(a) cell2mat(y)];   start=cell2mat(a);   plot3(start(1,1),start(2,1),start(3,1),<span style="color:#B20000">'kx'</span>, <span style="color:blue">...</span>      record(1,:),record(2,:),record(3,:),color(rem(i,5)+1))<span style="color:blue">end</span></pre><img xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd" src="demohop3_img07.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 we simulate the Hopfield for the following initial conditions, each acolumn vector of P.</p><p xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd">These points were exactly between the two target stable points.  The result isthat they all move into the center of the state space, where an undesiredstable point exists.</p><pre xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd" style="position: relative; left:30px">P = [ 1.0  -1.0  -0.5  1.00  1.00  0.0; <span style="color:blue">...</span>      0.0   0.0   0.0  0.00  0.00 -0.0; <span style="color:blue">...</span>     -1.0   1.0   0.5 -1.01 -1.00  0.0];claplot3(T(1,:),T(2,:),T(3,:),<span style="color:#B20000">'r*'</span>)color = <span style="color:#B20000">'rgbmy'</span>;<span style="color:blue">for</span> i=1:6   a = {P(:,i)};   [y,Pf,Af] = sim(net,{1 10},{},a);   record=[cell2mat(a) cell2mat(y)];   start=cell2mat(a);   plot3(start(1,1),start(2,1),start(3,1),<span style="color:#B20000">'kx'</span>, <span style="color:blue">...</span>      record(1,:),record(2,:),record(3,:),color(rem(i,5)+1))<span style="color:blue">end</span></pre><img xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd" src="demohop3_img08.gif"><originalCode xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd" code="%% A Three Neuron Hopfield Network&#xA;% A Hopfield network is designed with target stable points. The behavior of the&#xA;% Hopfield network for different initial conditions is studied.&#xA;% &#xA;% Copyright 1992-2002 The MathWorks, Inc.&#xA;% $Revision: 1.16 $  $Date: 2002/03/29 19:36:21 $&#xA;&#xA;%%&#xA;% We would like to obtain a Hopfield network that has the two stable points&#xA;% defined by the two target (column) vectors in T.&#xA; T = [+1 +1; ...&#xA;      -1 +1; ...&#xA;      -1 -1];&#xA;&#xA;%%&#xA;% Here is a plot where the stable points are shown at the corners.  All possible&#xA;% states of the 2-neuron Hopfield network are contained within the plots&#xA;% boundaries.&#xA;&#xA;axis([-1 1 -1 1 -1 1])&#xA;set(gca,'box','on'); axis manual;  hold on;&#xA;plot3(T(1,:),T(2,:),T(3,:),'r*')&#xA;title('Hopfield Network State Space')&#xA;xlabel('a(1)');&#xA;ylabel('a(2)');&#xA;zlabel('a(3)');&#xA;view([37.5 30]);&#xA;&#xA;%%&#xA;% The function NEWHOP creates Hopfield networks given the stable points T.&#xA;&#xA;net = newhop(T);&#xA;&#xA;%%&#xA;% Here we define a random starting point and simulate the Hopfield network for&#xA;% 50 steps.  It should reach one of its stable points.&#xA;&#xA;a = {rands(3,1)};&#xA;[y,Pf,Af] = sim(net,{1 10},{},a);&#xA;&#xA;&#xA;%%&#xA;% We can make a plot of the Hopfield networks activity.&#xA;% &#xA;% Sure enough, the network ends up at a designed stable point in the corner.&#xA;&#xA;record = [cell2mat(a) cell2mat(y)];&#xA;start = cell2mat(a);&#xA;hold on&#xA;plot3(start(1,1),start(2,1),start(3,1),'bx', ...&#xA;   record(1,:),record(2,:),record(3,:))&#xA;&#xA;&#xA;%%&#xA;% We repeat the simulation for 25 more randomly generated initial conditions.&#xA;&#xA;color = 'rgbmy';&#xA;for i=1:25&#xA;   a = {rands(3,1)};&#xA;   [y,Pf,Af] = sim(net,{1 10},{},a);&#xA;   record=[cell2mat(a) cell2mat(y)];&#xA;   start=cell2mat(a);&#xA;   plot3(start(1,1),start(2,1),start(3,1),'kx', ...&#xA;      record(1,:),record(2,:),record(3,:),color(rem(i,5)+1))&#xA;end&#xA;&#xA;&#xA;%%&#xA;% Now we simulate the Hopfield for the following initial conditions, each a&#xA;% column vector of P.&#xA;%&#xA;% These points were exactly between the two target stable points.  The result is&#xA;% that they all move into the center of the state space, where an undesired&#xA;% stable point exists.&#xA;&#xA;P = [ 1.0  -1.0  -0.5  1.00  1.00  0.0; ...&#xA;      0.0   0.0   0.0  0.00  0.00 -0.0; ...&#xA;     -1.0   1.0   0.5 -1.01 -1.00  0.0];&#xA;cla&#xA;plot3(T(1,:),T(2,:),T(3,:),'r*')&#xA;color = 'rgbmy';&#xA;for i=1:6&#xA;   a = {P(:,i)};&#xA;   [y,Pf,Af] = sim(net,{1 10},{},a);&#xA;   record=[cell2mat(a) cell2mat(y)];&#xA;   start=cell2mat(a);&#xA;   plot3(start(1,1),start(2,1),start(3,1),'kx', ...&#xA;      record(1,:),record(2,:),record(3,:),color(rem(i,5)+1))&#xA;end&#xA;&#xA;&#xA;"></originalCode>

⌨️ 快捷键说明

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