フィルターのクリア

Genetic Algorithm Iteration display in command window real time

11 ビュー (過去 30 日間)
Soham
Soham 2015 年 12 月 12 日
編集済み: Marcos Rogério Fernandes 2018 年 11 月 30 日
I was reading the thread http://www.mathworks.com/matlabcentral/answers/180145-saving-showing-value-of-variables-in-genetic-algorithms and had a similar question. I wanted to know whether there is any was to display the best score and the population corresponding to that best score after every generation in the command window while matlab is running the code. Is that possible ?

採用された回答

jgg
jgg 2015 年 12 月 12 日
The suggestion is actually made in the last part of the thread: use an output function. This is a function which you can define which is called at each generation. Then set options = gaoptimset('OutputFcns',@myfun); where @myfun is an anonymous function that uses your output function. It needs to have the structure defined here but it's pretty straightforward.
For instance, you could write an output function which displays the current level, or saves it to a file, or whatever. The information about the current state is here here. For instance, you could just write the function to do disp(state.Best) to accomplish what you want, but I'm sure you could get more creative.

その他の回答 (1 件)

Marcos Rogério Fernandes
Marcos Rogério Fernandes 2018 年 11 月 30 日
編集済み: Marcos Rogério Fernandes 2018 年 11 月 30 日
You can use the "gaoptimset" function to define the parameter "Display" as 'iter', so the command you should use is
[x,fval]=ga(@fitness,nVal,[],[],[],[],[],[],[],gaoptimset("Display","iter"))
So in that way, while matlab is running the ga algoritm it will show in the command window informations about each generation.

カテゴリ

Help Center および File ExchangeGenetic Algorithm についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by