Genetic Algorithm Plotter does not display

11 views (last 30 days)
Hi
I'm using the ga optimizer to find some parameters. However, the bestfit plot does not show up at all.
I used this code from the help section
%% Fit options
opts=optimoptions('ga','FunctionTolerance', 1E-9,'MaxGenerations',5000000,'MaxStallGenerations',500000,'HybridFcn','patternsearch', ...
'PlotFcn',{@gaplotbestf,@gaplotchange},'PopulationSize',500,'FitnessLimit',-inf,'MigrationDirection','both');
%% Optimizer
% Do a ro
lb = [ 0 ; 0 ; 0 ];
ub = [ Inf ; 3.0 ; 5.0 ];
f=@(param_vec) e_and_r_vals(param_vec)
[best_fit_param,fval,exitflag,output,population,scores] = ga(f,3,[],[],[],[],lb,ub,[],opts)
Also the below does not show the plot
%% Fit options
opts=optimoptions('ga','FunctionTolerance', 1E-9,'MaxGenerations',5000000,'MaxStallGenerations',500000,'HybridFcn','patternsearch', ...
'PlotFcn','@gaplotbestf','PopulationSize',500,'FitnessLimit',-inf,'MigrationDirection','both');
%% Optimizer
% Do a ro
lb = [ 0 ; 0 ; 0 ];
ub = [ Inf ; 3.0 ; 5.0 ];
f=@(param_vec) e_and_r_vals(param_vec)
[best_fit_param,fval,exitflag,output,population,scores] = ga(f,3,[],[],[],[],lb,ub,[],opts)

Answers (1)

Walter Roberson
Walter Roberson on 22 Oct 2021
opts=optimoptions('ga', 'FunctionTolerance', 1E-9, 'MaxGenerations', 5000000, 'MaxStallGenerations', 500000, 'HybridFcn', 'patternsearch', ...
'PlotFcn', @gaplotbestf, 'PopulationSize', 500, 'FitnessLimit', -inf, 'MigrationDirection', 'both');
You can specify the plot function by name (character vector or string scalar) or by handle. You cannot specify the plot function by character vector that looks sort of like a handle. @gaplotbestf or 'gaplotbestf' not '@gaplotbestf'
  2 Comments
Khaled Mohamed
Khaled Mohamed on 22 Oct 2021
Edited: Khaled Mohamed on 22 Oct 2021
Hi.
I tried that as well but It did not show. The strange thing is that simulated annealing plots show. However, ga and particle swarm plots do not.
Walter Roberson
Walter Roberson on 23 Oct 2021
We will probably need all your code and whatever data to test with

Sign in to comment.

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!