Genetic Algorithm taking too long to optimize
Show older comments
Hi,
I have been trying to build a code to optimize a curve towards an ideal curve using genetic algorithm but the iterations are not going past the 1st generation. However the optimization app says that it is still optimizing. Can someone guide me and check if there is something wrong with my code and suggest ways to speed it up for faster results. As you are aware the stochastic process might not give the best results in the first attempt but might take two or three attempts, the time consumed till then would be too long. Please note that the variables are changing in each for loop iteration therefore the number of variables are 14. I request for some urgent help on this code:
function [Error] = opskinmodel(x)
Einf=x(1);
Es_cole(1)=x(2);
Es_cole(2)=x(3);
Es_cole(3)=x(4);
Es_cole(4)=x(5);
Tau(1)=x(6);
Tau(2)=x(7);
Tau(3)=x(8);
Tau(4)=x(9);
Cond=x(10);
alpha(1)=x(11);
alpha(2)=x(12);
alpha(3)=x(13);
alpha(4)=x(14);
freq=90e9; % Frequency Limit
Eo = 8.854e-12; % Permittivity of free space
g =1:1:(freq/1e9);
CondGabData=xlsread('tissueproperties(final).csv','C:C');% Conductivity from Gabriel's data
PermGabData=xlsread('tissueproperties(final).csv','D:D'); % Permitivity from Gabriel's data
% Cole Cole ----------------------------------------------------------
i=1;
j=sqrt(-1);%imaginary iota
m=1;
Error=0; % Cost Function
PDiff=0;
CDiff=0;
for f =1e9:1e9:(freq)
tmp = 0; % temporary summation variable for higher order value addition
for k=1:4
tmp = tmp + Es_cole(k) / (1 + (j * 2 * pi * (f) * Tau(k)))^(1-alpha(k)); % higher order summation
end
Er_relative(i) = Einf + tmp + Cond/(j * 2 * pi * (f) * Eo);% Complex relative permitivity
Er(i)=real(Er_relative(i));% real part (e') relative permitivity
Ei(i)=-imag(Er_relative(i));% imaginary part (e'') loss factor
Conductivity(i)=Ei(i)*Eo*2*pi*f; % conductivity
i=i+1;
end
%EVALUATION OF COST FUNCTION
for f=1e9:1e9:freq;
lossfactor(m)=CondGabData(m)/(Eo*2*pi*f); % (e'' or lossfactor of Gabriel's data)
PDiff=PDiff+((PermGabData(m)-Er(m))/median(Er))^2;
CDiff=CDiff+((CondGabData(m)-Conductivity(m))/median(Conductivity))^2;
m=m+1;
end
Error=(PDiff+CDiff)/length(g);
3 Comments
Geoff Hayes
on 23 Mar 2016
Akbar - are you using the Genetic Algorithm from the Global Optimization Toolbox, or are you using a custom GA? What is your initial population size? How are you invoking the GA with the above optimization function?
Looking at your code, there are several optimizations that come to mind:
- Pre-size your arrays (i.e. Er_relative, Er, Ei, Conductivity)
- Remove unneeded calculations (i.e. lossfactor)
- Don't read from the Excel files on every call to this function. Since (presumably) these files are static (and so are not updated during the run of the GA) then persist the data from these files so that you only read once. See defining persistent variables for details.
Try implementing the above suggestions and see what happens.
Akbar Raza
on 23 Mar 2016
Akbar Raza
on 23 Mar 2016
Edited: Akbar Raza
on 23 Mar 2016
Accepted Answer
More Answers (0)
Categories
Find more on Direct Search in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!