資源簡介
BP神經網絡源代碼,壓縮包里面包括訓練代碼、測試代碼、采樣數據。

代碼片段和文件信息
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‘;
%?創建一個模式識別網絡(兩層BP網絡),同時給出中間層神經元的個數,這里使用20
hiddenlayerSize?=?20;
net?=?patternnet(hiddenlayerSize);
%?對數據進行預處理,這里使用了歸一化函數(一般不用修改)
%?For?a?list?of?all?processing?functions?type:?help?nnprocess
net.inputs{1}.processFcns?=?{‘removeconstantrows‘‘mapminmax‘};
net.outputs{2}.processFcns?=?{‘removeconstantrows‘‘mapminmax‘};
%?把訓練數據分成三部分,訓練網絡、驗證網絡、測試網絡
%?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;
%?訓練函數
%?For?a?list?of?all?training?functions?type:?help?nntrain
net.trainFcn?=?‘trainlm‘;??%?Levenberg-Marquardt
%?使用均方誤差來評估網絡
%?For?a?list?of?all?performance?functions?type:?help?nnperformance
net.performFcn?=?‘mse‘;??%?Mean?squared?error
%?畫圖函數
%?For?a?list?of?all?plot?functions?type:?help?nnplot
net.plotFcns?=?{‘plotperform‘‘plottrainstate‘‘ploterrhist‘?...
??‘plotregression‘?‘plotfit‘};
%?開始訓練網絡(包含了訓練和驗證的過程)
[nettr]?=?train(netinputstargets);
%?測試網絡
outputs?=?net(inputs);
errors?=?gsubtract(targetsoutputs);
performance?=?perform(nettargetsoutputs)
%?獲得訓練、驗證和測試的結果
trainTargets?=?targets?.*?tr.trainMask{1};
valTargets?=?targets??.*?tr.valMask{1};
testTargets?=?targets??.*?tr.testMask{1};
trainPerformance?=?perform(nettrainTargetsoutputs)
valPerformance?=?perform(netvalTargetsoutputs)
testPerformance?=?perform(nettestTargetsoutputs)
%?可以查看網絡的各個參數
view(net)
%?根據畫圖的結果,決定是否滿意
%?Uncomment?these?lines?to?enable?various?plots.
figure?plotperform(tr)
figure?plottrainstate(tr)
figure?plotconfusion(targetsoutputs)
figure?ploterrhist(errors)
%如果你對該次訓練滿意,可以保存訓練好網絡
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
- 上一篇:多重曝光圖像的區域融合
- 下一篇:非常有用的自適應信號處理答案
評論
共有 條評論