Genetic Algorithm Plotter does not display

13 次查看(过去 30 天)
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)

回答(1 个)

Walter Roberson
Walter Roberson 2021-10-22
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 个评论
Khaled Mohamed
Khaled Mohamed 2021-10-22
编辑:Khaled Mohamed 2021-10-22
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 2021-10-23
We will probably need all your code and whatever data to test with

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Genetic Algorithm 的更多信息

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by