# NOT RUN {
##### Rosenbrock function
# minimum at f(1,1) = 0
ro <- function(x){
100*(x[2]-x[1]^2)^2+(1-x[1])^2
}
# Random start values. Example arguments for the relatively simple Rosenbrock function.
ro_sa <- optim_sa(fun = ro,
start = c(runif(2, min = -1, max = 1)),
lower = c(-5, -5),
upper = c(5, 5),
trace = TRUE,
control = list(t0 = 100,
nlimit = 550,
t_min = 0.1,
dyn_rf = FALSE,
rf = 1,
r = 0.7
)
)
# Visual inspection.
plot(ro_sa)
plot(ro_sa, type = "contour")
##### Holder table function
# 4 minima at
#f(8.055, 9.665) = -19.2085
#f(-8.055, 9.665) = -19.2085
#f(8.055, -9.665) = -19.2085
#f(-8.055, -9.665) = -19.2085
ho <- function(x){
x1 <- x[1]
x2 <- x[2]
fact1 <- sin(x1) * cos(x2)
fact2 <- exp(abs(1 - sqrt(x1^2 + x2^2) / pi))
y <- -abs(fact1 * fact2)
}
# Random start values. Example arguments for the relatively complex Holder table function.
optim_sa(fun = ho,
start = c(1, 1),
lower = c(-10, -10),
upper = c(10, 10),
trace = TRUE,
control = list(dyn_rf = FALSE,
rf = 1.6,
t0 = 10,
nlimit = 200,
r = 0.6,
t_min = 0.1
)
)
# }
Run the code above in your browser using DataLab