genetic algorithm fintess function
3 次查看(过去 30 天)
显示 更早的评论
Hi,
I need help with figuring out how to start with my genetic algorithm code for my problem. Especially figuring out the firness/objective function for my problem. The aim to produce two continouos optimised values.
Any help with be appreciated.
4 个评论
Walter Roberson
2019-3-4
Why bother to run that through ga? Why not just say x = FTe and y = FTi ?
You can use the options to configure a FitnessLimit of 0.01 .
采纳的回答
Walter Roberson
2019-3-4
编辑:Walter Roberson
2019-3-4
FTe = randn() * 10;
FTi = randn() * 10;
H = @(xy) 0.5 * (xy(1) - FTe).^2 .* 0.5*(xy(2) - FTi).^2;
good_enough = 0.01;
nvar = 2;
A = []; b = [];
Aeq = []; beq = [];
lb = zeros(1, nvar); %lower bound 0
ub = ones(1, nvar); %upper bound 1
nlcon = [];
options = optimoptions('ga', 'display', 'iter', 'FitnessLimit', good_enough);
[xy, fval] = ga(H, nvar, A, b, Aeq, beq, lb, ub, nlcon, options )
ga does not care whether the formula gives 0: ga will keep minimizing until either the target fitness is reached (if one was specified), or until it decide that there have been no improvements for a sufficiently long time, or until it has executed the function more times that it has been configured to try. It is just that function value 0 (such as a residue function) or function value -infinity are the two common cases for knowing when to stop: if you do not know what the global minima is for your objective function, then it is hard to know if ga did a good enough job.
With the random FTe and FTi that I put in for this sample code, if the random values are outside of the lower bound to upper bound range, ga will keep bouncing off the ends of the ranges until it gives up. If, though, the random FTe and FTi happen to be in the 0 to 1 range, then with that particular formula, ga will need only a small number of iterations to reach the target you asked for.
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Genetic Algorithm 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!