Need help! I try to build Neural Network but it does not fit well with the training data!
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I check my feed forward and backpropagation but cant find error, please help! Thank you so much.
Here is my code:
%% Prepare data
% train data:
I=1; % number of independent variables
F=1; % number of dependent varaiables
Ib=[-pi:0.1:(4*pi)].'; % input matrix
Yb= sin(Ib); % (actual) output matrix
P=size(Ib,1); % number of observations
% Normalize:
Input(:,1)=(Ib(:,1)-min(Ib(:,1)))/(max(Ib(:,1))-min(Ib(:,1)));
Y(:,1)=(Yb(:,1)-min(Yb(:,1)))/(max(Yb(:,1))-min(Yb(:,1)));
%% Neural Network:
% hyperparameter for NN:
Gen=10^8; % number of times train neural network
Epsi= 10^(-7); % tolerance
SSEold=999; % sum squared error
m=0; % update step size
A=1;
B=10000;
mu=A/(B+m); % step size or rate of learning
% layer:
N=1; % number of hidden layers
H=15; % number of hidden nodes
g=0.01;
% Initial parameter:
W1=rand(I+1,H);
X=g.*rand(H,F);
bias=g*rand(P,1); % bias node
bias1=g*rand(1,1); % bias weight to output layer
% Add bias node to Input layer:
Input=cat(2,Input,bias);
Err=10;
while (Err >Epsi && m < Gen)
%% Forward probagation:
Vp=Input*W1;
Vp=1./(1+exp(-Vp));
Yhat=bias1+Vp*X;
SSEnew=sum(abs(Y-Yhat).^2,1);
%% Backward probagation:
Yerr=Y-Yhat;
bias1=bias1+mu*sum(Yerr);
W1=W1+mu*(Input.')*(Yerr*(X.').*Vp.*(1-Vp));
X=X+mu*(Yerr'*Vp).';
%% Update:
m=m+1;
mu=A/(B+m);
%% Calculate Sum Squared Error:
Err=abs(SSEnew-SSEold);
SSEold=SSEnew;
end
%% plot
figure1=figure;
grid on
plot(Y)
hold on
plot(Yhat)
0 commentaires
Réponse acceptée
Greg Heath
le 26 Nov 2018
>> Vp = Input * W1;
Error using *
>> size(Input), size(W1)
ans =
158 4
ans =
2 15
Hope this helps
Thank you for formally accepting my answer
Greg
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Sequence and Numeric Feature Data Workflows dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!