Why does multiobjective genetic algorithm optimization fail with parallel or vectorization on?

조회 수: 2 (최근 30일)
I am using the multiobjective GA optimization with 5 variables and 2 objectives. Everything works fine in serial mode.
My system returns NaN from the function using parallel mode and complains that the function needs to return a vector of length equal to population. Of course, this cannot be true, because it is a multiobjective function, it will not be a vector but an array. Still, I even put a checking step to output the length of the array and it is correct.
I am using global variables in the function itself. The function gives the input vector to a set of neural networks, and returns their response. Then the various results of the neural network ensembles are collected and returned.
The size of the output is equal to [number_of_objectives populationSize], as verified by the output. After the end of the first generation the solver stops and gives the report that the function must return a vector of length equal to the population.
How can a multiobjective function only return a [1 x populationSize] and still work?
Even more strange, parallel mode works, but always returns NaN from the function. I have passed the function vectorized inputs in the normal command window and it returns things as expected.
Any ideas what is wrong? My global variable is a cell array of neural networks. I can post the code, but it isn't likely to be the issue. Still, I will make it available if necessary.
  댓글 수: 2
bumblethumbs
bumblethumbs 2017년 2월 21일
Update: I copied the global variables to local copies as suggested in other parallel literature, and while this worked well, it does use a lot more memory. Fortunately that is an acceptable solution. Any other suggestions would be considered helpful.
Walter Roberson
Walter Roberson 2017년 2월 21일
You can use the shared memory approach I pointed to in my link. But not, I suspect, for global variables. Or perhaps yes for global variables if you share the memory and then assign to a global, counting on copy-on-write.
Note: global variables are the slowest variables of all. If you want fast execution you should not use them.

댓글을 달려면 로그인하십시오.

채택된 답변

Walter Roberson
Walter Roberson 2017년 2월 21일
global variables are not shared with workers in the Parallel Computing Toolbox. You would have to assign relevant values on all of the workers; for example you can use parfEvalOnAll; see also https://www.mathworks.com/matlabcentral/answers/302511-why-does-ga-parallel-global-variables-sub2ind-fail
  댓글 수: 1
bumblethumbs
bumblethumbs 2017년 2월 21일
Thanks! I followed a few links there and was able to quickly see why parallel processing was failing. Vectorization was faster, in the end, but the solutions in the above link helped me see other methods for getting data to the function from the workspace without the global type. Since I was not needing to write to the networks the reference method of a read only copy per worker was acceptable. Thanks for the help!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Genetic Algorithm에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by