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

📄 demogrn1.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">GRNN Function Approximation</p><p xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd">This demonstration uses functions NEWGRNN and SIM.</p><p xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd">Copyright 1992-2002 The MathWorks, Inc.$Revision: 1.7 $  $Date: 2002/03/29 19:36:24 $</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 are eight data points of a function we would like to fit.  The functionsinputs P should result in target outputs T.</p><pre xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd" style="position: relative; left:30px">P = [1 2 3 4 5 6 7 8];T = [0 1 2 3 2 1 2 1];plot(P,T,<span style="color:#B20000">'.'</span>,<span style="color:#B20000">'markersize'</span>,30)axis([0 9 -1 4])title(<span style="color:#B20000">'Function to approximate.'</span>)xlabel(<span style="color:#B20000">'P'</span>)ylabel(<span style="color:#B20000">'T'</span>)</pre><img xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd" src="demogrn1_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">We use NEWGRNN to create a generalized regression network.  We use a SPREADslightly lower than 1, the distance between input values, in order, to get afunction that fits individual data points fairly closely.  A smaller spreadwould fit data better but be less smooth.</p><pre xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd" style="position: relative; left:30px">spread = 0.7;net = newgrnn(P,T,spread);A = sim(net,P);hold onoutputline = plot(P,A,<span style="color:#B20000">'.'</span>,<span style="color:#B20000">'markersize'</span>,30,<span style="color:#B20000">'color'</span>,[1 0 0]);title(<span style="color:#B20000">'Create and test a network.'</span>)xlabel(<span style="color:#B20000">'P'</span>)ylabel(<span style="color:#B20000">'T and A'</span>)</pre><img xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd" src="demogrn1_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">We can use the network to approximate the function at a new input value.</p><pre xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd" style="position: relative; left:30px">p = 3.5;a = sim(net,p);plot(p,a,<span style="color:#B20000">'.'</span>,<span style="color:#B20000">'markersize'</span>,30,<span style="color:#B20000">'color'</span>,[1 0 0]);title(<span style="color:#B20000">'New input value.'</span>)xlabel(<span style="color:#B20000">'P and p'</span>)ylabel(<span style="color:#B20000">'T and a'</span>)</pre><img xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd" src="demogrn1_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">Here the network's response is simulated for many values, allowing us to seethe function it represents.</p><pre xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd" style="position: relative; left:30px">P2 = 0:.1:9;A2 = sim(net,P2);plot(P2,A2,<span style="color:#B20000">'linewidth'</span>,4,<span style="color:#B20000">'color'</span>,[1 0 0])title(<span style="color:#B20000">'Function to approximate.'</span>)xlabel(<span style="color:#B20000">'P and P2'</span>)ylabel(<span style="color:#B20000">'T and A2'</span>)</pre><img xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd" src="demogrn1_img05.gif"><originalCode xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd" code="%% GRNN Function Approximation&#xA;% This demonstration uses functions NEWGRNN and SIM.&#xA;%&#xA;% Copyright 1992-2002 The MathWorks, Inc.&#xA;% $Revision: 1.7 $  $Date: 2002/03/29 19:36:24 $&#xA;&#xA;%%&#xA;% Here are eight data points of a function we would like to fit.  The functions&#xA;% inputs P should result in target outputs T.&#xA;&#xA;P = [1 2 3 4 5 6 7 8];&#xA;T = [0 1 2 3 2 1 2 1];&#xA;&#xA;plot(P,T,'.','markersize',30)&#xA;axis([0 9 -1 4])&#xA;title('Function to approximate.')&#xA;xlabel('P')&#xA;ylabel('T')&#xA;&#xA;&#xA;%%&#xA;% We use NEWGRNN to create a generalized regression network.  We use a SPREAD&#xA;% slightly lower than 1, the distance between input values, in order, to get a&#xA;% function that fits individual data points fairly closely.  A smaller spread&#xA;% would fit data better but be less smooth.&#xA;&#xA;spread = 0.7;&#xA;net = newgrnn(P,T,spread);&#xA;A = sim(net,P);&#xA;&#xA;hold on&#xA;outputline = plot(P,A,'.','markersize',30,'color',[1 0 0]);&#xA;title('Create and test a network.')&#xA;xlabel('P')&#xA;ylabel('T and A')&#xA;&#xA;%%&#xA;% We can use the network to approximate the function at a new input value.&#xA;&#xA;p = 3.5;&#xA;a = sim(net,p);&#xA;plot(p,a,'.','markersize',30,'color',[1 0 0]);&#xA;title('New input value.')&#xA;xlabel('P and p')&#xA;ylabel('T and a')&#xA;&#xA;&#xA;%%&#xA;% Here the network's response is simulated for many values, allowing us to see&#xA;% the function it represents.&#xA;&#xA;P2 = 0:.1:9;&#xA;A2 = sim(net,P2);&#xA;plot(P2,A2,'linewidth',4,'color',[1 0 0])&#xA;title('Function to approximate.')&#xA;xlabel('P and P2')&#xA;ylabel('T and A2')&#xA;"></originalCode>

⌨️ 快捷键说明

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