nlminb supplying NaN parameters to objective function

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

nlminb supplying NaN parameters to objective function

Prof J C Nash (U30A)
Your problem is saying (on my machine) that it cannot compute the
gradient. Since it does this numerically, my guess is that the step to
evaluate the gradient violates the bounds and we get log(-something).

I also get

> Warning messages:
> 1: In dnbinom(x = dummyData[, "Y"], mu = mu, size = params[length(params)],  :
>   NaNs produced
> 2: In nlminb(start = sv, objective = nLL, lower = 0, upper = Inf, control = list(trace = TRUE)) :
>   NA/NaN function evaluation
> 3: In dnbinom(x = dummyData[, "Y"], mu = mu, size = params[length(params)],  :
>   NaNs produced
> 4: In nlminb(start = sv, objective = nLL, lower = 0, upper = Inf, control = list(trace = TRUE)) :
>   NA/NaN function evaluation



I put lower=0.01 and got convergence OK, but that may not be suitable,
since all but one of the parameters are at that bound.

> $par
>  [1] 0.01000000 0.01000000 0.01000000 0.01000000 0.01000000 0.01000000
>  [7] 0.01000000 0.01000000 0.01000000 0.01000000 0.01000000 0.01000000
> [13] 0.09168027
>
> $objective
> [1] 11879.51
>
> $convergence
> [1] 0
>
> $iterations
> [1] 8
>
> $evaluations
> function gradient
>       13      119
>
> $message
> [1] "relative convergence (4)"


As it turns out, Duncan Murdoch, Ben Bolker and I had a meeting
yesterday to discuss improvements in optimization and nonlinear least
squares and derivatives. One suggestion to be implemented is a wrapper
for objective functions to reveal when bounds are violated. It will,
however, take a little time for me to get that organized.

FYI, without the reproducible example, you would not have received this
attempt to explain things. Thanks.

JN



> A follow-up to my yesterday's email.
>
> I was able to make a reproducible example. All you will have to do is
> load the .RData file that you can download here:
> https://drive.google.com/file/d/0B0DKwRjF11x4dG1uRWhwb1pfQ2s/view?usp=sharing
>
> and run this line of code:
>
> nlminb(start=sv, objective = nLL, lower = 0, upper = Inf,
> control=list(trace=TRUE))
>
> which output the following:
>
>   0:     12523.401: 0.0328502 0.0744493 0.00205298 0.0248628 0.0881807
> 0.0148887 0.0244485 0.0385922 0.0714495 0.0161784 0.0617551 0.0244901
> 0.0784038
>   1:     12421.888: 0.0282245 0.0697934  0.00000 0.0199076 0.0833634
> 0.0101135 0.0189494 0.0336236 0.0712130 0.0160687 0.0616015 0.0244689
> 0.0660129
>   2:     12050.535: 0.00371847 0.0451786  0.00000  0.00000 0.0575667
> 0.00000  0.00000 0.00697067 0.0697205 0.0156250 0.0608550 0.0243431
> 0.0994355
>   3:     12037.682: 0.00303460 0.0445012  0.00000  0.00000 0.0568530
> 0.00000  0.00000 0.00636016 0.0696959 0.0156250 0.0608550 0.0243419
> 0.0988824
>   4:     12012.684: 0.00164710 0.0431313  0.00000  0.00000 0.0554032
> 0.00000  0.00000 0.00515500 0.0696451 0.0156250 0.0608550 0.0243395
> 0.0978328
>   5:     12003.017: 0.00107848 0.0425739  0.00000  0.00000 0.0548073
> 0.00000  0.00000 0.00469592 0.0696233 0.0156250 0.0608550 0.0243386
> 0.0974616
>   6:     11984.372:  0.00000 0.0414397  0.00000  0.00000 0.0535899
> 0.00000  0.00000 0.00378996 0.0695782 0.0156250 0.0608550 0.0243370
> 0.0967449
>   7:     11978.154:  0.00000 0.0409106  0.00000  0.00000 0.0530158
> 0.00000  0.00000 0.00340746 0.0695560 0.0156250 0.0608550 0.0243363
> 0.0964537
>   8:    -0.0000000:  0.00000      nan  0.00000  0.00000      nan
> 0.00000  0.00000      nan      nan      nan      nan      nan      nan
>
> Regards,
>
> Jean
>
> 2015-05-06 17:43 GMT-07:00 Jean Marchal <[hidden email]>:
>> Dear list,
>>
>> I am doing some maximum likelihood estimation using nlminb() with
>> box-constraints to ensure that all parameters are positive. However,
>> nlminb() is behaving strangely and seems to supply NaN as parameters
>> to my objective function (confirmed using browser()) and output the
>> following:
>>
>> $par
>>  [1] NaN NaN NaN   0 NaN   0 NaN NaN NaN NaN NaN NaN NaN
>>
>> $objective
>> [1] 0
>>
>> $convergence
>> [1] 1
>>
>> $iterations
>> [1] 19
>>
>> $evaluations
>> function gradient
>>       87      542
>>
>> $message
>> [1] "gr cannot be computed at initial par (65)"
>>

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: nlminb supplying NaN parameters to objective function

Jean Marchal
Prof. Nash,

awesome! This sounds promising.

Thank you for the explanation,

Jean

2015-05-08 14:16 GMT-07:00 Prof J C Nash (U30A) <[hidden email]>:

> Your problem is saying (on my machine) that it cannot compute the
> gradient. Since it does this numerically, my guess is that the step to
> evaluate the gradient violates the bounds and we get log(-something).
>
> I also get
>
> > Warning messages:
> > 1: In dnbinom(x = dummyData[, "Y"], mu = mu, size =
> params[length(params)],  :
> >   NaNs produced
> > 2: In nlminb(start = sv, objective = nLL, lower = 0, upper = Inf,
> control = list(trace = TRUE)) :
> >   NA/NaN function evaluation
> > 3: In dnbinom(x = dummyData[, "Y"], mu = mu, size =
> params[length(params)],  :
> >   NaNs produced
> > 4: In nlminb(start = sv, objective = nLL, lower = 0, upper = Inf,
> control = list(trace = TRUE)) :
> >   NA/NaN function evaluation
>
>
>
> I put lower=0.01 and got convergence OK, but that may not be suitable,
> since all but one of the parameters are at that bound.
>
> > $par
> >  [1] 0.01000000 0.01000000 0.01000000 0.01000000 0.01000000 0.01000000
> >  [7] 0.01000000 0.01000000 0.01000000 0.01000000 0.01000000 0.01000000
> > [13] 0.09168027
> >
> > $objective
> > [1] 11879.51
> >
> > $convergence
> > [1] 0
> >
> > $iterations
> > [1] 8
> >
> > $evaluations
> > function gradient
> >       13      119
> >
> > $message
> > [1] "relative convergence (4)"
>
>
> As it turns out, Duncan Murdoch, Ben Bolker and I had a meeting
> yesterday to discuss improvements in optimization and nonlinear least
> squares and derivatives. One suggestion to be implemented is a wrapper
> for objective functions to reveal when bounds are violated. It will,
> however, take a little time for me to get that organized.
>
> FYI, without the reproducible example, you would not have received this
> attempt to explain things. Thanks.
>
> JN
>
>
>
> > A follow-up to my yesterday's email.
> >
> > I was able to make a reproducible example. All you will have to do is
> > load the .RData file that you can download here:
> >
> https://drive.google.com/file/d/0B0DKwRjF11x4dG1uRWhwb1pfQ2s/view?usp=sharing
> >
> > and run this line of code:
> >
> > nlminb(start=sv, objective = nLL, lower = 0, upper = Inf,
> > control=list(trace=TRUE))
> >
> > which output the following:
> >
> >   0:     12523.401: 0.0328502 0.0744493 0.00205298 0.0248628 0.0881807
> > 0.0148887 0.0244485 0.0385922 0.0714495 0.0161784 0.0617551 0.0244901
> > 0.0784038
> >   1:     12421.888: 0.0282245 0.0697934  0.00000 0.0199076 0.0833634
> > 0.0101135 0.0189494 0.0336236 0.0712130 0.0160687 0.0616015 0.0244689
> > 0.0660129
> >   2:     12050.535: 0.00371847 0.0451786  0.00000  0.00000 0.0575667
> > 0.00000  0.00000 0.00697067 0.0697205 0.0156250 0.0608550 0.0243431
> > 0.0994355
> >   3:     12037.682: 0.00303460 0.0445012  0.00000  0.00000 0.0568530
> > 0.00000  0.00000 0.00636016 0.0696959 0.0156250 0.0608550 0.0243419
> > 0.0988824
> >   4:     12012.684: 0.00164710 0.0431313  0.00000  0.00000 0.0554032
> > 0.00000  0.00000 0.00515500 0.0696451 0.0156250 0.0608550 0.0243395
> > 0.0978328
> >   5:     12003.017: 0.00107848 0.0425739  0.00000  0.00000 0.0548073
> > 0.00000  0.00000 0.00469592 0.0696233 0.0156250 0.0608550 0.0243386
> > 0.0974616
> >   6:     11984.372:  0.00000 0.0414397  0.00000  0.00000 0.0535899
> > 0.00000  0.00000 0.00378996 0.0695782 0.0156250 0.0608550 0.0243370
> > 0.0967449
> >   7:     11978.154:  0.00000 0.0409106  0.00000  0.00000 0.0530158
> > 0.00000  0.00000 0.00340746 0.0695560 0.0156250 0.0608550 0.0243363
> > 0.0964537
> >   8:    -0.0000000:  0.00000      nan  0.00000  0.00000      nan
> > 0.00000  0.00000      nan      nan      nan      nan      nan      nan
> >
> > Regards,
> >
> > Jean
> >
> > 2015-05-06 17:43 GMT-07:00 Jean Marchal <[hidden email]>:
> >> Dear list,
> >>
> >> I am doing some maximum likelihood estimation using nlminb() with
> >> box-constraints to ensure that all parameters are positive. However,
> >> nlminb() is behaving strangely and seems to supply NaN as parameters
> >> to my objective function (confirmed using browser()) and output the
> >> following:
> >>
> >> $par
> >>  [1] NaN NaN NaN   0 NaN   0 NaN NaN NaN NaN NaN NaN NaN
> >>
> >> $objective
> >> [1] 0
> >>
> >> $convergence
> >> [1] 1
> >>
> >> $iterations
> >> [1] 19
> >>
> >> $evaluations
> >> function gradient
> >>       87      542
> >>
> >> $message
> >> [1] "gr cannot be computed at initial par (65)"
> >>
>
>

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.