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]]
Hi, R is quite good at optimization. Here's a basic tutorial: https://www.is.uni-freiburg.de/resources/computational-economics/5_OptimizationR.pdf There are a LOT of possibilities: https://cran.r-project.org/web/views/Optimization.html Sarah On Tue, Nov 27, 2018 at 6:19 PM FAIL PEDIA <soloparapaginas123456789 at gmail.com> 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
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 < soloparapaginas123456789 at gmail.com> 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]] > > ______________________________________________ > R-help at r-project.org 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]]
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