Help with syntax of calling genetic algorithm (ga) function

조회 수: 1 (최근 30일)
Dustyn Roberts
Dustyn Roberts 2013년 10월 8일
댓글: Dustyn Roberts 2013년 10월 8일
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.

답변 (2개)

Sean de Wolski
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
Dustyn Roberts
Dustyn Roberts 2013년 10월 8일
So I should just put
dbstop if error
In a bunch of places to see where is jumps out? The multiplication the way it is works fine with fmincon, so I don't see why it would be an issue calling ga. Thanks.
Sean de Wolski
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
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
  댓글 수: 1
Dustyn Roberts
Dustyn Roberts 2013년 10월 8일
Thanks but I got the same error with mtimes using pattern search as I did with ga. I just tried with fmincon again, no errors. Still confused.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Solver Outputs and Iterative Display에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by