Optimisation Tool GA Custom Plot
Mostrar comentarios más antiguos
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
Respuesta aceptada
Más respuestas (1)
PB75
el 1 de Abr. de 2021
0 votos
Categorías
Más información sobre Genetic Algorithm en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!