Neural network with error BP

2 次查看(过去 30 天)
Hazim Nasir
Hazim Nasir 2019-3-12
Hello
I am totally new to ANN, I have a simple problem which is I have to train a network with 2000 input output data set
The network consists of three inputs (x,y,z) and three outputs (t1, t2, t3), each row in the attached axcel files is input and its corresponding output with one hidden layer
this is a regression problem and I read some papers say that at hidden layer there should be sigmoid function and at output layer there sould be linear function x=y
But the problem is I got NAN when I use linear on output layer. Thank you for any idea or help
clear;
clc;
inpt = xlsread('inpt.xlsx');
outpt = xlsread('outpt.xlsx');
nh=50; % number of neurons in hidden layer
ni=3; % number of inputs
no=3; % number of outputs
wi = unifrnd(-1,1,[ni,nh]); % weights on inputs-hidden
wo = unifrnd(-1,1,[nh,no]); % weights on hidden-outputs
th_h = unifrnd(-1,1,[1,nh]); % bais on hidden layer
th_o = unifrnd(-1,1,[1,no]); % bais on output layer
a=0.1;
Error=30;
epoch = 1;
while abs(Error) >= 10
for i=1:size(inpt,1)
% estimate y
for k=1:nh
y(k) = sig(inpt(i,:)*wi(:,k)-th_h(k)) ;
end
% estimate thetas (output)
for k=1:no
th(k) = (y*wo(:,k)-th_o(k)) ;
end
% estimate error
e=outpt(i,:)-th;
Error = sum((e).^2)
% estimate delat at output layer
do= th.*(1-th).*e;
% error qradient at output layer
for k=1:nh
for j=1:no
dwo(k,j)=a*y(k)*do(j);
end
end
dth_o = a*(-1)*do;
% error qradient at hidden layer
for k=1:nh
D(k) = sum(wo(k,:).*do.*(y(k)*(1-y(k))));
end
for k=1:nh
dwi(:,k)=a*inpt(i,:)'*D(k);
end
dth_h = a*(-1)*D;
% update weights
wi = wi+dwi;
th_h= th_h+dth_h;
wo = wo+dwo;
th_o = th_o+dth_o;
epoch = epoch+1;
end
end
epoch

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Linear Regression 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by