# Basic optimization question (I'm a rookie)

7 messages
Open this post in threaded view
|

## Basic optimization question (I'm a rookie)

 Hello, and thanks to anyone who takes the time to read this I'm trying to learn to properly optimize a function with a constraint using R. For example, maximize the area of a terrain with a maximum perimeter. For this example the function would be:      Area <- function(x,y){x*y} The restriction would be the following function:      Perimeter <- function(x,y){2*(x+y)} The idea is to give a desired value to "Perimeter" and get the values of x & y that maximize the area and respect the constraint. I've searched online for some time, and only found a video of a dude that plotted the functions toggling the values to find the tangent optimum point (something useless, because the idea is to make the optimization more efficiently than using a paper and a pencil) Thanks again, and sorry if this question is silly.         [[alternative HTML version deleted]] ______________________________________________ [hidden email] mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Open this post in threaded view
|

## Re: Basic optimization question (I'm a rookie)

 Hi, R is quite good at optimization. Here's a basic tutorial: https://www.is.uni-freiburg.de/resources/computational-economics/5_OptimizationR.pdfThere are a LOT of possibilities: https://cran.r-project.org/web/views/Optimization.htmlSarah On Tue, Nov 27, 2018 at 6:19 PM FAIL PEDIA <[hidden email]> wrote: > > Hello, and thanks to anyone who takes the time to read this > > I'm trying to learn to properly optimize a function with a constraint using > R. For example, maximize the area of a terrain with a maximum perimeter. > For this example the function would be: > >      Area <- function(x,y){x*y} > > The restriction would be the following function: > >      Perimeter <- function(x,y){2*(x+y)} > > The idea is to give a desired value to "Perimeter" and get the values of x > & y that maximize the area and respect the constraint. > > I've searched online for some time, and only found a video of a dude that > plotted the functions toggling the values to find the tangent optimum point > (something useless, because the idea is to make the optimization more > efficiently than using a paper and a pencil) > > Thanks again, and sorry if this question is silly. > -- Sarah Goslee (she/her) http://www.sarahgoslee.com______________________________________________ [hidden email] mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Open this post in threaded view
|

## Re: Basic optimization question (I'm a rookie)

 In reply to this post by Ekapunk Of course, this particular example is trivially solvable by hand: x ==y ==p/4 , a square. Note also that optimization with equality constraints are generally solvable by the method of Lagrange multipliers for smooth functions and constraints, so that numerical methods may not be needed for relatively simple cases. Cheers, Bert On Tue, Nov 27, 2018 at 3:19 PM FAIL PEDIA < [hidden email]> wrote: > Hello, and thanks to anyone who takes the time to read this > > I'm trying to learn to properly optimize a function with a constraint using > R. For example, maximize the area of a terrain with a maximum perimeter. > For this example the function would be: > >      Area <- function(x,y){x*y} > > The restriction would be the following function: > >      Perimeter <- function(x,y){2*(x+y)} > > The idea is to give a desired value to "Perimeter" and get the values of x > & y that maximize the area and respect the constraint. > > I've searched online for some time, and only found a video of a dude that > plotted the functions toggling the values to find the tangent optimum point > (something useless, because the idea is to make the optimization more > efficiently than using a paper and a pencil) > > Thanks again, and sorry if this question is silly. > >         [[alternative HTML version deleted]] > > ______________________________________________ > [hidden email] mailing list -- To UNSUBSCRIBE and more, see > 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. >         [[alternative HTML version deleted]] ______________________________________________ [hidden email] mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Open this post in threaded view
|

## High dimensional optimization in R

 In reply to this post by Sarah Goslee Hi, Sarah Goslee (jn reply to  Basic optimization question (I'm a rookie)):  "R is quite good at optimization." I wonder what is the experience of the R user community with high dimensional problems, various objective functions and various numerical methods in R. In my experience with my package CatDyn (which depends on optimx), I have fitted nonlinear models with nearly 50 free parameters using normal, lognormal, gamma, Poisson and negative binomial exact loglikelihoods, and adjusted profile normal and adjusted profile lognormal approximate loglikelihoods. Most numerical methods crash, but CG and spg often, and BFGS, bobyqa, newuoa and Nelder-Mead sometimes, do yield good results (all numerical gradients less than 1)  after 1 day or more running in a normal 64 bit PC with Ubuntu 16.04 or Windows 7. Ruben -- Ruben H. Roa-Ureta, Ph. D. Consultant, ORCID ID 0000-0002-9620-5224 Marine Studies Section, Center for Environment and Water, Research Institute, King Fahd University of Petroleum and Minerals, KFUPM Box 1927, Dhahran 31261, Saudi Arabia Office Phone : 966-3-860-7850 Cellular Phone : 966-540026401 ______________________________________________ [hidden email] mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Open this post in threaded view
|

## Re: High dimensional optimization in R

 I fit also model with many variables (>100) and I get good result when I mix several method iteratively, for example: 500 iterations of Nelder-Mead followed by 500 iterations of BFGS followed by 500 iterations of Nelder-Mead followed by 500 iterations of BFGS etc. until it stabilized. It can take several days. I use or several rounds of optimx or simply succession of optim. Marc Le 28/11/2018 à 09:29, Ruben a écrit : > Hi, > > Sarah Goslee (jn reply to  Basic optimization question (I'm a > rookie)):  "R is quite good at optimization." > > I wonder what is the experience of the R user community with high > dimensional problems, various objective functions and various > numerical methods in R. > > In my experience with my package CatDyn (which depends on optimx), I > have fitted nonlinear models with nearly 50 free parameters using > normal, lognormal, gamma, Poisson and negative binomial exact > loglikelihoods, and adjusted profile normal and adjusted profile > lognormal approximate loglikelihoods. > > Most numerical methods crash, but CG and spg often, and BFGS, bobyqa, > newuoa and Nelder-Mead sometimes, do yield good results (all numerical > gradients less than 1)  after 1 day or more running in a normal 64 bit > PC with Ubuntu 16.04 or Windows 7. > > Ruben > ______________________________________________ [hidden email] mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.