Optimisation Tool GA Custom Plot

조회 수: 2 (최근 30일)
PB75
PB75 2021년 3월 31일
답변: PB75 2021년 4월 1일
Hi All,
Have searched through the previous questions posted on custom plots and output functions in optimisation toolbox using the GA solver, however, still need some guidance please.
My optimisation problem has 2 variables k(1) & k(2) (PI gains) and the fitness function is to minimum ITAE seen by the controller.
For my report I would like to plot the 2 variables and the fitness function value at the end of each generation (25) to show how the variables and the ITAE change, in a surface plot or heat plot.
I have tried to use @gaplotchange as a starting point, however this shows and error "Too many ouput arguments".
Can anyone help with modifying the 'gaplotchange' code or suggest a better 'PlotFnc' to plot a surface or heat plot at each generation?
Can the history be outputed to the workspace with a predefined output function?
Additionally, does the function get called from the Optimisation Tool>Options>Output function>Custom function ?
function state = gaplotchange(options, state, flag)
% GAPLOTCHANGE Plots the logarithmic change in the best score from the
% previous generation.
%
persistent last_best % Best score in the previous generation
if(strcmp(flag,'init')) % Set up the plot
xlim([1,options.MaxGenerations]);
axx = gca;
axx.YScale = 'log';
hold on;
xlabel Generation
title('Log Absolute Change in Best Fitness Value')
end
best = min(state.Score); % Best score in the current generation
if state.Generation == 0 % Set last_best to best.
last_best = best;
else
change = last_best - best; % Change in best score
last_best = best;
if change > 0 % Plot only when the fitness improves
plot(state.Generation,change,'xr');
end
end
Thanks
patrick

채택된 답변

Alan Weiss
Alan Weiss 2021년 3월 31일
Perhaps if you put the names of the functions in curly braces {} you would have success:
{@gaplotbestf,@gaplotchange}
But come to think of it, gaplotbestf is a built in PLOT function, not an OUTPUT function. Maybe you should include the check mark for gaplotbestf in the plot function section and just include the handle for gaplotchange in the output function section.
Alan Weiss
MATLAB mathematical toolbox documentation

추가 답변 (1개)

PB75
PB75 2021년 4월 1일
Hi Alan,
Thanks for your reply.
Error "Too many ouput arguments" was due to me putting the "aplotchange" function in the output function section, needs to be in the plot section.
Cheers

카테고리

Help CenterFile Exchange에서 Genetic Algorithm에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by