Find values for best and mean fitness value for each generation in Genetic Algorithm
7 ビュー (過去 30 日間)
古いコメントを表示
After running GA, using Optimization toolbox and code below, the following mean and best fitness value graph was obtained.
[x,fval,exitflag,output,population,score] = ...
ga(@revisepartialmodespring,nvars,[],[],[],[],lb,ub,[],[],options);
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/716719/image.png)
How to get the value of best fitness at each generation ?.. I wanted to show a comparison of the best fitness v/s generation for different problems on the same graph. Hence I need values to best fitness at each generation.
1 件のコメント
Debaditya Gupta
2022 年 3 月 31 日
How to get similar type of graph in Particle Swarm Optimization in matlab?
Matlab PSO script is showing only iteration vs best fitnes value, but mean fitness value is not showing
採用された回答
Alan Weiss
2021 年 8 月 22 日
Use a Custom Output Function for Genetic Algorithm. Model it on the gaplotbestf plot function. To see that function,
edit gaplotbestf
Alan Weiss
MATLAB mathematical toolbox documentation
2 件のコメント
Alan Weiss
2021 年 8 月 25 日
options = optimoptions("ga","OutputFcn",@gascoreoutfun);
rng default % For reproducibility
x = ga(@ps_example,2,[],[],[],[],[],[],[],[],options)
size(gapopulationhistory)
function [state,options,optchanged] = gascoreoutfun(options,state,flag)
persistent history
optchanged = false;
switch flag
case 'init'
history = [min(state.Score),mean(state.Score)];
assignin('base','gapopulationhistory',history);
case 'iter'
history = [history;min(state.Score),mean(state.Score)];
assignin('base','gapopulationhistory',history);
case 'done'
end
end
Alan Weiss
MATLAB mathematical toolbox documentation
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Genetic Algorithm についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!