Out of the bluw, a code I use to run a GA optimization has become much (>ten-fold) slower. The specifics are as follows:
Ubuntu 20.04, 64Gb/2.4 GHz RAM, i9-7900X CPU @ 3.30GHz. Not using GPUs for any of my MATLAB (2018a) operations.
I won't paste the whole code, but a short pseudocode is provided for the function:
fopt = @(x)MyFun(x,pars);
tic;[x,fval] = ga(fopt,N,[],[],[],[],Lower,Upper,[],[],opt.options);toc
function f = MyFun(x,pars)
%LOTS OF STUFF
for j = 1:numel(pars(1))
%LOTS OF STUFF
end
%f = result of lots of stuffy calcuations
Let's have a look at opt.options:
ConstraintTolerance: 1.0000e-08
CrossoverFraction: 0.5000
FunctionTolerance: 3.0000e-31
InitialPopulationMatrix: [65×7 double]
NonlinearConstraintAlgorithm: 'penalty'
CreationFcn: @gacreationuniform
CrossoverFcn: @crossoverscattered
FitnessScalingFcn: @fitscalingrank
InitialPopulationRange: []
MutationFcn: {@mutationgaussian [1] [1]}
PopulationType: 'doubleVector'
SelectionFcn: @selectionstochunif
This code used to run @1.3 s per GA generation with a popualtion of 400. One day, out of the blue, from one run to the next, without even restarting MATLAB, the run became much slower (over a minute per generation). I couldn't think of anything, so instead of reinstalling MATLAB, I recovered an earlier OS image. The code now ran again @1.3 s per GA generation for two times, but the third time I ran it.... again, about ten times slower.
The things to note:
- The time for GA generation seems to be independent of population size! I have never encountered anything like this. I've checked population sizes in the range 66 to 400, and all now run at around 18 s per generation.
- Other calculations, including using parpools, are unaffected. For instance, with an active parpool, the command:
tic;parfor j = 1:30; inv(rand(3e3));end;toc
used to be resolved on average in around seven seconds. This calculation time is not affected by whatever is plaguing the GA module.
Any suggestions would be greatly appreciated.