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 Center および File ExchangeGenetic Algorithm についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by