#####################
# require(optimx)
# Simple bounds test for n=4
bt.f<-function(x){
sum(x*x)
}
bt.g<-function(x){
gg<-2.0*x
}
n<-4
lower<-rep(0,n)
upper<-lower # to get arrays set
bdmsk<-rep(1,n)
# bdmsk[(trunc(n/2)+1)]<-0
for (i in 1:n) {
lower[i]<-1.0*(i-1)*(n-1)/n
upper[i]<-1.0*i*(n+1)/n
}
xx<-0.5*(lower+upper)
cat("lower bounds:")
print(lower)
cat("start: ")
print(xx)
cat("upper bounds:")
print(upper)
abtrvm <- list() # ensure we have the structure
cat("Rvmmin \n\n")
# Note: trace set to 0 below. Change as needed to view progress.
# Following can be executed if package optimx available
# abtrvm <- optimr(xx, bt.f, bt.g, lower=lower, upper=upper, method="Rvmmin",
# control=list(trace=0))
# Note: use lower=lower etc. because there is a missing hess= argument
# print(abtrvm)
abtrvm$par <- c(0.00, 0.75, 1.50, 2.25)
abtrvm$value <- 7.875
cat("Axial search")
axabtrvm <- axsearch(abtrvm$par, fn=bt.f, fmin=abtrvm$value, lower, upper, bdmsk=NULL)
print(axabtrvm)
abtrvm1 <- optimr(xx, bt.f, bt.g, lower=lower, upper=upper, method="Rvmmin",
control=list(maxit=1, trace=0))
proptimr(abtrvm1)
abtrvm1$value <- 8.884958
abtrvm1$par <- c(0.625, 1.625, 2.625, 3.625)
cat("Axial search")
axabtrvm1 <- axsearch(abtrvm1$par, fn=bt.f, fmin=abtrvm1$value, lower, upper, bdmsk=NULL)
print(axabtrvm1)
cat("Do NOT try axsearch() with maximize\n")
Run the code above in your browser using DataLab