Dear All, I couple of weeks ago, I’ve 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. I’ve 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, I’d 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? Many thanks in advance for your help. Lars. [[alternative HTML version deleted]]
On Tue, Mar 17, 2009 at 12:09 AM, Lars Bishop <lars52r at gmail.com> wrote:> I couple of weeks ago, I?ve 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. > > I?ve 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, I?d 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
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 <lars52r at 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 <phhs80 at gmail.com> wrote: >> >> On Tue, Mar 17, 2009 at 12:09 AM, Lars Bishop <lars52r at gmail.com> wrote: >> > I couple of weeks ago, I?ve 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. >> > >> > I?ve 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, I?d 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 at 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. > >
On Wed, Mar 18, 2009 at 7:43 PM, Berend Hasselman <bhh at xs4all.nl> wrote:>>> system.time(ans.nl <- nleqslv(x=p0, fn=broydt))[1] >> >> user.self >> ? ?8.17 > > On my Imac 2.16Ghz and R 2.8.1 and Mac OS X 10.5.6 > this took approximately 5 seconds. > > Interesting is this experiment. > I set the jacobian for a starting point with all x-values equal to -1 to a > diagonal matrix with 7 on the diagonal > (not a bad approximation). > > Solving the 1000 equation system now takes 1.4 seconds on my computer with > Broyden and double dogleg in 26 iterations > (only 1 jacobian is needed in the first iteration). > So the overhead of calculating ?the initial jacobian appears to be a > bottleneck.Thanks, Berend and Ravi. If you try with 10 000 variables, then nleqslv seems to be running endlessly whereas with dfsane it takes just 0.134 (same units as used by system.time). Paul