日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 >

matlab 曲线收敛,BP神经网络学习曲线收敛问题

發(fā)布時間:2023/12/20 41 豆豆
生活随笔 收集整理的這篇文章主要介紹了 matlab 曲线收敛,BP神经网络学习曲线收敛问题 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

利用手算、串行訓(xùn)練方式下的BP神經(jīng)網(wǎng)絡(luò),其誤差學(xué)習(xí)曲線不能呈現(xiàn)收斂嗎?

[% script: main_seral.m

% 串行方式訓(xùn)練BP網(wǎng)絡(luò),實現(xiàn)性別識別

%% 清理

clear all

clc

%% 讀入數(shù)據(jù)

xlsfile='student.xls';

[data,label]=getdata(xlsfile);

%% 劃分?jǐn)?shù)據(jù)

[traind,trainl,testd,testl]=divide(data,label);

%% 設(shè)置參數(shù)

rng('default')

rng(0)

nTrainNum = 60; % 60個訓(xùn)練樣本

nSampDim = 2;? ?% 樣本是2維的

M=2000;? ?? ?? ?% 迭代次數(shù)

ita=0.1;? ?? ???% 學(xué)習(xí)率

alpha=0.2;

%% 構(gòu)造網(wǎng)絡(luò)

HN=3;? ?? ?? ???% 隱含層層數(shù)

net.w1=rand(3,HN);

net.w2=rand(HN+1,1);

%% 歸一化數(shù)據(jù)

mm=mean(traind);

for i=1:2

traind_s(:,i)=traind(:,i)-mm(i);

end

ml(1) = std(traind_s(:,1));

ml(2) = std(traind_s(:,2));

for i=1:2

traind_s(:,i)=traind_s(:,i)/ml(i);

end

%% 訓(xùn)練

for x=1:M? ?? ?? ?? ?? ?? ?? ?? ???% 迭代

ind=randi(60);? ?? ?? ?? ?? ???% 從1-60中選一個隨機(jī)數(shù)

in=[traind_s(ind,:),1];? ?? ???% 輸入層輸出

net1_in=in*net.w1;? ?? ?? ?? ? % 隱含層輸入

net1_out=logsig(net1_in);? ?? ?% 隱含層輸出

net2_int = [net1_out,1];? ?? ? % 下一次輸入

net2_in = net2_int*net.w2;? ???% 輸出層輸入

net2_out = logsig(net2_in);? ? % 輸出層輸出

err=trainl(ind)-net2_out;? ?? ?% 誤差

errt(x)=1/2*sqrt(sum(err.^2)); % 誤差平方

fprintf('第 %d 次循環(huán), 第%d個學(xué)生, 誤差??%f\n',x,ind, errt(x));

% 調(diào)整權(quán)值

for i=1:length(net1_out)+1

for j=1:1

ipu1(j)=err(j);? ???% 局部梯度

% 輸出層與隱含層之間的調(diào)整量

delta1(i,j) = ita.*ipu1(j).*net2_int(i);

end

end

for m=1:3

for i=1:length(net1_out)

% 局部梯度

ipu2(i)=net1_out(i).*(1-net1_out(i)).*sum(ipu1.*net.w2);

% 輸入層和隱含層之間的調(diào)整量

delta2(m,i)= ita.*in(m).*ipu2(i);

end

end

% 調(diào)整權(quán)值

if x==1

net.w1 = net.w1+delta2;

net.w2 = net.w2+delta1;

else

net.w1 = net.w1+delta2*(1-alpha) + alpha*old_delta2;

net.w2 = net.w2+delta1*(1-alpha) + alpha*old_delta1;

end

old_delta1=delta1;

old_delta2=delta2;

end

%% 測試

% 測試數(shù)據(jù)歸一化

for i=1:2

testd_s(:,i)=testd(:,i)-mm(i);

end

for i=1:2

testd_s(:,i)=testd_s(:,i)/ml(i);

end

testd_s = [testd_s,ones(length(testd_s),1)];

net1_in=testd_s*net.w1;

net1_out=logsig(net1_in);

net1_out=[net1_out,ones(length(net1_out),1)];

net2_int = net1_out;

net2_in = net2_int*net.w2;

net2_out=net2_in;

% 取整

net2_out(net2_out<0.5)=0;

net2_out(net2_out>=0.5)=1;

rate=sum(net2_out==testl')/length(net2_out);

%% 顯示

fprintf('??正確率:\n? ? %f %%\n', rate*100);

figure(1);

plot(1:M,errt,'b-','LineWidth',1.5);

xlabel('迭代次數(shù)')

ylabel('誤差')

title('BP網(wǎng)絡(luò)串行訓(xùn)練的誤差')

% axis([0,200,0,0.45])]

BP_seral.jpg

(59.39 KB, 下載次數(shù): 1)

2016-5-5 15:34 上傳

2016-5-5 15:40 上傳

點擊文件名下載附件

882 Bytes, 下載次數(shù): 11

被調(diào)函數(shù)

2016-5-5 15:41 上傳

點擊文件名下載附件

383 Bytes, 下載次數(shù): 13

被調(diào)函數(shù)

2016-5-5 15:41 上傳

點擊文件名下載附件

31 KB, 下載次數(shù): 11

數(shù)據(jù)

2016-5-5 15:41 上傳

點擊文件名下載附件

2.66 KB, 下載次數(shù): 12

主程序

總結(jié)

以上是生活随笔為你收集整理的matlab 曲线收敛,BP神经网络学习曲线收敛问题的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。