Help with syntax of calling genetic algorithm (ga) function
1 次查看(过去 30 天)
显示 更早的评论
I have a fairly complex optimization problem set up that I've solved through fmincon by calling it like this
myfun = @(x5) 0.5 * (norm(C*x5 - d))^2 + 0.5 * (timeIntervalMeanGlobal * powerAbsMaxMaxGlobal * sum(x5(28:128),1))^2;
[x5, fval] = fmincon(myfun, initialGuess, -A, b, Aeq, beq, lb, []);
The components are far to long to print here, but here are the dimensions
C: 49 x 128 x5: 128 x 1 d: 49 x 1 timeIntervalMeanGlobal, powerAbsMaxMaxGlobal: constants initialGuess: 128 x 1 A: 44541 x 128 b: 44541 x 1 Aeq: 24 x 128 beq: 24 x 1 lb: 128 x 1
This works in code, but I don't get results that I'm completely happy with. I'd like to compare it with the built in ga function in MATLAB, which is called in a similar way, but I get an error when I try to run it like this
[x5, fval] = ga(myfun, nvars, -A, b, Aeq, beq, lb, []);
where nvars = 128. There's a long list of about 8 errors starting with
??? Error using ==> mtimes
Inner matrix dimensions must agree.
and ending with
Caused by:
Failure in user-supplied fitness function evaluation. GA cannot continue.
Can someone please instruct me on how to call ga properly, and give insight on why this error might occur with the ga call when the same code doesn't cause an error with fmincon? I've tried all the MATLAB help files and examples with a few different permutations of this but no better luck. Thanks.
0 个评论
回答(2 个)
Sean de Wolski
2013-10-8
编辑:Sean de Wolski
2013-10-8
I would try:
dbstop if error
To stop with the debugger when the error occurs. It looks like you may need to change a matrix multiplication to an elementwise one.
2 个评论
Sean de Wolski
2013-10-8
No. Run this command once at the command prompt (or go to Editor Tab, break points, stop on errors). Now the next time (and every time) an error occurs, the debugger will stop on the offending line whereever it is and you can investigate what is going on (i.e. what variables/functions/etc) are being called and how this differs from what you expect.
Alan Weiss
2013-10-8
I do not understand what is going on. But I suggest that you try patternsearch instead of ga. patternsearch is usually faster, more reliable, and easier to tune than ga. The patternsearch calling syntax is identical to fmincon's.
Alan Weiss
MATLAB mathematical toolbox documentation
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Surrogate Optimization 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!