Re: [R] Looking for constrained optimisation code

From: Hong Ooi <Hong.Ooi_at_iag.com.au>
Date: Thu 01 Dec 2005 - 01:15:10 EST


Ah! I didn't notice this until now.

Yes, following Nocedal & Wright (excellent book, that) I've defined a quadratic penalty function to enforce an equality constraint, and added it to the objective. (Originally I had an inequality constraint in mind, but the equality one doesn't run into problems when you're on the boundary -- as is likely to happen in this case -- and gets the job done.) Getting the gradient right was a bit tedious, but it seems to be working now.

I did find an interesting thing in working with both Splus and R, though. In Splus, both optim and nlminb run fairly slowly with a pure-S objective function supplied, even when it was as vectorized as I could make it. So I thought to compile the objective function in C, and this sped it up by a factor of 2-4x. On the other hand, the pure-S version actually ran quite fast in R, and the compiled version actually _slowed_ it down by a small but noticeable amount.

Is this a common experience? Is the R interpreter so efficient that using compiled code is unlikely to improve speed further? (I'm using R 2.2 and Splus 7.04, on a Windows XP workstation with 3GB of memory.)

-- 
Hong Ooi
Senior Research Analyst, IAG Limited
388 George St, Sydney NSW 2000
+61 (2) 9292 1566
-----Original Message-----
From: Spencer Graves [mailto:spencer.graves@pdf.com] 
Sent: Tuesday, 29 November 2005 12:58 PM
To: Hong Ooi
Cc: Thomas Lumley; r-help@stat.math.ethz.ch
Subject: Re: [R] Looking for constrained optimisation code

	  Have you considered migrating the constraints into the
objective 
function, then cranking up the penalty for constraint violation once you

have a more or less feasible solution?

	  spencer graves

Hong Ooi wrote:


>
________________________________________________________________________ _______________
>
>
> You know, this is the first time I've heard of constrOptim.
>
> I actually have a rather complicated, nonlinear boundary expression in
> mind, so this function by itself isn't quite what I'm after. Still, I
> should be able to hack up a barrier function in my own code and feed
> that into optim/nlminb/constrOptim.
>
> Thanks!
>
>
-- Spencer Graves, PhD Senior Development Engineer PDF Solutions, Inc. 333 West San Carlos Street Suite 700 San Jose, CA 95110, USA spencer.graves@pdf.com www.pdf.com <http://www.pdf.com> Tel: 408-938-4420 Fax: 408-280-7915 _______________________________________________________________________________________ The information transmitted in this message and its attachme...{{dropped}} ______________________________________________ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Received on Thu Dec 01 02:26:03 2005

This archive was generated by hypermail 2.1.8 : Thu 01 Dec 2005 - 04:31:32 EST