简体   繁体   English

如何使遗传算法能够收敛(Matlab)

[英]How to allow the genetic algorithm to run to convergence (Matlab)

I am running genetic algorithm using global optimization toolbox in Matlab. 我正在使用Matlab中的全局优化工具箱来运行遗传算法。 I want to allow the algorithm to run until the difference between the best value is <=10^{-15}. 我要允许算法运行,直到最佳值之间的差为<= 10 ^ {-15}。 I tried to use ftol and ctol for this purpose but the algorithm terminates at 541 iterations. 我试图为此目的使用ftol和ctol,但是该算法在541次迭代时终止。 Any suggestions will be appreciated! 任何建议将不胜感激!

An example of my objective function is below: 我的目标函数的示例如下:

function y=objfun(x)
  t = [3,227,342,351,353,444,556,571,759,836];
  n= length(t);
  sumt = sum(t);
    y = -(- x(1)*(1-exp(-x(2)*t(n)))  + n*log(x(2)));
end

and the GA code is GA代码是

options.TolFun=1e-15;
%options.TolCon=1e-15;
format longG
[x,fval] = ga(@objfun,2,[],[],[],[],[10 0.001],[20 0.1])

Here are a full list of stop criteria you can modify: 这是您可以修改的停止条件的完整列表:

% default options
options = optimoptions('ga');

% stop criteria
options = optimoptions(options,'MaxGenerations', MaxGenerationsVal); % number of generations
options = optimoptions(options,'MaxTime', MaxTimeVal); % time limit
options = optimoptions(options,'FitnessLimit', FitnessLimitVal); % fitness limit
options = optimoptions(options,'MaxStallGenerations', MaxStallGenerationsVal); % stall generation
options = optimoptions(options,'MaxStallTime', MaxStallTimeVal); % stall time limit
options = optimoptions(options,'FunctionTolerance', FunctionToleranceVal); % function tolerance
options = optimoptions(options,'ConstraintTolerance', ConstraintToleranceVal); % constraint tolerance

[x,fval] = ga(@objfun,2,[],[],[],[],[10 0.001],[20 0.1],[],[],options);

I haven't tested the code. 我还没有测试代码。 Let me if this helps :) 让我来帮忙:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM