資源簡(jiǎn)介
用matlab代碼實(shí)現(xiàn)的BP神經(jīng)網(wǎng)絡(luò),擬合了一個(gè)曲線,里面兩個(gè)文件,運(yùn)行BP文件就可以,可以直觀看到結(jié)果
代碼片段和文件信息
%生成數(shù)據(jù)
x=1:0.1:7;
y=x.^2.*sin(x);
%得到訓(xùn)練模型,4個(gè)參數(shù)分別是隱藏層神經(jīng)元數(shù),最大迭代次數(shù),輸入和輸出數(shù)據(jù)
model=BP_train(5100xy);
%計(jì)算網(wǎng)絡(luò)輸出
for?j?=?1:1:sample_size
????H?=?x(j:)*model.W12+model.b2;
????H?=?1./(1+exp(-H));
????net_output?=?H*model.W23+model.b3;
end????
%計(jì)算誤差
e=y-net_output;
%繪圖
subplot(311)
plot(xy‘:‘);
hold?on
plot(xnet_output‘+‘);
legend(‘原數(shù)據(jù)‘‘訓(xùn)練數(shù)據(jù)‘);
subplot(312)
plot(xe);
legend(‘網(wǎng)絡(luò)輸出誤差‘);
subplot(313)
plot(model.E);
legend(‘訓(xùn)練過程殘差‘);
?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????文件?????????541??2018-04-21?21:52??bp代碼\BP.m
?????文件????????1535??2018-04-21?21:50??bp代碼\BP_train.m
?????目錄???????????0??2018-04-21?21:55??bp代碼\
?????文件????????3468??2017-12-24?20:31??bp代碼\BPNet.m
?????文件????????2848??2017-12-17?19:18??bp代碼\Iris.txt
評(píng)論
共有 條評(píng)論