필터 지우기
필터 지우기

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);
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
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
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
Ankur Shah
Ankur Shah 2021년 8월 25일
Thanks for reply. Could you help me with code. I have tried but am unable to save Generations v/s best fitness data.
Alan Weiss
Alan Weiss 2021년 8월 25일
options = optimoptions("ga","OutputFcn",@gascoreoutfun);
rng default % For reproducibility
x = ga(@ps_example,2,[],[],[],[],[],[],[],[],options)
Optimization terminated: average change in the fitness value less than options.FunctionTolerance.
x = 1×2
-4.6793 -0.0860
size(gapopulationhistory)
ans = 1×2
122 2
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 CenterFile Exchange에서 Genetic Algorithm에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by