Lars, Here is how you can solve the example given by Paul using spg() in "BB" package.
f <- function(x, lambda) x[1] + x[2] - lambda * (x[1]^2 + x[2]^2 - 1)^2 # look at how Penalized function is formulated eps <- Inf tol <- 1.e-05 p0 <- c(1, 1) lambda <- 0.1 # start with a small value for lambda while (eps > tol) { ans <- spg(fn=f, par=p0, lambda=lambda, control=list(maximize=TRUE, trace=FALSE)) par <- ans$par eps <- max(abs(p0 - par)) p0 <- par lambda <- 10 * lambda # increase the penalty } ans Hope this helps, Ravi. ---------------------------------------------------------------------------- ------- Ravi Varadhan, Ph.D. Assistant Professor, The Center on Aging and Health Division of Geriatric Medicine and Gerontology Johns Hopkins University Ph: (410) 502-2619 Fax: (410) 614-9625 Email: rvarad...@jhmi.edu Webpage: http://www.jhsph.edu/agingandhealth/People/Faculty/Varadhan.html ---------------------------------------------------------------------------- -------- -----Original Message----- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Paul Smith Sent: Tuesday, March 17, 2009 2:34 PM To: r-help@r-project.org Subject: Re: [R] Non-Linear Optimization - Query Hi Lars, Consider the following problem: max x + y subject to x^2 + y^2 =1. The solution is obviously (x,y) = (sqrt(2) / 2, sqrt(2) / 2). Now, consider the unconstrained maximization problem on the variables x, y and lambda: max x + y + lambda * (x^2 + y^2 - 1) (Notice that the objective function here corresponds to the Lagrangian.) Clearly, this second problem has no maximum. These two simple examples should make evident that your strategy of maximizing the Lagrangian does not lead necessarily to a solution. What do you mean by "how do I construct my system of equations"? Do you mean how to derive analytically the equations? Or do you mean how to insert them into R? Best, Paul On Tue, Mar 17, 2009 at 11:33 AM, Lars Bishop <lars...@gmail.com> wrote: > Thanks Paul Sorry to ask this, but I'm new in R. Can't I just use the > Lagrangian as my objective function in BB? Otherwise, how do I > construct my system of equations? > > Thanks again > > Lars. > > On Mon, Mar 16, 2009 at 9:54 PM, Paul Smith <phh...@gmail.com> wrote: >> >> On Tue, Mar 17, 2009 at 12:09 AM, Lars Bishop <lars...@gmail.com> wrote: >> > I couple of weeks ago, Ive asked for a package recommendation for >> > nonlinear optimization. In my problem I have a fairly complicated >> > non-linear objective function subject to one non-linear equality >> > constrain. >> > >> > Ive been suggested to use the *Rdonlp2* package, but I did not get >> > any results after running the program for 5 hrs. Is it normal to >> > run this type of programs for hours? Also, Id like to ask the >> > experts whether there is any other alternative I could use to solve >> > this. For example, can I define a Lagrange function (add lambda as >> > a parameter) and use optim() or any other optimization function? >> >> Are your objective function and your constraint differentiable? If >> so, then construct the Lagrangean and get the system of equations for >> calculating the first order conditions. This nonlinear system of >> equations can be solved with the package BB (by Ravi Varadhan). >> >> Paul >> >> ______________________________________________ >> R-help@r-project.org mailing list >> 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. > > ______________________________________________ R-help@r-project.org mailing list 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. ______________________________________________ R-help@r-project.org mailing list 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.