Thread Subject: Matlab's fmincon and other optimization functions are so difficult to debug...

Subject: Matlab's fmincon and other optimization functions are so difficult to debug...

From: Vista

Date: 7 Jun, 2007 01:57:44

Message: 1 of 3

Hi all,

Is there a way to debug into the objective function of "fmincon"?

I found that the debugging of optimization code in Matlab is extremely hard.
Basically, "fmincon" and all other Matlab optimization functions just don't
allow debugging into the objective function, even when I turn on "stop when
errors" option in Matlab.

Is there any good way to handle this difficulty? Staring at code for hours
and hours doesnot help debugging at all. And the productivity is low when
optimization code is involved. Especially for those hard-to-catch type of
bugs, after hours or days of running, if the Matlab optimizer doesn't allow
debugging into the objective function, then it's hard to capture the bug...

Any thoughts? Thanks a lot!

Subject: Matlab's fmincon and other optimization functions are so difficult to debug...

From: Marcus M. Edvall

Date: 7 Jun, 2007 05:20:15

Message: 2 of 3

Have you used keyboard? try-catch.

Best wishes, Marcus
Tomlab Optimization Inc.
 <http://tomopt.com>

Subject: Matlab's fmincon and other optimization functions are so difficult to debug...

From: Steven Lord

Date: 7 Jun, 2007 09:31:53

Message: 3 of 3


"Vista" <abc@gmai.com> wrote in message
news:f48h9q$no3$1@news.Stanford.EDU...
> Hi all,
>
> Is there a way to debug into the objective function of "fmincon"?
>
> I found that the debugging of optimization code in Matlab is extremely
> hard. Basically, "fmincon" and all other Matlab optimization functions
> just don't allow debugging into the objective function, even when I turn
> on "stop when errors" option in Matlab.

I'm guessing you changed the options in the Errors tab of the "Stop if
Errors/Warnings" dialog (or used "dbstop if error".) When the Optimization
Toolbox functions, like FMINCON, call your function they call it inside a
TRY/CATCH block (so they can catch the error and exit gracefully, rather
than having their execution stopped immediately when the error occurs. You
want to change the options in the Try/Catch Errors tab instead (or use
"dbstop if all error" or "dbstop if caught error", depending on which
version of MATLAB you're using.)

However, there's another option, and that is to test your function outside
of FMINCON. It's a good idea to perform unit testing on your function
before you try to use it in your application. That way you hopefully don't
run into a problem in your code in the middle of an optimization, which
would mean you'd need to rerun the whole optimization.

--
Steve Lord
slord@mathworks.com

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread

Contact us at files@mathworks.com