Can genetic algorithm be nested?
6 ビュー (過去 30 日間)
古いコメントを表示
i want to have a code that does double optimization
i want the ga to first assume a vector q of 1s and 0s, then for each member in the population before calculating the fitness i want it to assume another vector which is the coefficients of q or if possible, only the elements that are assumed to be 1 in vector q. is a double optimization in the genetic algorithm possible ??
can i put a line that calls the ga toolbox in the fitness function for example ??
0 件のコメント
回答 (1 件)
Stephan
2019 年 6 月 28 日
編集済み: Stephan
2019 年 6 月 28 日
It should be possible in one single call of ga. In this case nvars would be 2*numel(q) and you have to set the correct bounds and intcon correctly.
Then in the first half set of variables ga assumes 0/1 for q and the second half set is used for the assumed coefficients that are multiplied by the assumed q-values. Since some of them are 0 the multiplication with a coefficient would still be zero.
See this example:
function myfitness = myFitness(x)
q = x(1):x(numel(x)/2);
coeffs = x((numel(x)/2)+1):x(end);
q_coeffs = coeffs.*q;
% Caculate your fitness value
myfitness = q_coeffs * something - m*c^2; % Your fitness calculation...
end
What would happen for this example:
ga assumes:
x(1) = 1
x(2) = 0
x(3) = 1
x(4) = 0.1
x(5) = 0.5
x(6) = 0.25
q_coeffs = [0.1*1, 0.5*0, 0.25*1] = [0.1 0 0.25]
2 件のコメント
Stephan
2019 年 7 月 1 日
The problem is, that you need to know the number of vars before starting ga. But i doubt that it takes less time to start ga twice. 128 decision variables is not a big optimization problem. I would try this way, since it is easy to program and to understand. If you program it in a vectorized manner, this part should run quickly.
参考
カテゴリ
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!