From: Robin Deits on 6 Jul 2010 04:34 I have been experimenting with the Matlab GA from the Genetic Algorithm and Direct Search Toolbox, Matlab 7.7.0 (R2008b). I have noticed a strange trend in the way the GA seems to perform, in that it seems to vectorize my fitness function, even when I have explicitly told it not to. My setup is as follows: fitnessFunc = @costFunction nvars = 5 A = []; B = []; Aeq = []; Beq = []; LB = <a 1x5 vector of minimums> UB = <a 1x5 vector of maximums> nonlcon = []; options = gaoptimset('Vectorized','off'); [x fval exitflag output population scores] = ga(fitnessFunc,nvars,A,b,Aeq,Beq,LB,UB,nonlcon,options); Where costFunction is a function that takes a vector x and returns a scalar, as it should. Here's where it gets weird: When I run the above code within my script, it generates an initial 1x5 vector for the input to costFunction (I can see this because costFunction prints out its own inputs), which then is evaluated. However, on some subsequent call to costFunction, often but not necessarily the second one, the GA calls costFunction with a 20x5 array of inputs which appears to be the entire population for the first generation of the algorithm and which causes costFunction to fail. This is exactly what it should be doing if it were to vectorize the fitness function, but I have explicitly told it not to do so (and besides, the default is 'off' anyway). Does anyone have any idea why this should be happening? It seems to be somehow related to the specific cost function I'm using (i.e. replacing my cost function with something like @(x) sum(x) causes the problem not to occur). In my case, costFunction performs a simulation using OctaveFEMM, which I have successfully integrated with Matlab's fminsearch in the past. I would really appreciate any help you can offer.
From: Robin Deits on 6 Jul 2010 04:42 Apologies -- there's another clue that I failed to mention. As far as I can tell from reading the outputs at various stages in costFunction, it appears that not only is costFunction incorrectly called with an array of inputs rather than a vector, but this incorrect call occurs partway through a previous run of costFunction, before that run has even returned an answer.
From: Robin Deits on 6 Jul 2010 06:30 Aha! I seem to have figured it out on my own. The problem was that certain parameters generated by the GA resulted in costFunction throwing an error. However, rather than stopping at this error as it normally would, the Matlab GA, for whatever reason, would attempt to evaluate the entire population at once, which would then cause an error and halt execution. This is probably due to the try...catch structure in makeState.m in the GA toolbox.
|
Pages: 1 Prev: read mat file in C++ Next: How to generate random matrix with constraints? |