How to optimize ANN structure using GA

5 views (last 30 days)
I've created this model by editing the codes from ANN toolbox. In my work i need to study the effect of changing various ANN topology on its performance. The purpose of this model is to train the network with operating data from a steam turbine. The data is normalized and then the target will be set according to the actual fault occurrence which tagged as "1" and during normal operation "0". For my next work, I'm trying to optimize the ANN topology by using GA.
For example,
% 'trainlm' is usually fastest.
% 'trainbr' takes longer but may be better for challenging problems.
% 'trainscg' uses less memory. NFTOOL falls back to this in low memory situations.
trainFcn = 'trainbr'; % Bayesian Regularization
How to use GA to optimize which of the three training algorithm gives the best RMSE. But for my work I'm also need to consider the number of neuron, the number of hidden layers, and activation function. The performance indicator of this network is RMSE so the RMSE should be the fitness for the GA.
I've also drafted the preliminary part of the GA to be used in my codes but I'm having a problem to combine with the ANN.
% Preliminary function decoding:
function [algo, archit, activf1, activf2] = decoding(X)
%
% function that decodes a binary string into information
% about the NN structure and training tralgorithm
%
% [algo, archit, activf1 activf2] = decoding(X)
%
% "X" is a population of binary strings of size 10 (excluding 32param)
% eg:[00,0000,00 00]
%
% algo = for training algorithm trainscg, trainlm, trainbr
%
% archit = hidden layer neurons from 0000 to 1001
%
% activf1 = type of activation functions of hidden nodes
% activf2 = type of activation functions of output nodes
% = 00 for logsig
% = 01 for tansig
% = 10 for purelin
%M=Pz (population size)
M = size(X,1);
%initializations:
a = zeros(M,2); %size for algo (training algorithm)
b = zeros(M,4); %size for archit (hidden layer neuron)
c = zeros(M,4); %size for activf and activf2
%d = zeros(Pz,32);
for i=1:M
a = X(i,1:2);
b = X(i,3:8);
c = X(i,9:10);
% for algo (training algorithm)
if (a == [0 0])
algo(i) = ['trainscg'];
elseif (a == [0 1])
algo(i) = ['trainlm'];
elseif (a == [1 0])
algo(i) = ['trainbr'];
end
% for archit (hidden layer neuron)
if (b == [0 0 0 0])
archit(i,1) = 1;
elseif (b == [0 0 0 1])
archit(i,1) = 2;
elseif (b == [0 0 1 0])
archit(i,1) = 3;
elseif (b == [0 0 1 1])
archit(i,1) = 4;
elseif (b == [0 1 0 0])
archit(i,1) = 5;
elseif (b == [0 1 0 1])
archit(i,1) = 6;
elseif (b == [0 1 1 0])
archit(i,1) = 7;
elseif (b == [0 1 1 1])
archit(i,1) = 8;
elseif (b == [1 0 0 0])
archit(i,1) = 9;
elseif (b == [1 0 0 1])
archit(i,1) = 10;
end
% for activf and activf2
if (c == [0 0 0 0])
activf1(i,:) = ['logsig'];
activf2(i,:) = ['logsig'];
elseif (c == [0 0 0 1])
activf1(i,:) = ['logsig'];
activf2(i,:) = ['tansig'];
elseif (c == [0 0 1 0])
activf1(i,:) = ['logsig'];
activf2(i,:) = ['purelin'];
elseif (c == [0 0 1 1])
activf1(i,:) = ['tansig'];
activf2(i,:) = ['logsig'];
elseif (c == [0 1 0 0])
activf1(i,:) = ['tansig'];
activf2(i,:) = ['tansig'];
elseif (c == [0 1 0 1])
activf1(i,:) = ['tansig'];
activf2(i,:) = ['purelin'];
elseif (c == [0 1 1 0])
activf1(i,:) = ['purelin'];
activf2(i,:) = ['logsig'];
elseif (c == [0 1 1 1])
activf1(i,:) = ['purelin'];
activf2(i,:) = ['tansig'];
elseif (c == [1 0 0 0])
activf1(i,:) = ['purelin'];
activf2(i,:) = ['purelin'];
end
end %for
'Population was decoded!'

Answers (0)

Community Treasure Hunt

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

Start Hunting!