Вы находитесь на странице: 1из 2

[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!!!

Вам также может понравиться