Matlab GA toolbox coupling with external simulation code.
이전 댓글 표시
I have the following problem when using GA tool for optimization. My objective function is the result of simulating each population in an external code. My question is: how can I handle the evaluation of the objective function for each population, running the simulation code for each individual.
댓글 수: 2
Ameer Hamza
2020년 10월 12일
Are you able to call the external simulation code from MATLAB, pass it some parameters, and get the output in return?
Yro
2020년 10월 12일
답변 (2개)
Star Strider
2020년 10월 12일
0 개 추천
See if the approach in Parameter Estimation for a System of Differential Equations will do what you want. It uses the ga function to optimise the parameters for differential equations integrated using ode45.
댓글 수: 8
Yro
2020년 10월 12일
Star Strider
2020년 10월 12일
My pleasure!
Yro
2020년 10월 13일
Star Strider
2020년 10월 13일
The ga function does that for you in each iteration. The result is the fitness value.
Yro
2020년 10월 13일
Star Strider
2020년 10월 13일
My pleasure!
I am not certain that I understand what you are asking here.
The ga function evaluates the fitness function for each ‘individual’ in the population each time. It then compares the fitness of the individuals and selects for those with the highest fitness (lowest scalar value of the fitness function). The code I referred to you that adjusts the parameters of the differential equations does exactly what you describe, so you can use it for guidance.
Note that the ‘ftns’ fitness function first calls the objective function ‘kinetics’ that uses the time vector and parameters (that define each ‘individual’ in the population each time) to integrate the differential equation system and return the desired output (here defined as ‘C’). That output is then compared to the concentrations in the ‘c’ matrix and the fitness evaluated for each individual by calculating the norm of the difference.
The ‘external simulation code’ in this example is the ‘kinetics’ function that integrates the differential equations and returns the desired output. That should be analogous to the sort of situation you are describing.
Yro
2020년 10월 13일
Star Strider
2020년 10월 13일
The diagram simply outlines the essence of the genetic algorithm.
You can likely substitute ‘ERANOS’ for ‘kinetics’ in my code, obviously with the appropriate changes. (I have no idea what ‘ERANOS’ is, so I cannot help you with it.)
Ameer Hamza
2020년 10월 13일
편집: Ameer Hamza
2020년 10월 13일
You can write a MATLAB function wrapper around the call to the external simulator. Something like this
function f = objFun(x)
% call your external simulation here, pass value of x
% and return the objective function value y.
y = call_external_simulation(x);
end
카테고리
도움말 센터 및 File Exchange에서 Surrogate Optimization에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!