[R] 1 dimensional optimization with local minima

Ravi Varadhan rvaradhan at jhmi.edu
Tue Nov 3 15:41:41 CET 2009


Hi,

One approach is to use the `multiStart' function in my "BB" package.  You have to provide a matrix of starting values for this. 

Here is a simple, one-dimensional optimization problem with multiple peaks and valleys.  I show how to find "all" the peaks in the bounded interval [0, 1].

myfn <- function(x) {
exp(-k1 * x) * sin(2*pi*k2*x)
}

k1 <- 0.5

k2 <- 5

x <- seq(0, 1, length=1000)

plot(x, fn(x), type="l")

require(BB)

p0mat <- matrix(runif(100), 100, 1)  # random starting values

ans <- multiStart(par=p0mat, fn=myfn, lower=0, upper=1, action="optimize", control=list(maximize=TRUE))

pconv <- ans$par[ans$conv]  # converged solutions

rp <- !duplicated(round(pconv, 3))  # unique, converged solutions

sort(pconv[rp])  # lists all the local maxima


Hope this helps,
Ravi.

____________________________________________________________________

Ravi Varadhan, Ph.D.
Assistant Professor,
Division of Geriatric Medicine and Gerontology
School of Medicine
Johns Hopkins University

Ph. (410) 502-2619
email: rvaradhan at jhmi.edu


----- Original Message -----
From: Jeroen Ooms <jeroen.ooms at stat.ucla.edu>
Date: Tuesday, November 3, 2009 2:27 am
Subject: [R]  1 dimensional optimization with local minima
To: r-help at r-project.org


> I am using numerical optimization to fit a 1 parameter model, in which 
> the
> input parameter is bounded. I am currently using optimize(), however, 
> the
> problem turns out to have local minima, and optimize does not always 
> seem to
> find the global minimum. I could to write a wrapping function that tries
> multiple intervals or starting values, but I would prefer a package 
> that has
> built-in methods to make it more robust against local minima.
> 
> I checked the CRAN Task View for Optimization, however there seem to 
> be a
> lot of alternatives, and not being an optimization expert, I could use 
> some
> advice. What could be an appropriate package or function for one-dimensional
> bounded optimization, that includes some protection against local 
> minima? 
> 
> 
> 
> -----
> Jeroen Ooms * Dept. of Methodology and Statistics * Utrecht University 
> 
> 
> Visit   www.jeroenooms.com  to explore some of my
> current projects.
> 
> 
> 
> 
> 
>  
> -- 
> View this message in context: 
> Sent from the R help mailing list archive at Nabble.com.
> 
> ______________________________________________
> R-help at r-project.org mailing list
> 
> PLEASE do read the posting guide 
> and provide commented, minimal, self-contained, reproducible code.




More information about the R-help mailing list