필터 지우기
필터 지우기

problem with rng during retraining of a neural network

조회 수: 1 (최근 30일)
Mohamad
Mohamad 2013년 12월 18일
댓글: Greg Heath 2013년 12월 19일
Hello
I have a trained a neural network on a data set and tested its generalization on an independent sample. I have deliberately reduced the training equations and increased the number of hidden nodes to make the net overfit since I am going to use some methods to avoid overfitting later. The problem is with rng. I have saved the rng state but when I use the same state for traing my net again, I get different results! here is the code:
[x,t]=bodyfat_dataset;
Q = size(x,2);
Q1 = floor(Q*0.30);
Q2 = Q-Q1;
Q3=floor(Q2*0.15);
ind = randperm(Q1+Q3);
ind1 = ind(1:Q1);
ind2 = ind(Q1+(1:Q3));
x1 = x(:,ind1);
t1 = t(:,ind1);
x2 = x(:,ind2);
t2 = t(:,ind2);
[I Ntrn] = size (x1);
[O Ntrn] = size (t1);
Ntrneq = prod(size(t1));
MSEtrn00 = mean(var(t1',1)) ;
Hub = -1 + ceil( (Ntrneq-O) / (I+O+1))
MSEgoal = 0.01*MSEtrn00;
MinGrad = MSEgoal/10;
Hmax = 10;
dH=1
Hmin =0
Ntrials = 20
rng(0)
j=0
for h = Hmin:dH:Hmax
j=j+1
if h==0
net = newff(x1,t1,[]);
Nw = (I+1)*O
else
net = newff(x1,t1,h);
Nw = (I+1)*h+(h+1)*O
end
Ndof = Ntrneq-Nw;
net.divideFcn = 'dividetrain';
net.trainParam.goal = MSEgoal;
net.trainParam.min_grad = MinGrad;
for i = 1:Ntrials
h = h
ntrial = i
net = configure(net,x1,t1);
[ net tr Ytrn ] = train(net,x1,t1);
ytrn = round(Ytrn)
MSEtrn = mse(t1-ytrn);
R2trn= 1-MSEtrn/MSEtrn00;
Ytst = net(x2)
MSEtst(i,j)=mse(net,t2,Ytst);
s(i,j) = rng;
end
end
.....................................
suppose that the best result was obtained for s(3,2) then for retraining of my net:
rng(s(3,2))
net=newff(x1,t1,2);
net.divideFcn='dividetrain';
net=train(net,x1,t1);
y2=net(x2);
perf=mse(net,t2,y2)
% the perf is diffrent than that of s(3,2) during the previous training!!!

채택된 답변

Greg Heath
Greg Heath 2013년 12월 19일
randperm is used without initializing the RNG.
Thank you for formally accepting my answer
Greg
  댓글 수: 2
Mohamad
Mohamad 2013년 12월 19일
Dear Greg Thank you very much. The rng was initialized but the problem with this code was not solved!! best
Greg Heath
Greg Heath 2013년 12월 19일
I do not understand your reply:
Randperm was called before rng(0). Therefore, if you run the code multiple times you will get multiple answers.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Sequence and Numeric Feature Data Workflows에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by