Simon Zehnder
2013-Sep-01 15:09 UTC
[R] How to catch errors regarding the hessian in 'optim'
Dear R-Users and R-Developers, in a comparison between two different estimation approaches I would like to catch errors from optim regarding the hessian matrix. I use optim with method = "L-BFGS-B" thereby relying on numerical differentiation for the hessian matrix. I do know, that the estimation approach that uses numerical optimization has sometimes problems with singular hessian matrices and I consider it as one of its disadvantages of this method. To show the frequency of such problems in my simulation study I have to set 'hessian = TRUE' and to collect the errors from optim regarding the hessian. Now I am a little stucked how I could catch specifically errors from the hessian matrix in 'optim'. I do know that such errors are thrown most certainly from function 'La_solve' in Lapack.c. Does anyone has an idea how I could solve this task (clearly with tryCatch but how to choose only errors for the hessian)? Best Simon
Prof J C Nash (U30A)
2013-Sep-02 14:42 UTC
[R] How to catch errors regarding the hessian in 'optim'
This may be one of the many mysteries of the internals of L-BFGS-B, which I have found fails from time to time. That is one of the reasons for Rvmmin and Rcgmin (and hopefully sooner rather than later Rtn - a truncated Newton method, currently working for unconstrained problems, but still glitchy for bounds constraints). These are all-R codes so that users and developers can get inside to control special situations. If you have a test problem -- the infamous reproducible example -- there are several of us who can likely help to sort out your troubles. JN On 13-09-02 06:00 AM, r-help-request at r-project.org wrote:> Message: 10 > Date: Sun, 1 Sep 2013 17:09:35 +0200 > From: Simon Zehnder<szehnder at uni-bonn.de> > To: R-help help<r-help at r-project.org> > Subject: [R] How to catch errors regarding the hessian in 'optim' > Message-ID:<EB37670E-8544-4C89-9172-245EB6CC596A at uni-bonn.de> > Content-Type: text/plain; charset=us-ascii > > Dear R-Users and R-Developers, > > in a comparison between two different estimation approaches I would like to catch errors from optim regarding the hessian matrix. > > I use optim with method = "L-BFGS-B" thereby relying on numerical differentiation for the hessian matrix. I do know, that the estimation approach that uses numerical optimization has sometimes problems with singular hessian matrices and I consider it as one of its disadvantages of this method. To show the frequency of such problems in my simulation study I have to set 'hessian = TRUE' and to collect the errors from optim regarding the hessian. > > Now I am a little stucked how I could catch specifically errors from the hessian matrix in 'optim'. I do know that such errors are thrown most certainly from function 'La_solve' in Lapack.c. Does anyone has an idea how I could solve this task (clearly with tryCatch but how to choose only errors for the hessian)? > > > Best > > Simon
Michael Meyer
2013-Sep-26 15:49 UTC
[R] How to catch errors regarding the hessian in 'optim'
I am weighing in even though I know nothing. in tryCatch define an error handler error = function(e){ ????text <- print(e)??????? # surely there must be better ways ???? ????# parse text for substring 'optim' or more strongly characteristic substrings ????# you have already seen to emerge from optim ????# do what you have to do if such is detected } Sorry if this answer seems trivial. Michael Meyer