How can I convert symbolic equation to fitness function which can be evaluated by genetic algorithm
3 次查看(过去 30 天)
显示 更早的评论
Hi,
I have a symbolic equation and wish to convert to a function which can be evaluated by genetic algorithm (ga). I have tried using the matlabFunction and convert the symbolic equation into a matlab file. However, this generated file can only be evaluated by fmincon or patternsearch algorithms and not genetic algorithm. I get this error using ga.
Caused by: Failure in initial user-supplied fitness function evaluation. GA cannot continue.
It seems like the matlabFunction does not generate the format required by ga, can anyone please advise what's the solution/workaround to this problem?
Thanks!
0 个评论
回答(3 个)
Alan Weiss
2014-1-22
fmincon and patternsearch expect that the variable x is a column, though they are pretty forgiving if it is something else. ga expects that x is a row. So perhaps you should have
X = sym('x',[1 2*N]);
I could not check this because I do not know what P and price are.
Alan Weiss
MATLAB mathematical toolbox documentation
1 个评论
Ashley Thornton
2015-8-20
Thanks so much. I was having the exact same problem, your solution worked a treat.
Walter Roberson
2014-1-21
Please show symvars() of the symbolic expression, and show the call to matlabFunction that you used. Please also show the first bit of the generated function -- in particular, the part inside the @() header. Please show your call to ga()
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Genetic Algorithm 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!