Description Usage Arguments Value About the parameter phi References See Also Examples
View source: R/goldensection.R
goldensection
is a line search method that computes the optimum of a
univariate function over an interval [a,b]
where it is known to be
unimodal.
1 | goldensection(phi, a = 0, b = 1, eps.alpha = 1e-06)
|
phi |
A univariate function. |
a, b |
Numbers, initial interval where the function is unimodal. |
eps.alpha |
A number, a tolerance to stop the optimization when the current
interval becomes smaller |
Step length alpha
where phi attains its minimum in
[a,b]
(assuming unimodality).
phi
should be either an originally univariate function
phi(alpha)
, or the result of a multi-variate one over a fixed interval
phi(alpha) := f(x + alpha*searchD)
, which should come from the
univariate_f
function.
Rao, Singiresu S.; Engineering Optimization Theory and and Practice, 4th ed., page 267.
Ramirez, Jaime A.; Campelo, Felipe; Guimaraes, Frederico G.; Batista, Lucas S.; Takahashi, Ricardo H. C.; Notas de aula de Otimizacao, pages 10:13.
The documentation of the function univariate_f
in this package.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | # A univariate function
phi <- function(alpha)
{
return (alpha^5 - 5*alpha^3 - 20*alpha + 5)
}
# Plot the function for convenience over the interval [-5,5]
plot(phi, -5, 5)
# Compute the optimum in the interval [0,5] where it is unimodal
alpha.opt1 <- goldensection(phi, a = 0, b = 5) #approx 2
# If it is changed to [-5,0] where it is not unimodal, an extreme is returned
alpha.opt2 <- goldensection(phi, a = -5, b = 0) #return -5
# Considering a multi-variate function, assume given the current point x and
# the search direction searchD
f <- function (x)
{
i <- seq(1, length(x))
return (sum( (x - i)^2 ))
}
x <- c(0,0,0,0) #current point
searchD <- c(1,2,3,4) #search direction
univariate_f <- function(f, x, searchD) {
phi <- f(x)
function(alpha) {
phi <- f(x + alpha * searchD)
return(phi)
}
}
phi <- univariate_f(f, x, searchD) #return univariate version
# Compute optimum over the line x + alpha*searchD in [0,2]
alpha.opt <- goldensection(phi, a = 0, b = 2) #approx 1
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.