資源簡介
BP神經(jīng)網(wǎng)絡(luò)源代碼,壓縮包里面包括訓(xùn)練代碼、測試代碼、采樣數(shù)據(jù)。

代碼片段和文件信息
close?all?
clear?all?
clc?
web?-browser?http://www.ilovematlab.cn/thread-220251-1-1.html
x=xlsread(‘training_data.xls‘[‘B2:G401‘]);?
y=xlsread(‘training_data.xls‘[‘I2:K401‘]);?
inputs?=?x‘;?
targets?=?y‘;
%?創(chuàng)建一個模式識別網(wǎng)絡(luò)(兩層BP網(wǎng)絡(luò)),同時給出中間層神經(jīng)元的個數(shù),這里使用20
hiddenlayerSize?=?20;
net?=?patternnet(hiddenlayerSize);
%?對數(shù)據(jù)進行預(yù)處理,這里使用了歸一化函數(shù)(一般不用修改)
%?For?a?list?of?all?processing?functions?type:?help?nnprocess
net.inputs{1}.processFcns?=?{‘removeconstantrows‘‘mapminmax‘};
net.outputs{2}.processFcns?=?{‘removeconstantrows‘‘mapminmax‘};
%?把訓(xùn)練數(shù)據(jù)分成三部分,訓(xùn)練網(wǎng)絡(luò)、驗證網(wǎng)絡(luò)、測試網(wǎng)絡(luò)
%?For?a?list?of?all?data?division?functions?type:?help?nndivide
net.divideFcn?=?‘dividerand‘;??%?Divide?data?randomly
net.divideMode?=?‘sample‘;??%?Divide?up?every?sample
net.divideParam.trainRatio?=?70/100;
net.divideParam.valRatio?=?15/100;
net.divideParam.testRatio?=?15/100;
%?訓(xùn)練函數(shù)
%?For?a?list?of?all?training?functions?type:?help?nntrain
net.trainFcn?=?‘trainlm‘;??%?Levenberg-Marquardt
%?使用均方誤差來評估網(wǎng)絡(luò)
%?For?a?list?of?all?performance?functions?type:?help?nnperformance
net.performFcn?=?‘mse‘;??%?Mean?squared?error
%?畫圖函數(shù)
%?For?a?list?of?all?plot?functions?type:?help?nnplot
net.plotFcns?=?{‘plotperform‘‘plottrainstate‘‘ploterrhist‘?...
??‘plotregression‘?‘plotfit‘};
%?開始訓(xùn)練網(wǎng)絡(luò)(包含了訓(xùn)練和驗證的過程)
[nettr]?=?train(netinputstargets);
%?測試網(wǎng)絡(luò)
outputs?=?net(inputs);
errors?=?gsubtract(targetsoutputs);
performance?=?perform(nettargetsoutputs)
%?獲得訓(xùn)練、驗證和測試的結(jié)果
trainTargets?=?targets?.*?tr.trainMask{1};
valTargets?=?targets??.*?tr.valMask{1};
testTargets?=?targets??.*?tr.testMask{1};
trainPerformance?=?perform(nettrainTargetsoutputs)
valPerformance?=?perform(netvalTargetsoutputs)
testPerformance?=?perform(nettestTargetsoutputs)
%?可以查看網(wǎng)絡(luò)的各個參數(shù)
view(net)
%?根據(jù)畫圖的結(jié)果,決定是否滿意
%?Uncomment?these?lines?to?enable?various?plots.
figure?plotperform(tr)
figure?plottrainstate(tr)
figure?plotconfusion(targetsoutputs)
figure?ploterrhist(errors)
%如果你對該次訓(xùn)練滿意,可以保存訓(xùn)練好網(wǎng)絡(luò)
save(‘training_net.mat‘‘net‘‘tr‘);
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2013-03-22?20:35??BP\
?????文件???????30369??2013-03-22?19:14??BP\training_data.xls
?????文件????????2238??2013-03-22?19:09??BP\Training_NPR.m
?????文件?????????600??2013-03-22?19:10??BP\Use_For_Predict.m
- 上一篇:多重曝光圖像的區(qū)域融合
- 下一篇:非常有用的自適應(yīng)信號處理答案
評論
共有 條評論