資源簡介
創(chuàng)建BP神經(jīng)網(wǎng)絡(luò),然后擬合二元一次函數(shù)圖像,并計(jì)算函數(shù)平均值、誤差等。
代碼片段和文件信息
clear;
%%定義樣本數(shù)據(jù)
x1=20*rand(1100)-10;
x2=20*rand(1100)-10;
x3=20*rand(1100)-10;
x4=20*rand(1100)-10;
%%劃分訓(xùn)練數(shù)據(jù)與測試數(shù)據(jù)
p?=?[x1;x2];
t?=?[x1+x2-4];
intest?=?[x3;x4];
outest?=?[x3+x4-4];
%%創(chuàng)建并訓(xùn)練網(wǎng)絡(luò)
net?=?newff(pt[16]);
net?=?train(netpt);
yy?=?sim(netintest);
%%輸出圖像
l1?=?linspace(-101050);
l2?=?linspace(-101050);
[X1X2]?=?meshgrid(l1l2);
P?=?[X1(:)‘;X2(:)‘];
Z?=?sim(netP);
Y?=?reshape(Z5050);
figure(1)
surf(X1X2Y);hold?on;
axis([-1010-1010min(Y(:))max(Y(:))]);
youtest?=?sim(netintest);
plot3(intest(1:)intest(2:)youtest‘b*‘)
xlabel(‘X1‘);
ylabel(‘X2‘);
zlabel(‘Y‘);
legend(‘?dāng)M合結(jié)果‘‘樣本點(diǎn)‘);
title(‘Y=X1+X2-4‘)
hold?off?
%%計(jì)算、顯示相對誤差等
e?=?(outest-yy)./outest;
figure(2);
plot(1:10
評論
共有 條評論