资源描述:
《bp神经网络matlab实例(bp神经网络matlab实例)》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、bp神经网络matlab实例(bp神经网络matlab实例)Case1trainingBPnetworkbymomentumgradientdescentalgorithm.Trainingsamplesaredefinedasfollows:InputvectorasP=[-1-231-115-3]Thetargetvectorist=[-1-111]Solution:theMATLABprogramofthisexampleisasfollows:CloseallClearEchoonCLC%NEWFF-generatinganewfeedforw
2、ardneuralnetwork%TRAIN--trainingBPneuralnetwork%SIM--SimulationofBPneuralnetworkPauseStartbyhittinganykeyCLCPercentdefinestrainingsamples%PasinputvectorP=[-1,-2,3,1;-1,1,5,-3];%TisthetargetvectorT=[-1,-1,1,1];Pause;CLC%createanewfeedforwardneuralnetworkNet=newff(minmax(P),[3,1],
3、{'tansig','purelin'},'traingdm')ThecurrentinputlayerweightsandthresholdsInputWeights=net.IW{1,1}Inputbias=net.b{1}ThecurrentnetworklayerweightsandthresholdsLayerWeights=net.LW{2,1}Layerbias=net.b{2}PauseCLC%settrainingparametersNet.trainParam.show=50;Net.trainParam.lr=0.05;Net.t
4、rainParam.mc=0.9;Net.trainParam.epochs=1000;Net.trainParam.goal=1e-3;PauseCLC%callTRAINGDMalgorithmtotrainBPnetwork[net,tr]=train(net,P,T);PauseCLCSimulationofBPnetworkby%A=sim(net,P)CalculatethesimulationerrorE=T-AMSE=mse(E)PauseCLCEchooffExample2adoptsBayesianregularizationalg
5、orithmtoimprovethegeneralizationabilityofBPnetwork.Inthiscase,weusedtwokindsoftrainingmethods,namelyL-Malgorithm(trainlm)andtheBiasregularizationalgorithm(trainbr),isusedtotraintheBPnetwork,sothatitcanfitattachedtoawhitenoisesinesampledata.Amongthem,thesampledatacanbegeneratedas
6、followsMATLABstatements:Inputvector:P=[-1:0.05:1];Targetvector:randn('seed',78341223);T=sin(2*pi*P)+0.1*randn(size(P));Solution:theMATLABprogramofthisexampleisasfollows:CloseallClearEchoonCLC%NEWFF-generatinganewfeedforwardneuralnetwork%TRAIN--trainingBPneuralnetwork%SIM--Simula
7、tionofBPneuralnetworkPauseStartbyhittinganykeyCLC%definetrainingsamplevector%PasinputvectorP=[-1:0.05:1];%TisthetargetvectorRandn('seed',78341223);T=sin(2*pi*P)+0.1*randn(size(P));DrawthesampledatapointsPlot(P,T,+);EchooffHoldon;Plot(P,sin(2*pi*P),':');Drawsinecurveswithoutnoise
8、EchoonCLCPauseCLC%createanewfeedforwardneuralne