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
참고 항목
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!