How to implement genetic algorithm with complex function based on data?
2 views (last 30 days)
Show older comments
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
0 Comments
Answers (1)
Walter Roberson
on 27 Dec 2019
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.
See Also
Categories
Find more on Genetic Algorithm in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!