Optimization using parallel-computing is returning optimized vector that does not match the reward provided.
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I am using MATLAB to run an optimization that calls on a Simulink model to optimize the joint angles of a walking robot. Due to the complexity of the optimization I am using the ga optimization function in matlab and the parallel-computing functionality to help speed up the process. I am running into an issue that when the optimization finishes it returns the reward and optimized vector of variables, however, when I take that array of variables and put it back into the objective function the value obtained does not match the reward value returned from ga. This problem does not occur if I remove the parallel-computing functionality, however, it drastically increases the time for the program to run to well over a day. Has anyone encountered a problem like this in the past?
0 commentaires
Réponse acceptée
Rakesh Kumar
le 30 Jan 2023
Hi Aaron,
Optimization solvers often does not work with "UseParallel == true" option when a Simulink model is part of objective/fitness function evaluation. This has to do with the Simulink model not being available on PCT engines in a reliable way when using PARFOR. Optimization solvers use PARFOR to evaluate the objective function in parallel. Hence, no support for Simulink when using GA or other optimization solvers. See limitations here:
https://www.mathworks.com/help/gads/how-solvers-compute-in-parallel.html
In your case, it is likely that GA is getting incorrect reward (fitness) value when running in parallel, so the result is useless.
If you want to make use of PCT with GA for Simulink, you will have to do your own parallel evaluation using PARSIM. See here:
When you can evaluate your function in parallel, use the option "UseVectorized == true" with GA. This setting will have GA send your objective the entire population to evaluate and you can evaluate them using PARSIM
I do not have an example using GA but I have something using another solver "surrogateopt". You can use this example to write something for GA. Focus on how the objective function can use PARSIM in this example.
Hth,
Rakesh
3 commentaires
Rakesh Kumar
le 31 Jan 2023
Hi Aaron,
GA should honor the population size you specify and should not override this based on number of cores. However, there are few things you must do.
For an efficient parallel optimization, it will make sense to keep all the cores busy as much as possible. Set the population size to an integer multiple of number of cores to do this.
In the example from surrogateopt the N (BatchUpdateInterval) is set to the number of cores (6) but it can be any multiple of the number of cores. It also sets the MaxFunctionEvaluations option to 600 (multiple of 6). There are other algorithmic reasons in surrogateopt to keep BatchUpdateInterval == 6
For GA, you can have to set the PopulationSize = 6*k (some multple k) ahead of time. And make sure you create as many SimulationInput objects (see the example demo)
simIn(1:PopulationSize) = Simulink.SimulationInput(model);
Pass the PopulationSize option to GA and I think the objective function should just work.
I am very appreciative of you putting in the work for this.
Thanks,
Rakesh
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Manual Performance Optimization dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!