Hello, I am new to ANN. I wanted to develop a network (fitnet) and used the following code in MATLAB (6 inputs and 1 output).

1 visualización (últimos 30 días)
But, the overall R=0.56. Are there any bugs in the code? How can I further improve this network? Is it possible to use ensemble techniques or advanced initialization techniques to this type of network (ex: glorot)?
Import the data
x=myModel(:,1:6);
y=myModel(:,7);
l=length(x);
Normalize the inputs
for k=1:6
xtnn(:,k)=(x(:,k)-min(x(:,k)))/(max(x(:,k))-min(x(:,k)));
end
for f=1
ytnn(:,f)=(y(:,f)-min(y(:,f)))/(max(y(:,f))-min(y(:,f)));
end
Train the ANN
trainFcn='trainlm'
xtn=xtnn'; % transpose of the input matrix
ytn=ytnn'; %transpose of the output matrix
hiddenLayerSize=(23);
netM=fitnet(hiddenLayerSize,trainFcn);
netM.divideFcn='divideind';
K-Fold Cross Validation
h=10;
c = crossvalind('KFold',l,10);
rng('default');
for i=1:h
netM=configure(netM,xtn,ytn);
vlInd=(c == i);
trInd= ~vlInd;
trInx=find(trInd);
vlInx=find(vlInd);
netM.divideParam.trainInd=trInx;
netM.divideParam.valInd=vlInx;
netM.trainParam.lr=0.01;
netM.trainParam.epochs=10000;
netM.performParam.regularization = 0.01;
netM.performFcn='mse';
netM.layers{1}.transferFcn='tansig';
netM.layers{2}.transferFcn='purelin';
netM.layers{1}.initFcn='initnw';
netM.layers{2}.initFcn='initnw';
tr.trainInd = trInx;
tr.valInd = vlInx;
net.initFcn='initlay';
netM=init(netM);
[netM,tr]=train(netM,xtn,ytn);
end
Output = sim(netM,xtn,[],[],ytn)
plotperf(tr)
trOutput=Output(trInx)
valOutput=Output(vlInx)
trTarget=ytn(trInx)
valTarget=ytn(vlInx)
plotregression(trTarget, trOutput, 'Train', valTarget, valOutput, 'Validation', ytn, Output, 'All')
tr.best_epoch
Obtaining the weights and bias matrices
w1=netM.IW{1,1};
w1'
w2=netM.LW{2,1};
w2'
b1=netM.b{1}
b2=netM.b{2}
Unnormalized Output
Output_I=Output';
Output_R=((Output_I(:,f))*(max(y(:,f))-min(y(:,f))))+(min(y(:,f)))
Performance of the network
perf=mse(netM,ytn,AN4)
save netM

Respuestas (0)

Etiquetas

Productos


Versión

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by