필터 지우기
필터 지우기

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

조회 수: 2 (최근 30일)
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
%
expectation=(expectation(:,1));
parents=zeros(1,nParents);
%% Sorting accordance with fitness value
A=sort(expectation);
B=A(1);
%% Select Global Best
GBparents(1,1)=find(expectation==B(1,1));
%% Select Parents Randomly
RN=randperm(nParents);
parents=[GBparents RN(1:nParents-1)];
end
Please check my code and tell me what is the problem.
Thank you.

답변 (1개)

Alan Weiss
Alan Weiss 2019년 2월 19일
I am not sure, but I am suspicious of the line
GBparents(1,1)=find(expectation==B(1,1));
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?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Genetic Algorithm에 대해 자세히 알아보기

제품


릴리스

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by