[Rd] Wierd nlm behaviour in 2.10.1 and 2.12.0 [Sec=Unclassified]

Ravi Varadhan rvaradhan at jhmi.edu
Thu Oct 14 05:21:05 CEST 2010


The scaling change that I did is extremely simple.  I just divided the objective function by `Abund' (actually, Abund^2).  Dividing a function by a constant (positive) factor does not change the optimum (minimum), so this is perfectly legal.  

Ravi.
____________________________________________________________________

Ravi Varadhan, Ph.D.
Assistant Professor,
Division of Geriatric Medicine and Gerontology
School of Medicine
Johns Hopkins University

Ph. (410) 502-2619
email: rvaradhan at jhmi.edu


----- Original Message -----
From: Troy Robertson <Troy.Robertson at aad.gov.au>
Date: Wednesday, October 13, 2010 9:08 pm
Subject: RE: [Rd] Wierd nlm behaviour in 2.10.1 and 2.12.0 [Sec=Unclassified]
To: 'Ravi Varadhan' <rvaradhan at jhmi.edu>, "'r-devel at R-project.org'" <r-devel at r-project.org>


> Thanks heaps Ravi,
>  
>  I will have to take the modified function to my modeller/statistician 
> and get him to check it out as I am only a general programmer and do 
> not understand the significance of your suggested changes.  Your 
> changes do look to produce consistent results though and as John Nash 
> pointed out in an email, the returned 'code' value was originally 5, 
> indicating a failure.  So it looks like the code I have been using has 
> always been producing erroneous output data :-(
>  
>  Still not sure why there is a difference between:
>  nlm(...)$estimate
>  AND
>  a<-nlm(...)
>  a$estimate
>  in R2.10.1 and R2.12.0beta though but not R2.11.1?
>  Even if nlm() is failing it should show consistent output I would 
> have thought?
>  
>  Thanks again for your suggestions Ravi.
>  
>  Troy
>  
>  
>  
>  > -----Original Message-----
>  > From: Ravi Varadhan [
>  > Sent: Thursday, 14 October 2010 2:29 AM
>  > To: 'Ravi Varadhan'; Troy Robertson; 'r-devel at R-project.org'
>  > Subject: RE: [Rd] Wierd nlm behaviour in 2.10.1 and 2.12.0
>  > [Sec=Unclassified]
>  >
>  >
>  > Try this:
>  >
>  > Myfunc2 <- function(rootM,Abund,Loss,OtherM) {
>  > # I have scaled the function
>  > (Loss/Abund - (rootM/(rootM+OtherM)*
>  >       (1-exp(-(rootM+OtherM)))))^2
>  > }
>  >
>  >
>  > nlm(myfunc2
>  >    ,0.001,print.level=0,fscale=0, gradtol=1E-10, stepmax = 100.0
>  >    ,Loss=FixedRemovals
>  >    ,Abund=AbStageInitial
>  >    ,OtherM=Rates)$estimate
>  >
>  > This should work quite robustly under various R versions on
>  > different platforms.
>  >
>  > Ravi.
>  >
>  > -----Original Message-----
>  > From: r-devel-bounces at r-project.org
>  > [
>  > On Behalf Of Ravi Varadhan
>  > Sent: Wednesday, October 13, 2010 9:27 AM
>  > To: 'Troy Robertson'; 'r-devel at R-project.org'
>  > Subject: Re: [Rd] Wierd nlm behaviour in 2.10.1 and 2.12.0
>  > [Sec=Unclassified]
>  >
>  > Hi Troy,
>  >
>  > I think that your problem is poorly scaled.  You have
>  > variables that vary over several orders of magnitude. This
>  > means that any small changes (due to subtle differences
>  > between R versions) could cause a big difference in the
>  > convergence behavior of the algorithms.  So, you are asking
>  > for trouble and you got it.  I would scale the problem such
>  > that the parameters, function and its gradient are
>  > essentially of the same magnitude.
>  >
>  > To paraphrase John Nash, who paraphrased Richard Varga, "It
>  > is all about scaling".
>  >
>  > Furthermore, I would specify the analytic gradient, which
>  > should be very easy to derive.
>  >
>  > Ravi.
>  >
>  >
>  > -----Original Message-----
>  > From: r-devel-bounces at r-project.org
>  > [
>  > On Behalf Of Troy Robertson
>  > Sent: Wednesday, October 13, 2010 1:51 AM
>  > To: 'r-devel at R-project.org'
>  > Subject: [Rd] Wierd nlm behaviour in 2.10.1 and 2.12.0
>  > [Sec=Unclassified]
>  >
>  > Hi all,
>  >
>  > When upgrading to 2.11.1 recently I noticed different results
>  > being produced by my code. After MUCH digging into my code I
>  > have finally narrowed it to a call to nlm(). The problem
>  > actually occurs in 2.10.1 and 2.12.0.
>  >
>  > This can be replicated by trying the code below in some
>  > different versions of R:
>  >
>  > FixedRemovals<-1836180125888
>  > AbStageInitial<-2223033830403
>  > Rates<- 0.3102445
>  > myfunc<-function(rootM,Abund,Loss,OtherM)
>  >      {(Loss-(rootM/(rootM+OtherM)*
>  >       (1-exp(-(rootM+OtherM)))*
>  >       Abund))^2}
>  >
>  > nlm(myfunc
>  >    ,0.001,print.level=0,fscale=0, gradtol=1E-10, stepmax = 100.0
>  >    ,Loss=FixedRemovals
>  >    ,Abund=AbStageInitial
>  >    ,OtherM=Rates)
>  >
>  > nlm(myfunc
>  >    ,0.001,print.level=0,fscale=0, gradtol=1E-10, stepmax = 100.0
>  >    ,Loss=FixedRemovals
>  >    ,Abund=AbStageInitial
>  >    ,OtherM=Rates)$estimate
>  >
>  > Why would I be seeing a different value of 'estimate' (or any
>  > of the other returned list items)? Originally I thought it
>  > was 2.11.1 that was giving me the grief with different output
>  > but now I see that in 2.11.1 I get the same value to each
>  > returned list item both ways. Can anyone explain this?
>  >
>  > Thanks
>  >
>  > Troy
>  > ______________________________________________________________
>  > _____________
>  >
>  >     Australian Antarctic Division - Commonwealth of Australia
>  > IMPORTANT: This transmission is intended for the addressee
>  > only. If you are not the intended recipient, you are notified
>  > that use or dissemination of this communication is strictly
>  > prohibited by Commonwealth law. If you have received this
>  > transmission in error, please notify the sender immediately
>  > by e-mail or by telephoning +61 3 6232 3209 and DELETE the message.
>  >         Visit our web site at 
>  > ______________________________________________________________
>  > _____________
>  >
>  > ______________________________________________
>  > R-devel at r-project.org mailing list
>  > 
>  >
>  > ______________________________________________
>  > R-devel at r-project.org mailing list
>  > 
>  >
>  >
>  ___________________________________________________________________________
>  
>      Australian Antarctic Division - Commonwealth of Australia
>  IMPORTANT: This transmission is intended for the addressee only. If 
> you are not the
>  intended recipient, you are notified that use or dissemination of 
> this communication is
>  strictly prohibited by Commonwealth law. If you have received this 
> transmission in error,
>  please notify the sender immediately by e-mail or by telephoning +61 
> 3 6232 3209 and
>  DELETE the message.
>          Visit our web site at 
>  ___________________________________________________________________________



More information about the R-devel mailing list