How to implement genetic algorithm with complex function based on data?

조회 수: 2 (최근 30일)
Rui Guan
Rui Guan 2019년 12월 27일
댓글: Rui Guan 2019년 12월 28일
Hi Guys,
I am very new to matlab and I am trying to use GA for my optimization problem. Bascially, I am trying the the minimun of the function with my data
Let's say, my function is called MINI, I have three variables for the function.
Two are what I get from my Data, called Data1 and Data2.
The third variable X is my target. It is a vector of length 11, it is a permutation of interger number 1 to 11. For example, [11,1,2,3,4,5,6,8,9,10,7]. or [1,2,3,4,5,6,7,8,9,10,11]
I would like to GA to find the value of X such that FUNC(x,Data1, Data2) is the minimized.
------------------------------------------------------------------------------------------
[X, Y] = ga(@(x)MINI(x,Data,Data2),4)
But it is returning with a million mistakes..
Subscript indices must either be real positive integers or logicals.
Error in createAnonymousFcn>@(x)fcn(x,FcnArgs{:}) (line 11)
fcn_handle = @(x) fcn(x,FcnArgs{:});
Error in makeState (line 47)
firstMemberScore = FitnessFcn(state.Population(initScoreProvided+1,:));
Error in gaunc (line 40)
state = makeState(GenomeLength,FitnessFcn,Iterate,output.problemtype,options);
Error in ga (line 371)
[x,fval,exitFlag,output,population,scores] = gaunc(FitnessFcn,nvars, ...
Caused by:
Failure in initial user-supplied fitness function evaluation. GA cannot continue.
------------------------------------------------------------------------------------------
It seems like a problem of the space of the variable, wow could I specify the domain of my variables?
Thank you very much for your help.
best,
Rui

답변 (1개)

Walter Roberson
Walter Roberson 2019년 12월 27일
You are not using integer constraints or upper or lower bounds, so ga is going to generate x as real numbers. You are then trying to use those real numbers to index arrays, which is going to fail. Furthermore, ga by itself will make no attempt to enforce permutations.
  댓글 수: 1
Rui Guan
Rui Guan 2019년 12월 28일
Thanks for your reply. I struggle to study the linkd you shared. In my case, how should I specify the integar and permuation? Perhaps could you please give an example of permuating v=[1,2,3,4,5]?

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by