Why the results of my Elman network are different every time?

조회 수: 2 (최근 30일)
Heather Zhang
Heather Zhang 2015년 7월 31일
댓글: Greg Heath 2015년 8월 13일
I created a elman network. But the results every time I run the code were different.I got different "errors","regression" and "avg_error" Could anyone tell me why? Appreciate SO MUCH!
Here is the code.
clear all
load('input4_train.mat');
load('output4_train.mat');
load('input4_test.mat');
load('output4_test.mat');
inputSeries = tonndata(input4_train,false,false);
targetSeries = tonndata(output4_train,false,false);
inputTest = tonndata(input4_test,false,false);
outputTest = tonndata(output4_test,false,false);
% Create a Network
hiddenLayerSize = 5;
net=newelm(inputSeries,targetSeries,[10,3,1], {'tansig','logsig','purelin'});
% Setup Division of Data for Training, Validation, Testing
net.divideParam.trainRatio = 70/100;
net.divideParam.valRatio = 15/100;
net.divideParam.testRatio = 15/100;
net.trainParam.epochs = 2000;
% Initial net
net = init(net);
% Train the Network
net = adapt(net,inputSeries,targetSeries);
% Test the Network
outputs = sim(net,inputTest);
errors = gsubtract(outputTest,outputs);
error = cell2mat(errors);
for i = 1:10
error(i)=abs(error(i));
end
avg_error = sum(error)/10;
performance = perform(net,outputTest,outputs)
% View the Network
view(net)
% Plots
figure, plotregression(outputTest,outputs)
figure, plotresponse(outputTest,outputs)
figure, ploterrcorr(errors)
  댓글 수: 3
Greg Heath
Greg Heath 2015년 8월 1일
편집: Walter Roberson 2015년 8월 2일
% load('input4_train.mat');
% load('output4_train.mat');
% load('input4_test.mat');
% load('output4_test.mat');
%
% inputSeries = tonndata(input4_train,false,false);
% targetSeries = tonndata(output4_train,false,false);
% inputTest = tonndata(input4_test,false,false);
% outputTest = tonndata(output4_test,false,false);
whos
% % Create a Network
% hiddenLayerSize = 5;
Value never used
% net=newelm(inputSeries,targetSeries,[10,3,1], {'tansig','logsig','purelin'});
No justification for 3 hidden layers. One is sufficient.
% % Setup Division of Data for Training, Validation, Testing
% net.divideParam.trainRatio = 70/100;
% net.divideParam.valRatio = 15/100;
% net.divideParam.testRatio = 15/100;
Above 3 commands unnecessary for default values.
% net.trainParam.epochs = 2000;
%
% % Initial net
% net = init(net);
%
% % Train the Network
% net = adapt(net,inputSeries,targetSeries);
%
% % Test the Network
% outputs = sim(net,inputTest);
%
% errors = gsubtract(outputTest,outputs);
% error = cell2mat(errors);
% for i = 1:10
% error(i)=abs(error(i));
% end
% avg_error = sum(error)/10;
Above 5 commands unnecessary.
help mae
doc mae
% performance = perform(net,outputTest,outputs)
% % View the Network
% view(net)
%
% % Plots
% figure, plotregression(outputTest,outputs)
% figure, plotresponse(outputTest,outputs)
% figure, ploterrcorr(errors)
Defaults: Above 3 commands unnecessary;
Heather Zhang
Heather Zhang 2015년 8월 2일
Thank you so much for your detailed,Greg! I need your help on my code. I will answer your questions.
Q2. What scenario did you use it for? Why was it used instead of timedelaynet or narxnet? I use it for dealing with a time series prediction issue.
Q3. Where did you obtain this code? Many of the options chosen make little sense. I coded it according to BP network code. I knew "newelm" function is for build an Elman network and "sim" is for testing a network. So I coded it by myself. I can tell there should be something wrong in it, but I don't know where the mistakes are.
So pleas help me on this code, and that would be appreciated very much!

댓글을 달려면 로그인하십시오.

채택된 답변

Walter Roberson
Walter Roberson 2015년 7월 31일
Neural Networks initialize their weights randomly usually. If you want repeatability you can initialize the weights yourself or you can set the random number generator seed.
  댓글 수: 2
Heather Zhang
Heather Zhang 2015년 8월 2일
Thank you so much,Walter! I use 'init' function to initialize the weights. Am I right? Looking forward to your answer.
Greg Heath
Greg Heath 2015년 8월 13일
YOU CAN ALSO USE THE FUNCTION CONFIGURE

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Deep Learning Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by