- 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.
Genetic Algorithm taking too long to optimize
31 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Akbar Raza
el 23 de Mzo. de 2016
Editada: Akbar Raza
el 24 de Mzo. de 2016
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 comentarios
Respuesta aceptada
Alan Weiss
el 23 de Mzo. de 2016
I think that the best thing to do is to not use ga, but instead use patternsearch, possibly starting from a variety of initial points. You will probably be surprised at the speed and robustness of patternsearch compared to ga.
The other thing to do to speed your code for either ga or patternsearch is NOT have a call to xlsread inside your objective function. Instead, call xlsread once OUTSIDE your objective function, and pass in any data to the objective function using MATLAB syntax.
Alan Weiss
MATLAB mathematical toolbox documentation
1 comentario
Más respuestas (0)
Ver también
Categorías
Más información sobre Surrogate Optimization en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!