【答案】應(yīng)助回帖
★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ 感謝參與,應(yīng)助指數(shù) +1 yue_shen000: 金幣+40, ★★★★★ 最佳答案, 很好 2012-05-13 14:52:36 yue_shen000: 回帖置頂 2012-05-13 14:53:38 xiegangmai: 金幣+2, 謝謝應(yīng)助! 2012-05-13 23:09:03
CODE: %輸入訓(xùn)練數(shù)據(jù)
input_train=[10 0.1 0.1 18 60;
10 0.1 0.1 18 70;
10 0.1 0.1 18 80;
10 0.2 0.2 24 60;
10 0.2 0.2 24 70;
10 0.2 0.2 24 80;
10 0.5 0.4 30 60;
10 0.5 0.4 30 70;
10 0.5 0.4 30 80;
13 0.1 0.1 30 60;
13 0.1 0.2 30 70;
13 0.1 0.4 30 80;
13 0.3 0.1 18 60;
13 0.2 0.2 18 70;
13 0.2 0.4 18 80;
13 0.5 0.1 24 60;
13 0.5 0.2 24 70;
13 0.5 0.4 24 80;
16 0.1 0.4 24 60;
16 0.1 0.4 24 70;
16 0.1 0.4 24 80;
16 0.2 0.1 30 60;
16 0.2 0.1 30 70;
16 0.2 0.1 30 80;
16 0.5 0.2 18 60;
16 0.5 0.2 18 70;
16 0.5 0.2 18 80]';
%訓(xùn)練目標向量
output_train=[0.62 0.65 0.65 0.69 0.59 0.52 0.57 0.58 0.42 0.64 0.71 0.75 0.68 0.54 0.57 0.87 0.52 0.52 0.75 0.68 0.71 0.64 0.86 0.95 0.68 0.57 0.52];
%測試樣本
input_test=[10 0.5 0.2 18 80;
8 0.7 0.3 18 80;
16 0.1 0.1 30 60;
18 0.05 0.05 36 60]';
%測試目標
output_test=[0.54 0.42 0.71 0.9];
%訓(xùn)練數(shù)據(jù)歸一化
[inputn,inputps]=mapminmax(input_train);
[outputn,outputps]=mapminmax(output_train);
%創(chuàng)建網(wǎng)絡(luò)參數(shù)
net=newff(inputn,outputn,[8,8],{'tansig','purelin'},'trainlm');
net.trainparam.show=300;
net.trainparam.mc=0.9;
net.trainparam.lr=0.05;
net.trainparam.epochs=200;
net.trainparam.goal=0.001;
%BP神經(jīng)網(wǎng)絡(luò)訓(xùn)練
[net,tr]=train(net,inputn,outputn);
%預(yù)測數(shù)據(jù)歸一化
inputn_test=mapminmax('apply',input_test,inputps);
%BP神經(jīng)網(wǎng)絡(luò)預(yù)測輸出
an=sim(net,inputn_test);
%輸出結(jié)果反歸一化
BPoutput=mapminmax('reverse',an,outputps);
figure(1)
plot(BPoutput,'g')
hold on
plot(output_test,'-*');
legend('預(yù)測輸出','期望輸出')
title('BP網(wǎng)絡(luò)預(yù)測輸出','fontsize',12)
ylabel('函數(shù)輸出','fontsize',12)
xlabel('樣本','fontsize',12)
%預(yù)測誤差
error=BPoutput-output_test;
figure(2)
plot(error,'-*')
title('BP網(wǎng)絡(luò)預(yù)測誤差','fontsize',12)
ylabel('誤差','fontsize',12)
xlabel('樣本','fontsize',12)
figure(3)
plot((output_test-BPoutput)./BPoutput,'-*');
title('神經(jīng)網(wǎng)絡(luò)預(yù)測誤差百分比')