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
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
Yro 2020 年 10 月 12 日
Thanks for your reply.
Yes, I can execute the code from Matlab, which for each individual in the population I have to execute the code, so I want how I can handle the evaluation of the objective function in Matlab.

サインインしてコメントする。

回答 (2 件)

Star Strider
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
Yro 2020 年 10 月 12 日
Thanks for your answer, I will consult it.
Star Strider
Star Strider 2020 年 10 月 12 日
My pleasure!
Yro
Yro 2020 年 10 月 13 日
Hi, any idea of how I can evaluate in an external code each individual of the population.
Thanks.
Star Strider
Star Strider 2020 年 10 月 13 日
The ga function does that for you in each iteration. The result is the fitness value.
Yro
Yro 2020 年 10 月 13 日
The problem is that each population I need to evaluate in the external simulation code and it returns the value of the objective function. Any idea how you could control each evaluation in Matlab?
Thanks in advance.
Star Strider
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
Yro 2020 年 10 月 13 日
Thank you very much for your explanation. I am attaching a diagram of the problem I want to solve. In each iteration, for each individual in the population, I have to execute the external code (ERANOS code, for example with the system function) to evaluate and return to Matlab the result obtained for the objective function. The results using ga for an arbitrary function is the value its best value in each generation. So I have no information or how you evaluate each solution.
Thanks.
Star Strider
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
Ameer Hamza 2020 年 10 月 13 日
編集済み: Ameer Hamza 2020 年 10 月 13 日

0 投票

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

カテゴリ

製品

リリース

R2019a

質問済み:

Yro
2020 年 10 月 12 日

コメント済み:

2020 年 10 月 13 日

Community Treasure Hunt

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

Start Hunting!

Translated by