MATLAB Answers

How to write selection function in genetic algorithm(Global Optimization Toolbox: ga)

7 ビュー (過去 30 日間)
Jungeon Kim
Jungeon Kim 2019 年 2 月 19 日
コメント済み: Jungeon Kim 2019 年 2 月 20 日
Hi guys.
I have some problem to use the genetic algorithm.
I want to use customized selection function, but I can only see error message: Index exceeds matrix dimensions
Here is my code below:
function parents=AGAselection(expectation, nParents, options)
% nParents= the number of parents
% A= sorted expectation
% B= expectation of nParents top parents
% GBparents= global best parents
%% Sorting accordance with fitness value
%% Select Global Best
%% Select Parents Randomly
parents=[GBparents RN(1:nParents-1)];
Please check my code and tell me what is the problem.
Thank you.

  0 件のコメント

サインイン to comment.

回答 (1 件)

Alan Weiss
Alan Weiss 2019 年 2 月 19 日
I am not sure, but I am suspicious of the line
What makes you think that expectation==B(1,1) has just one element?
Alan Weiss
MATLAB mathematical toolbox documentation

  1 件のコメント

Jungeon Kim
Jungeon Kim 2019 年 2 月 20 日
The code is referred to the page above.
He said his problem is solved.
I don't know the structure of parents(I think the parents is vector that consists of cell.)
I want to extract just best parent.
Is there any problem in the line?

サインイン to comment.

サインイン してこの質問に回答します。

Translated by