Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

fmincon - NaN ???

42 views
Skip to first unread message

Ka Lee

unread,
Aug 13, 2009, 3:43:04 PM8/13/09
to
Hi,

I am using fmincon to perform my optimization. I set the option so that it displays the iteration history. Something weird happening:

Max Line search Directional First-order
Iter F-count f(x) constraint steplength derivative optimality Procedure
0 18 9900.84 -8.163
1 47 9895.23 -8.163 0.000488 -4.09e+003 5.06e+003
2 78 9894.96 -8.163 0.000122 -2.3e+003 1.15e+003
3 109 9894.43 -8.163 0.000122 -1.31e+003 543
4 137 9893.52 -8.164 0.000977 -15.8 218
5 163 9892.25 -8.167 0.00391 38.9 119
6 185 9890.95 -8.24 0.0625 649 458
7 206 9865.53 -8.642 0.125 285 197
8 228 9864.79 -9.1 0.0625 -30.3 102
9 250 9856.12 -9.024 0.0625 479 163
10 272 9828.1 -10.4 0.0625 54.2 457
11 290 NaN 1.776e-015 1 NaN Inf
12 307 NaN 1.776e-015 2 NaN Inf Hessian not updated
13 324 NaN 1.776e-015 2 NaN Inf Hessian not updated
14 341 NaN 1.776e-015 2 NaN Inf Hessian not updated
15 358 NaN 1.776e-015 2 NaN Inf Hessian not updated
16 375 NaN 1.776e-015 2 NaN Inf Hessian not updated
17 392 NaN 1.776e-015 2 NaN Inf Hessian not updated
18 409 NaN 1.776e-015 2 NaN Inf Hessian not updated
19 426 NaN 1.776e-015 2 NaN Inf Hessian not updated

I suppose this may mean my function has issue. But is there something about fmincon that I can do to try to resolve this problem?

Thanks.

dpb

unread,
Aug 13, 2009, 3:48:36 PM8/13/09
to
Ka Lee wrote:
...

> 10 272 9828.1 -10.4 0.0625 54.2 457
> 11 290 NaN 1.776e-015 1 NaN Inf

...


> I suppose this may mean my function has issue. But is there something
> about fmincon that I can do to try to resolve this problem?

Well, the NaN means your function did something very bad like 0/0 or
other expression to cause the problem.

You'll first want to look at the function itself very closely w/ such
kinds of issues in mind. Especially consider boundary cases of 0.0,
huge(), etc., where things may go south while they don't w/ smaller
values. Underflow owing to the argument of an exponential growing w/o
bound might be an example of the sort of thing to look for. You may be
able to fix those by special cases or rearranging the order of
calculation or other manipulations.

--

Ka Lee

unread,
Aug 13, 2009, 4:22:20 PM8/13/09
to
dpb <no...@non.net> wrote in message <h61re6$dp1$1...@news.eternal-september.org>...

> You'll first want to look at the function itself very closely w/ such
> kinds of issues in mind. Especially consider boundary cases of 0.0,
> huge(), etc., where things may go south while they don't w/ smaller
> values. Underflow owing to the argument of an exponential growing w/o
> bound might be an example of the sort of thing to look for. You may be
> able to fix those by special cases or rearranging the order of
> calculation or other manipulations.
>
> --

Thanks. But could you clarify what you mean by "boundary cases of 0.0,
huge()" ?

dpb

unread,
Aug 13, 2009, 4:44:33 PM8/13/09
to

Look at the output of the function as the inputs approach those values.

For example, y = poly_1(x)/poly_2(x)

what happens if both poly_1 and poly_2 have zero intercepts as x-->0 as
a contrived but simple example.

Other ways to get zero unexpectedly could be exp(-x) as x grows. Again,
if it's in an expression that has another root or other factor one could
get an unrepresentable value.

huge() in ML is actually realmax; I used the Fortran intrinsic by
accident, sorry. There's also realmin. They're the largest and
smallest representable floating point numbers; I'm suggesting see what
your function does as you get to such limits.

Another potential "gotcha" is subtraction of two values--it's possible
each is sizable but their difference is small and could eventually
underflow or leave so few significant bits that subsequent use of the
result of the difference causes later numeric problems.

Read the section in the online help on "Special Values" for a list and
some discussion of what they mean and particularly w/ NaN on how it's
generated.

Also read section on debugging m-files and in particular you may want to
use the feature dbstop on naninf which will cause your function to stop
in the debugger when the nan or an inf is generated. This will then let
you inspect values at the time to add in figuring out what went wrong.

I was simply suggesting you look at the equations in your function first
w/ the idea of what they will do as the input parameters change to the
possible extremes or through zero as a preliminary step--it may, in
fact, be obvious if you look. Since we don't have the function it's not
possible to say "oh, look! There you're dividing by zero if x=2" or
somesuch thing...

--

--

0 new messages