Calling ga creation functions independently

Before running ga(), I would like to do some pre-analysis of the initial population. To this end, is it possible to call the default creation functions used by ga() as independent stand-alone functions?

2 件のコメント

Stephen23
Stephen23 2018 年 10 月 5 日
Have you tried accessing either of them?:
Are they on the MATLAB path, or in a private directory?
Matt J
Matt J 2018 年 10 月 5 日
Interestingly, gacreationuniform() is accessible, but requires input arguments that only ga() knows how to set up.

サインインしてコメントする。

 採用された回答

Matt J
Matt J 2018 年 10 月 5 日
編集済み: Matt J 2018 年 10 月 5 日

0 投票

Here's one method which uses a dummy call to ga() with an OutputFcn. I'm still interested to know if there's a more direct way, however.
function pop=gaPopulation(varargin)
% pop=gaPopulation(varargin)
%
%Get the initial population constructed by ga(varargin{:}).
if numel(varargin) && ...
(isa(varargin{end}, 'optim.options.GaOptions') || isstruct(varargin{end}) )
opts=varargin{end};
if isstruct(opts)
opts=gaoptimset(opts,'OutputFcn',@outputfcn);
else
opts=optimoptions(opts,'OutputFcn',@outputfcn,'Display','none');
end
varargin(end)=[];
else
opts=optimoptions(@ga,'OutputFcn',@outputfcn,'Display','none');
end
varargin(end+1:10)={[]};
pop=[];
ga(varargin{:},opts);
function [state,options,optchanged] = outputfcn(options, state,flag)
optchanged=false;
if strcmp(flag,'init')
pop=state.Population;
state.StopFlag='stop';
end
end
end

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeStartup and Shutdown についてさらに検索

質問済み:

2018 年 10 月 5 日

編集済み:

2018 年 10 月 5 日

Community Treasure Hunt

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

Start Hunting!

Translated by