Optimisation Tool GA Custom Plot
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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
0 Commenti
Risposta accettata
Alan Weiss
il 31 Mar 2021
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
0 Commenti
Più risposte (1)
Vedere anche
Categorie
Scopri di più su Genetic Algorithm in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!