-
Notifications
You must be signed in to change notification settings - Fork 50
Optimization Function Zoo
If you want to check whether your custom optimizers are working properly, you must use test functions to check for this. You will find below a large set of test functions to use.
Please use the following code to setup your function optimization zoo here.
# Load library
library(lattice) #for plot
library(R.utils) #for timing
# to avoid parsing warnings
Bound <- 0
f_name <- ""
f <<- function() {}
# Model zoo
f_zoo <- data.frame(matrix(ncol = 10, nrow = 47))
colnames(f_zoo) <- c("Name", "Description", "Lower_Bound", "Upper_Bound", "X1", "X2", "Minimum", "Parsable", "Dimensions", "Absolute")
f_zoo_select <- function(id) {
if (id == 1) {
# Model 1: Ackley Function
f_zoo[id, 1] <<- "Ackley Function"
f_zoo[id, 2] <<- "The Ackley function is widely used for testing optimization algorithms. In its two-dimensional form, as shown in the plot above, it is characterized by a nearly flat outer region, and a large hole at the centre. The function poses a risk for optimization algorithms, particularly hillclimbing algorithms, to be trapped in one of its many local minima."
f_zoo[id, 3] <<- -32768
f_zoo[id, 4] <<- 32768
f_zoo[id, 5] <<- 0
f_zoo[id, 6] <<- 0
f_zoo[id, 7] <<- 0
f_zoo[id, 8] <<- TRUE
f_zoo[id, 9] <<- 2
f_zoo[id, 10] <<- FALSE
f <<- function(xx, a=20, b=0.2, c=2*pi) {
d <- length(xx)
sum1 <- sum(xx^2)
sum2 <- sum(cos(c*xx))
term1 <- -a * exp(-b*sqrt(sum1/d))
term2 <- -exp(sum2/d)
y <- term1 + term2 + a + exp(1)
return(y)
}
} else if (id == 2) {
f_zoo[id, 1] <<- "Bukin Function number 6"
f_zoo[id, 2] <<- "The sixth Bukin function has many local minima, all of which lie in a ridge."
f_zoo[id, 3] <<- -15
f_zoo[id, 4] <<- 5
f_zoo[id, 5] <<- -10
f_zoo[id, 6] <<- 1
f_zoo[id, 7] <<- 0
f_zoo[id, 8] <<- TRUE
f_zoo[id, 9] <<- 2
f_zoo[id, 10] <<- FALSE
f <<- function(xx) {
x1 <- xx[1]
x2 <- xx[2]
term1 <- 100 * sqrt(abs(x2 - 0.01*x1^2))
term2 <- 0.01 * abs(x1+10)
y <- term1 + term2
return(y)
}
} else if (id == 3) {
#pivot signs to get the other global minimums (4 in total)
f_zoo[id, 1] <<- "Cross-In-Tray Function"
f_zoo[id, 2] <<- "The Cross-in-Tray function has multiple global minima."
f_zoo[id, 3] <<- -10
f_zoo[id, 4] <<- 19
f_zoo[id, 5] <<- 1.3491
f_zoo[id, 6] <<- -1.3491
f_zoo[id, 7] <<- -2.06261
f_zoo[id, 8] <<- TRUE
f_zoo[id, 9] <<- 2
f_zoo[id, 10] <<- TRUE
f <<- function(xx) {
x1 <- xx[1]
x2 <- xx[2]
fact1 <- sin(x1)*sin(x2)
fact2 <- exp(abs(100 - sqrt(x1^2+x2^2)/pi))
y <- -0.0001 * (abs(fact1*fact2)+1)^0.1
return(y)
}
} else if (id == 4) {
f_zoo[id, 1] <<- "Drop-Wave Function"
f_zoo[id, 2] <<- "The Drop-Wave function is multimodal and highly complex."
f_zoo[id, 3] <<- -5.12
f_zoo[id, 4] <<- 5.12
f_zoo[id, 5] <<- 0
f_zoo[id, 6] <<- 0
f_zoo[id, 7] <<- -1
f_zoo[id, 8] <<- TRUE
f_zoo[id, 9] <<- 2
f_zoo[id, 10] <<- FALSE
f <<- function(xx) {
x1 <- xx[1]
x2 <- xx[2]
frac1 <- 1 + cos(12*sqrt(x1^2+x2^2))
frac2 <- 0.5*(x1^2+x2^2) + 2
y <- -frac1/frac2
return(y)
}
} else if (id == 5) {
f_zoo[id, 1] <<- "Eggholder Function"
f_zoo[id, 2] <<- "The Eggholder function is a difficult function to optimize, because of the large number of local minima. "
f_zoo[id, 3] <<- -512
f_zoo[id, 4] <<- 512
f_zoo[id, 5] <<- 512
f_zoo[id, 6] <<- 404.2319
f_zoo[id, 7] <<- -959.6407
f_zoo[id, 8] <<- TRUE
f_zoo[id, 9] <<- 2
f_zoo[id, 10] <<- FALSE
f <<- function(xx) {
x1 <- xx[1]
x2 <- xx[2]
term1 <- -(x2+47) * sin(sqrt(abs(x2+x1/2+47)))
term2 <- -x1 * sin(sqrt(abs(x1-(x2+47))))
y <- term1 + term2
return(y)
}
} else if (id == 6) {
f_zoo[id, 1] <<- "Gramacy & Lee Function"
f_zoo[id, 2] <<- "This is a simple one-dimensional test function."
f_zoo[id, 3] <<- 0.5
f_zoo[id, 4] <<- 2.5
f_zoo[id, 5] <<- 0.548563
f_zoo[id, 6] <<- 0
f_zoo[id, 7] <<- -0.869011
f_zoo[id, 8] <<- TRUE
f_zoo[id, 9] <<- 1
f_zoo[id, 10] <<- FALSE
f <<- function(x) {
term1 <- sin(10*pi*x) / (2*x)
term2 <- (x-1)^4
y <- term1 + term2
return(y)
}
} else if (id == 7) {
f_zoo[id, 1] <<- "Griewank Function"
f_zoo[id, 2] <<- "The Griewank function has many widespread local minima, which are regularly distributed."
f_zoo[id, 3] <<- -600
f_zoo[id, 4] <<- 600
f_zoo[id, 5] <<- 0
f_zoo[id, 6] <<- 0
f_zoo[id, 7] <<- 0
f_zoo[id, 8] <<- TRUE
f_zoo[id, 9] <<- 2
f_zoo[id, 10] <<- FALSE
f <<- function(xx) {
ii <- c(1:length(xx))
sum <- sum(xx^2/4000)
prod <- prod(cos(xx/sqrt(ii)))
y <- sum - prod + 1
return(y)
}
} else if (id == 8) {
#pivot signs to get the other global minimums (4 in total)
f_zoo[id, 1] <<- "Holder Table Function"
f_zoo[id, 2] <<- "The Holder Table function has many local minima, with four global minima."
f_zoo[id, 3] <<- -10
f_zoo[id, 4] <<- 10
f_zoo[id, 5] <<- -8.05502
f_zoo[id, 6] <<- -9.66459
f_zoo[id, 7] <<- -19.2085
f_zoo[id, 8] <<- TRUE
f_zoo[id, 9] <<- 2
f_zoo[id, 10] <<- TRUE
f <<- function(xx) {
x1 <- xx[1]
x2 <- xx[2]
fact1 <- sin(x1)*cos(x2)
fact2 <- exp(abs(1 - sqrt(x1^2+x2^2)/pi))
y <- -abs(fact1*fact2)
return(y)
}
} else if (id == 9) {
f_zoo[id, 1] <<- "Langermann Function"
f_zoo[id, 2] <<- "The Langermann function is multimodal, with many unevenly distributed local minima."
f_zoo[id, 3] <<- 0
f_zoo[id, 4] <<- 10
f_zoo[id, 5] <<- NA
f_zoo[id, 6] <<- NA
f_zoo[id, 7] <<- -1.5
f_zoo[id, 8] <<- TRUE
f_zoo[id, 9] <<- 2
f_zoo[id, 10] <<- FALSE
f <<- function(xx, m=5, cvec=c(1,2,5,2,3), A=matrix(c(3,5,5,2,2,1,1,4,7,9),5,2,byrow=TRUE)) {
d <- length(xx)
xxmat <- matrix(rep(xx,times=m), m, d, byrow=TRUE)
inner <- rowSums((xxmat-A[,1:d])^2)
outer <- sum(cvec * exp(-inner/pi) * cos(pi*inner))
y <- outer
return(y)
}
} else if (id == 10) {
f_zoo[id, 1] <<- "Levy Function"
f_zoo[id, 2] <<- "The first Levy function."
f_zoo[id, 3] <<- -10
f_zoo[id, 4] <<- 10
f_zoo[id, 5] <<- 1
f_zoo[id, 6] <<- 1
f_zoo[id, 7] <<- 0
f_zoo[id, 8] <<- TRUE
f_zoo[id, 9] <<- 2
f_zoo[id, 10] <<- FALSE
f <<- function(xx) {
d <- length(xx)
w <- 1 + (xx - 1)/4
term1 <- (sin(pi*w[1]))^2
term3 <- (w[d]-1)^2 * (1+1*(sin(2*pi*w[d]))^2)
wi <- w[1:(d-1)]
sum <- sum((wi-1)^2 * (1+10*(sin(pi*wi+1))^2))
y <- term1 + sum + term3
return(y)
}
} else if (id == 11) {
f_zoo[id, 1] <<- "Levy Function number 13"
f_zoo[id, 2] <<- "The thirteen Levy Function."
f_zoo[id, 3] <<- -10
f_zoo[id, 4] <<- 10
f_zoo[id, 5] <<- 1
f_zoo[id, 6] <<- 1
f_zoo[id, 7] <<- 0
f_zoo[id, 8] <<- TRUE
f_zoo[id, 9] <<- 2
f_zoo[id, 10] <<- FALSE
f <<- function(xx) {
x1 <- xx[1]
x2 <- xx[2]
term1 <- (sin(3*pi*x1))^2
term2 <- (x1-1)^2 * (1+(sin(3*pi*x2))^2)
term3 <- (x2-1)^2 * (1+(sin(2*pi*x2))^2)
y <- term1 + term2 + term3
return(y)
}
} else if (id == 12) {
f_zoo[id, 1] <<- "Rastrigin Function"
f_zoo[id, 2] <<- "The Rastrigin function has several local minima. It is highly multimodal, but locations of the minima are regularly distributed."
f_zoo[id, 3] <<- -5.12
f_zoo[id, 4] <<- 5.12
f_zoo[id, 5] <<- 0
f_zoo[id, 6] <<- 0
f_zoo[id, 7] <<- 0
f_zoo[id, 8] <<- TRUE
f_zoo[id, 9] <<- 2
f_zoo[id, 10] <<- FALSE
f <<- function(xx) {
d <- length(xx)
sum <- sum(xx^2 - 10*cos(2*pi*xx))
y <- 10*d + sum
return(y)
}
} else if (id == 13) {
f_zoo[id, 1] <<- "Schaffer Function number 2"
f_zoo[id, 2] <<- "The second Schaffer function."
f_zoo[id, 3] <<- -100
f_zoo[id, 4] <<- 100
f_zoo[id, 5] <<- 0
f_zoo[id, 6] <<- 0
f_zoo[id, 7] <<- 0
f_zoo[id, 8] <<- TRUE
f_zoo[id, 9] <<- 2
f_zoo[id, 10] <<- FALSE
f <<- function(xx) {
x1 <- xx[1]
x2 <- xx[2]
fact1 <- (sin(x1^2-x2^2))^2 - 0.5
fact2 <- (1 + 0.001*(x1^2+x2^2))^2
y <- 0.5 + fact1/fact2
return(y)
}
} else if (id == 14) {
f_zoo[id, 1] <<- "Schaffer Function number 4"
f_zoo[id, 2] <<- "The fourth Schaffer function."
f_zoo[id, 3] <<- -100
f_zoo[id, 4] <<- 100
f_zoo[id, 5] <<- 0
f_zoo[id, 6] <<- 1.25313
f_zoo[id, 7] <<- 0.292579
f_zoo[id, 8] <<- TRUE
f_zoo[id, 9] <<- 2
f_zoo[id, 10] <<- FALSE
f <<- function(xx) {
x1 <- xx[1]
x2 <- xx[2]
fact1 <- cos(sin(abs(x1^2-x2^2))) - 0.5
fact2 <- (1 + 0.001*(x1^2+x2^2))^2
y <- 0.5 + fact1/fact2
return(y)
}
} else if (id == 15) {
f_zoo[id, 1] <<- "Schwefel Function"
f_zoo[id, 2] <<- "The Schwefel function is complex, with many local minima."
f_zoo[id, 3] <<- -500
f_zoo[id, 4] <<- 500
f_zoo[id, 5] <<- 420.9687
f_zoo[id, 6] <<- 420.9687
f_zoo[id, 7] <<- 0
f_zoo[id, 8] <<- TRUE
f_zoo[id, 9] <<- 2
f_zoo[id, 10] <<- FALSE
f <<- function(xx) {
d <- length(xx)
sum <- sum(xx*sin(sqrt(abs(xx))))
y <- 418.9829*d - sum
return(y)
}
} else if (id == 16) {
f_zoo[id, 1] <<- "Schubert Function"
f_zoo[id, 2] <<- "The Shubert function has several local minima and many global minima."
f_zoo[id, 3] <<- -10
f_zoo[id, 4] <<- 10
f_zoo[id, 5] <<- 0
f_zoo[id, 6] <<- 0
f_zoo[id, 7] <<- -186.7309
f_zoo[id, 8] <<- TRUE
f_zoo[id, 9] <<- 2
f_zoo[id, 10] <<- FALSE
f <<- function(xx) {
x1 <- xx[1]
x2 <- xx[2]
ii <- c(1:5)
sum1 <- sum(ii * cos((ii+1)*x1+ii))
sum2 <- sum(ii * cos((ii+1)*x2+ii))
y <- sum1 * sum2
return(y)
}
} else if (id == 17) {
f_zoo[id, 1] <<- "Bohachevsky Function number 1"
f_zoo[id, 2] <<- "The Bohachevsky functions all have the same similar bowl shape."
f_zoo[id, 3] <<- -100
f_zoo[id, 4] <<- 100
f_zoo[id, 5] <<- 0
f_zoo[id, 6] <<- 0
f_zoo[id, 7] <<- 0
f_zoo[id, 8] <<- TRUE
f_zoo[id, 9] <<- 2
f_zoo[id, 10] <<- FALSE
f <<- function(xx) {
x1 <- xx[1]
x2 <- xx[2]
term1 <- x1^2
term2 <- 2*x2^2
term3 <- -0.3 * cos(3*pi*x1)
term4 <- -0.4 * cos(4*pi*x2)
y <- term1 + term2 + term3 + term4 + 0.7
return(y)
}
} else if (id == 18) {
f_zoo[id, 1] <<- "Perm Function 0, d=2, beta=10"
f_zoo[id, 2] <<- "The Perm function."
f_zoo[id, 3] <<- -2
f_zoo[id, 4] <<- 2
f_zoo[id, 5] <<- 1
f_zoo[id, 6] <<- 0.5
f_zoo[id, 7] <<- 0
f_zoo[id, 8] <<- TRUE
f_zoo[id, 9] <<- 2
f_zoo[id, 10] <<- FALSE
f <<- function(xx, b=10) {
d <- length(xx)
ii <- c(1:d)
jj <- matrix(rep(ii,times=d), d, d, byrow=TRUE)
xxmat <- matrix(rep(xx,times=d), d, d, byrow=TRUE)
inner <- rowSums((jj+b)*(xxmat^ii-(1/jj)^ii))
outer <- sum(inner^2)
y <- outer
return(y)
}
} else if (id == 19) {
f_zoo[id, 1] <<- "Rotated HYper-Ellipsoid Function"
f_zoo[id, 2] <<- "The Rotated Hyper-Ellipsoid function is continuous, convex and unimodal. It is an extension of the Axis Parallel Hyper-Ellipsoid function, also referred to as the Sum Squares function."
f_zoo[id, 3] <<- -65.536
f_zoo[id, 4] <<- 65.536
f_zoo[id, 5] <<- 0
f_zoo[id, 6] <<- 0
f_zoo[id, 7] <<- 0
f_zoo[id, 8] <<- TRUE
f_zoo[id, 9] <<- 2
f_zoo[id, 10] <<- FALSE
f <<- function(xx) {
d <- length(xx)
xxmat <- matrix(rep(xx,times=d), d, d, byrow=TRUE)
xxmatlow <- xxmat
xxmatlow[upper.tri(xxmatlow)] <- 0
inner <- rowSums(xxmatlow^2)
outer <- sum(inner)
y <- outer
return(y)
}
} else if (id == 20) {
f_zoo[id, 1] <<- "Sphere Function"
f_zoo[id, 2] <<- "The Sphere function has d local minima except for the global one. It is continuous, convex and unimodal. "
f_zoo[id, 3] <<- -5.12
f_zoo[id, 4] <<- 5.12
f_zoo[id, 5] <<- 0
f_zoo[id, 6] <<- 0
f_zoo[id, 7] <<- 0
f_zoo[id, 8] <<- TRUE
f_zoo[id, 9] <<- 2
f_zoo[id, 10] <<- FALSE
f <<- function(xx) {
sum <- sum(xx^2)
y <- sum
return(y)
}
} else if (id == 21) {
f_zoo[id, 1] <<- "Sum of Different Powers Function"
f_zoo[id, 2] <<- "The Sum of Different Powers function is unimodal."
f_zoo[id, 3] <<- -1
f_zoo[id, 4] <<- 1
f_zoo[id, 5] <<- 0
f_zoo[id, 6] <<- 0
f_zoo[id, 7] <<- 0
f_zoo[id, 8] <<- TRUE
f_zoo[id, 9] <<- 2
f_zoo[id, 10] <<- FALSE
f <<- function(xx) {
ii <- c(1:length(xx))
sum <- sum((abs(xx))^(ii+1))
y <- sum
return(y)
}
} else if (id == 22) {
f_zoo[id, 1] <<- "Sum Squares Function"
f_zoo[id, 2] <<- "The Sum Squares function, also referred to as the Axis Parallel Hyper-Ellipsoid function, has no local minimum except the global one. It is continuous, convex and unimodal."
f_zoo[id, 3] <<- -10
f_zoo[id, 4] <<- 10
f_zoo[id, 5] <<- 0
f_zoo[id, 6] <<- 0
f_zoo[id, 7] <<- 0
f_zoo[id, 8] <<- TRUE
f_zoo[id, 9] <<- 2
f_zoo[id, 10] <<- FALSE
f <<- function(xx) {
ii <- c(1:length(xx))
sum <- sum(ii*xx^2)
y <- sum
return(y)
}
} else if (id == 23) {
#known solution: 6, 10, 12, 12, 10, 6
f_zoo[id, 1] <<- "Trid Function"
f_zoo[id, 2] <<- "The Trid function has no local minimum except the global one."
f_zoo[id, 3] <<- -36
f_zoo[id, 4] <<- 36
f_zoo[id, 5] <<- NA
f_zoo[id, 6] <<- NA
f_zoo[id, 7] <<- -200
f_zoo[id, 8] <<- TRUE
f_zoo[id, 9] <<- 6
f_zoo[id, 10] <<- FALSE
f <<- function(xx) {
d <- length(xx)
xi <- xx[2:d]
xold <- xx[1:(d-1)]
sum1 = (xx[1]-1)^2 + sum((xi-1)^2)
sum2 <- sum(xi*xold)
y <- sum1 - sum2
return(y)
}
} else if (id == 24) {
f_zoo[id, 1] <<- "Booth Function"
f_zoo[id, 2] <<- "The Booth Function."
f_zoo[id, 3] <<- -10
f_zoo[id, 4] <<- 10
f_zoo[id, 5] <<- 1
f_zoo[id, 6] <<- 3
f_zoo[id, 7] <<- 0
f_zoo[id, 8] <<- TRUE
f_zoo[id, 9] <<- 2
f_zoo[id, 10] <<- FALSE
f <<- function(xx) {
x1 <- xx[1]
x2 <- xx[2]
term1 <- (x1 + 2*x2 - 7)^2
term2 <- (2*x1 + x2 - 5)^2
y <- term1 + term2
return(y)
}
} else if (id == 25) {
f_zoo[id, 1] <<- "Matyas Function"
f_zoo[id, 2] <<- "The Matyas function has no local minima except the global one. "
f_zoo[id, 3] <<- -10
f_zoo[id, 4] <<- 10
f_zoo[id, 5] <<- 0
f_zoo[id, 6] <<- 0
f_zoo[id, 7] <<- 0
f_zoo[id, 8] <<- TRUE
f_zoo[id, 9] <<- 2
f_zoo[id, 10] <<- FALSE
f <<- function(xx) {
x1 <- xx[1]
x2 <- xx[2]
term1 <- 0.26 * (x1^2 + x2^2)
term2 <- -0.48*x1*x2
y <- term1 + term2
return(y)
}
} else if (id == 26) {
f_zoo[id, 1] <<- "McCormick Function"
f_zoo[id, 2] <<- "The McCormick Function"
f_zoo[id, 3] <<- -1.5
f_zoo[id, 4] <<- 4
f_zoo[id, 5] <<- -0.54719
f_zoo[id, 6] <<- -1.54719
f_zoo[id, 7] <<- -1.9133
f_zoo[id, 8] <<- TRUE
f_zoo[id, 9] <<- 2
f_zoo[id, 10] <<- FALSE
f <<- function(xx) {
x1 <- xx[1]
x2 <- xx[2]
term1 <- sin(x1 + x2)
term2 <-(x1 - x2)^2
term3 <- -1.5*x1
term4 <- 2.5*x2
y <- term1 + term2 + term3 + term4 + 1
return(y)
}
} else if (id == 27) {
#known solution: 1, 2, 3, 4
f_zoo[id, 1] <<- "Power Sum Function"
f_zoo[id, 2] <<- "The Power Sum function."
f_zoo[id, 3] <<- 0
f_zoo[id, 4] <<- 4
f_zoo[id, 5] <<- NA
f_zoo[id, 6] <<- NA
f_zoo[id, 7] <<- 0
f_zoo[id, 8] <<- TRUE
f_zoo[id, 9] <<- 4
f_zoo[id, 10] <<- FALSE
f <<- function(xx, b=c(8, 18, 44, 114)) {
d <- length(xx)
ii <- c(1:d)
xxmat <- matrix(rep(xx,times=d), d, d, byrow=TRUE)
inner <- rowSums(xxmat^ii)
outer <- sum((inner-b)^2)
y <- outer
return(y)
}
} else if (id == 28) {
f_zoo[id, 1] <<- "Zakharov Function"
f_zoo[id, 2] <<- "The Zakharov function has no local minima except the global one."
f_zoo[id, 3] <<- -5
f_zoo[id, 4] <<- 10
f_zoo[id, 5] <<- 0
f_zoo[id, 6] <<- 0
f_zoo[id, 7] <<- 0
f_zoo[id, 8] <<- TRUE
f_zoo[id, 9] <<- 2
f_zoo[id, 10] <<- FALSE
f <<- function(xx) {
ii <- c(1:length(xx))
sum1 <- sum(xx^2)
sum2 <- sum(0.5*ii*xx)
y <- sum1 + sum2^2 + sum2^4
return(y)
}
} else if (id == 29) {
f_zoo[id, 1] <<- "Three-Hump Camel Function"
f_zoo[id, 2] <<- "The function has three local minima. "
f_zoo[id, 3] <<- -5
f_zoo[id, 4] <<- 5
f_zoo[id, 5] <<- 0
f_zoo[id, 6] <<- 0
f_zoo[id, 7] <<- 0
f_zoo[id, 8] <<- TRUE
f_zoo[id, 9] <<- 2
f_zoo[id, 10] <<- FALSE
f <<- function(xx) {
x1 <- xx[1]
x2 <- xx[2]
term1 <- 2*x1^2
term2 <- -1.05*x1^4
term3 <- x1^6 / 6
term4 <- x1*x2
term5 <- x2^2
y <- term1 + term2 + term3 + term4 + term5
return(y)
}
} else if (id == 30) {
#only alternative signs!
f_zoo[id, 1] <<- "Sixth-Hump Camel Function"
f_zoo[id, 2] <<- "The function has six local minima, two of which are global. "
f_zoo[id, 3] <<- -3
f_zoo[id, 4] <<- 3
f_zoo[id, 5] <<- 0.0898
f_zoo[id, 6] <<- -0.7126
f_zoo[id, 7] <<- -1.0316
f_zoo[id, 8] <<- TRUE
f_zoo[id, 9] <<- 2
f_zoo[id, 10] <<- FALSE
f <<- function(xx) {
x1 <- xx[1]
x2 <- xx[2]
term1 <- (4-2.1*x1^2+(x1^4)/3) * x1^2
term2 <- x1*x2
term3 <- (-4+4*x2^2) * x2^2
y <- term1 + term2 + term3
return(y)
}
} else if (id == 31) {
f_zoo[id, 1] <<- "Dixon-Price Function"
f_zoo[id, 2] <<- "The Dixon-Price function."
f_zoo[id, 3] <<- -10
f_zoo[id, 4] <<- 10
f_zoo[id, 5] <<- 1
f_zoo[id, 6] <<- sqrt(2)
f_zoo[id, 7] <<- 0
f_zoo[id, 8] <<- TRUE
f_zoo[id, 9] <<- 2
f_zoo[id, 10] <<- FALSE
f <<- function(xx) {
x1 <- xx[1]
d <- length(xx)
term1 <- (x1-1)^2
ii <- c(2:d)
xi <- xx[2:d]
xold <- xx[1:(d-1)]
sum <- sum(ii * (2*xi^2 - xold)^2)
y <- term1 + sum
return(y)
}
} else if (id == 32) {
f_zoo[id, 1] <<- "Rosenbrock Function"
f_zoo[id, 2] <<- "The Rosenbrock function, also referred to as the Valley or Banana function, is a popular test problem for gradient-based optimization algorithms. The function is unimodal, and the global minimum lies in a narrow, parabolic valley. However, even though this valley is easy to find, convergence to the minimum is difficult."
f_zoo[id, 3] <<- -5
f_zoo[id, 4] <<- 10
f_zoo[id, 5] <<- 1
f_zoo[id, 6] <<- 1
f_zoo[id, 7] <<- 0
f_zoo[id, 8] <<- TRUE
f_zoo[id, 9] <<- 2
f_zoo[id, 10] <<- FALSE
f <<- function(xx) {
d <- length(xx)
xi <- xx[1:(d-1)]
xnext <- xx[2:d]
sum <- sum(100*(xnext-xi^2)^2 + (xi-1)^2)
y <- sum
return(y)
}
} else if (id == 33) {
f_zoo[id, 1] <<- "De Jong Function number 5"
f_zoo[id, 2] <<- "The fifth function of De Jong is multimodal, with very sharp drops on a mainly flat surface."
f_zoo[id, 3] <<- -65536
f_zoo[id, 4] <<- 65536
f_zoo[id, 5] <<- -32
f_zoo[id, 6] <<- -32
f_zoo[id, 7] <<- 0.998
f_zoo[id, 8] <<- TRUE
f_zoo[id, 9] <<- 2
f_zoo[id, 10] <<- FALSE
f <<- function(xx) {
x1 <- xx[1]
x2 <- xx[2]
A = matrix(0, 2, 25)
a <- c(-32, -16, 0, 16, 32)
A[1,] <- rep(a, times=5)
A[2,] <- rep(a, each=5)
sumterm1 <- c(1:25)
sumterm2 <- (x1 - A[1,1:25])^6
sumterm3 <- (x2 - A[2,1:25])^6
sum <- sum(1 / (sumterm1+sumterm2+sumterm3))
y <- 1 / (0.002 + sum)
return(y)
}
} else if (id == 34) {
f_zoo[id, 1] <<- "Easom Function"
f_zoo[id, 2] <<- "The Easom function has several local minima. It is unimodal, and the global minimum has a small area relative to the search space. "
f_zoo[id, 3] <<- -100
f_zoo[id, 4] <<- 100
f_zoo[id, 5] <<- pi
f_zoo[id, 6] <<- pi
f_zoo[id, 7] <<- -1
f_zoo[id, 8] <<- TRUE
f_zoo[id, 9] <<- 2
f_zoo[id, 10] <<- FALSE
f <<- function(xx) {
x1 <- xx[1]
x2 <- xx[2]
fact1 <- -cos(x1)*cos(x2)
fact2 <- exp(-(x1-pi)^2-(x2-pi)^2)
y <- fact1*fact2
return(y)
}
} else if (id == 35) {
f_zoo[id, 1] <<- "Michalewicz Function"
f_zoo[id, 2] <<- "The Michalewicz function has d! local minima, and it is multimodal. The parameter m defines the steepness of they valleys and ridges; a larger m leads to a more difficult search. The recommended value of m is m = 10."
f_zoo[id, 3] <<- 0
f_zoo[id, 4] <<- pi
f_zoo[id, 5] <<- 2.20
f_zoo[id, 6] <<- 1.57
f_zoo[id, 7] <<- -1.8013
f_zoo[id, 8] <<- TRUE
f_zoo[id, 9] <<- 2
f_zoo[id, 10] <<- FALSE
f <<- function(xx, m=10) {
ii <- c(1:length(xx))
sum <- sum(sin(xx) * (sin(ii*xx^2/pi))^(2*m))
y <- -sum
return(y)
}
} else if (id == 36) {
f_zoo[id, 1] <<- "Beale Function"
f_zoo[id, 2] <<- "The Beale function is multimodal, with sharp peaks at the corners of the input domain. "
f_zoo[id, 3] <<- -4.5
f_zoo[id, 4] <<- 4.5
f_zoo[id, 5] <<- 3
f_zoo[id, 6] <<- 0.5
f_zoo[id, 7] <<- 0
f_zoo[id, 8] <<- TRUE
f_zoo[id, 9] <<- 2
f_zoo[id, 10] <<- FALSE
f <<- function(xx) {
x1 <- xx[1]
x2 <- xx[2]
term1 <- (1.5 - x1 + x1*x2)^2
term2 <- (2.25 - x1 + x1*x2^2)^2
term3 <- (2.625 - x1 + x1*x2^3)^2
y <- term1 + term2 + term3
return(y)
}
} else if (id == 37) {
#solutions: (-pi, 12.275), (pi, 2.275), (9.42478, 2.475)
f_zoo[id, 1] <<- "Branin Function"
f_zoo[id, 2] <<- "The Branin, or Branin-Hoo, function has three global minima."
f_zoo[id, 3] <<- -5
f_zoo[id, 4] <<- 15
f_zoo[id, 5] <<- NA
f_zoo[id, 6] <<- NA
f_zoo[id, 7] <<- 0.397887
f_zoo[id, 8] <<- TRUE
f_zoo[id, 9] <<- 2
f_zoo[id, 10] <<- FALSE
f <<- function(xx, a=1, b=5.1/(4*pi^2), c=5/pi, r=6, s=10, t=1/(8*pi)) {
x1 <- xx[1]
x2 <- xx[2]
term1 <- a * (x2 - b*x1^2 + c*x1 - r)^2
term2 <- s*(1-t)*cos(x1)
y <- term1 + term2 + s
return(y)
}
} else if (id == 38) {
#solution: 1,1,1,1
f_zoo[id, 1] <<- "Colville Function"
f_zoo[id, 2] <<- "The Colville function."
f_zoo[id, 3] <<- -10
f_zoo[id, 4] <<- 10
f_zoo[id, 5] <<- NA
f_zoo[id, 6] <<- NA
f_zoo[id, 7] <<- 0
f_zoo[id, 8] <<- TRUE
f_zoo[id, 9] <<- 4
f_zoo[id, 10] <<- FALSE
f <<- function(xx) {
x1 <- xx[1]
x2 <- xx[2]
x3 <- xx[3]
x4 <- xx[4]
term1 <- 100 * (x1^2-x2)^2
term2 <- (x1-1)^2
term3 <- (x3-1)^2
term4 <- 90 * (x3^2-x4)^2
term5 <- 10.1 * ((x2-1)^2 + (x4-1)^2)
term6 <- 19.8*(x2-1)*(x4-1)
y <- term1 + term2 + term3 + term4 + term5 + term6
return(y)
}
} else if (id == 39) {
f_zoo[id, 1] <<- "Forrester et al. Function"
f_zoo[id, 2] <<- "This function is a simple one-dimensional test function. It is multimodal, with one global minimum, one local minimum and a zero-gradient inflection point. "
f_zoo[id, 3] <<- 0
f_zoo[id, 4] <<- 1
f_zoo[id, 5] <<- 0.7572
f_zoo[id, 6] <<- 0
f_zoo[id, 7] <<- -6.02074
f_zoo[id, 8] <<- TRUE
f_zoo[id, 9] <<- 1
f_zoo[id, 10] <<- FALSE
f <<- function(x, A=0.5, B=10, C=-5) {
fact1 <- (6*x - 2)^2
fact2 <- sin(12*x - 4)
yh <- fact1 * fact2
term1 <- A * yh
term2 <- B * (x-0.5)
y <- term1 + term2 - C
return(y)
}
} else if (id == 40) {
f_zoo[id, 1] <<- "Goldstein-Price Function"
f_zoo[id, 2] <<- "The Goldstein-Price function has several local minima."
f_zoo[id, 3] <<- -2
f_zoo[id, 4] <<- 2
f_zoo[id, 5] <<- 0
f_zoo[id, 6] <<- -1
f_zoo[id, 7] <<- 3
f_zoo[id, 8] <<- TRUE
f_zoo[id, 9] <<- 2
f_zoo[id, 10] <<- FALSE
f <<- function(xx) {
x1 <- xx[1]
x2 <- xx[2]
fact1a <- (x1 + x2 + 1)^2
fact1b <- 19 - 14*x1 + 3*x1^2 - 14*x2 + 6*x1*x2 + 3*x2^2
fact1 <- 1 + fact1a*fact1b
fact2a <- (2*x1 - 3*x2)^2
fact2b <- 18 - 32*x1 + 12*x1^2 + 48*x2 - 36*x1*x2 + 27*x2^2
fact2 <- 30 + fact2a*fact2b
y <- fact1*fact2
return(y)
}
} else if (id == 41) {
#solution: (0.114614, 0.555649, 0.852547)
f_zoo[id, 1] <<- "Hartmann 3-Dimensional Function"
f_zoo[id, 2] <<- "The 3-dimensional Hartmann function has 4 local minima."
f_zoo[id, 3] <<- 0
f_zoo[id, 4] <<- 1
f_zoo[id, 5] <<- NA
f_zoo[id, 6] <<- NA
f_zoo[id, 7] <<- -3.86278
f_zoo[id, 8] <<- TRUE
f_zoo[id, 9] <<- 3
f_zoo[id, 10] <<- FALSE
f <<- function(xx) {
alpha <- c(1.0, 1.2, 3.0, 3.2)
A <- c(3.0, 10, 30, 0.1, 10, 35, 3.0, 10, 30, 0.1, 10, 35)
A <- matrix(A, 4, 3, byrow=TRUE)
P <- 10^(-4) * c(3689, 1170, 2673, 4699, 4387, 7470, 1091, 8732, 5547, 381, 5743, 8828)
P <- matrix(P, 4, 3, byrow=TRUE)
xxmat <- matrix(rep(xx,times=4), 4, 3, byrow=TRUE)
inner <- rowSums(A[,1:3]*(xxmat-P[,1:3])^2)
outer <- sum(alpha * exp(-inner))
y <- -outer
return(y)
}
} else if (id == 42) {
#solution: (0.1873, 0.1906, 0.5566, 0.2647)
f_zoo[id, 1] <<- "Hartmann 4-Dimensional Function"
f_zoo[id, 2] <<- "The 4-dimensional Hartmann function is multimodal. It is given here in the form of Picheny et al. (2012), having a mean of zero and a variance of one. The authors also add a small Gaussian error term to the output."
f_zoo[id, 3] <<- 0
f_zoo[id, 4] <<- 1
f_zoo[id, 5] <<- NA
f_zoo[id, 6] <<- NA
f_zoo[id, 7] <<- -3.135474
f_zoo[id, 8] <<- TRUE
f_zoo[id, 9] <<- 4
f_zoo[id, 10] <<- FALSE
f <<- function(xx) {
alpha <- c(1.0, 1.2, 3.0, 3.2)
A <- c(10, 3, 17, 3.5, 1.7, 8, 0.05, 10, 17, 0.1, 8, 14, 3, 3.5, 1.7, 10, 17, 8, 17, 8, 0.05, 10, 0.1, 14)
A <- matrix(A, 4, 6, byrow=TRUE)
P <- 10^(-4) * c(1312, 1696, 5569, 124, 8283, 5886, 2329, 4135, 8307, 3736, 1004, 9991, 2348, 1451, 3522, 2883, 3047, 6650, 4047, 8828, 8732, 5743, 1091, 381)
P <- matrix(P, 4, 6, byrow=TRUE)
xxmat <- matrix(rep(xx,times=4), 4, 4, byrow=TRUE)
inner <- rowSums(A[,1:4]*(xxmat-P[,1:4])^2)
outer <- sum(alpha * exp(-inner))
y <- (1.1 - outer) / 0.839
return(y)
}
} else if (id == 43) {
f_zoo[id, 1] <<- "Hartmann 6-Dimensional Function"
f_zoo[id, 2] <<- "The 6-dimensional Hartmann function has 6 local minima."
f_zoo[id, 3] <<- 0
f_zoo[id, 4] <<- 1
f_zoo[id, 5] <<- NA
f_zoo[id, 6] <<- NA
f_zoo[id, 7] <<- -3.2237
f_zoo[id, 8] <<- TRUE
f_zoo[id, 9] <<- 6
f_zoo[id, 10] <<- FALSE
f <<- function(xx) {
alpha <- c(1.0, 1.2, 3.0, 3.2)
A <- c(10, 3, 17, 3.5, 1.7, 8, 0.05, 10, 17, 0.1, 8, 14, 3, 3.5, 1.7, 10, 17, 8, 17, 8, 0.05, 10, 0.1, 14)
A <- matrix(A, 4, 6, byrow=TRUE)
P <- 10^(-4) * c(1312, 1696, 5569, 124, 8283, 5886, 2329, 4135, 8307, 3736, 1004, 9991, 2348, 1451, 3522, 2883, 3047, 6650, 4047, 8828, 8732, 5743, 1091, 381)
P <- matrix(P, 4, 6, byrow=TRUE)
xxmat <- matrix(rep(xx,times=4), 4, 6, byrow=TRUE)
inner <- rowSums(A[,1:6]*(xxmat-P[,1:6])^2)
outer <- sum(alpha * exp(-inner))
y <- -(2.58 + outer) / 1.94
return(y)
}
} else if (id == 44) {
f_zoo[id, 1] <<- "Perm Function d=2, beta=0.5"
f_zoo[id, 2] <<- "The Perm function."
f_zoo[id, 3] <<- -2
f_zoo[id, 4] <<- 2
f_zoo[id, 5] <<- 1
f_zoo[id, 6] <<- 2
f_zoo[id, 7] <<- 0
f_zoo[id, 8] <<- TRUE
f_zoo[id, 9] <<- 2
f_zoo[id, 10] <<- FALSE
f <<- function(xx, b=0.5) {
d <- length(xx)
ii <- c(1:d)
jj <- matrix(rep(ii,times=d), d, d, byrow=TRUE)
xxmat <- matrix(rep(xx,times=d), d, d, byrow=TRUE)
inner <- rowSums((jj^ii+b)*((xxmat/jj)^ii-1))
outer <- sum(inner^2)
y <- outer
return(y)
}
} else if (id == 45) {
#set to 16 dimensions
f_zoo[id, 1] <<- "Powell Function"
f_zoo[id, 2] <<- "The Powell function."
f_zoo[id, 3] <<- -4
f_zoo[id, 4] <<- 5
f_zoo[id, 5] <<- 0
f_zoo[id, 6] <<- 0
f_zoo[id, 7] <<- 0
f_zoo[id, 8] <<- TRUE
f_zoo[id, 9] <<- 16
f_zoo[id, 10] <<- FALSE
f <<- function(xx) {
d <- length(xx)
xxa <- xx[seq(1, d-3, 4)]
xxb <- xx[seq(2, d-2, 4)]
xxc <- xx[seq(3, d-1, 4)]
xxd <- xx[seq(4, d, 4)]
sumterm1 <- (xxa + 10*xxb)^2
sumterm2 <- 5 * (xxc - xxd)^2
sumterm3 <- (xxb - 2*xxc)^4
sumterm4 <- 10 * (xxa - xxd)^4
sum <- sum(sumterm1 + sumterm2 + sumterm3 + sumterm4)
y <- sum
return(y)
}
} else if (id == 46) {
#solution = (4,4,4,4)
f_zoo[id, 1] <<- "Shekel Function"
f_zoo[id, 2] <<- "The Shekel function has m local minima."
f_zoo[id, 3] <<- 0
f_zoo[id, 4] <<- 10
f_zoo[id, 5] <<- NA
f_zoo[id, 6] <<- NA
f_zoo[id, 7] <<- -10.5364
f_zoo[id, 8] <<- TRUE
f_zoo[id, 9] <<- 4
f_zoo[id, 10] <<- FALSE
f <<- function(xx, m=10) {
m <- 10
b <- 0.1 * c(1, 2, 2, 4, 4, 6, 3, 7, 5, 5)
C <- c(4.0, 1.0, 8.0, 6.0, 3.0, 2.0, 5.0, 8.0, 6.0, 7.0, 4.0, 1.0, 8.0, 6.0, 7.0, 9.0, 3.0, 1.0, 2.0, 3.0, 4.0, 1.0, 8.0, 6.0, 3.0, 2.0, 5.0, 8.0, 6.0, 7.0, 4.0, 1.0, 8.0, 6.0, 7.0, 9.0, 3.0, 1.0, 2.0, 3.0)
C <- matrix(C, 4, 10, byrow=TRUE)
Ct <- t(C)
xxmat <- matrix(rep(xx,times=m), m, 4, byrow=TRUE)
inner <- rowSums((xxmat-Ct[,1:4])^2)
outer <- sum(1/(inner+b))
y <- -outer
return(y)
}
} else if (id == 47) {
f_zoo[id, 1] <<- "Styblinski-Tang Function"
f_zoo[id, 2] <<- "The Styblinski-Tang function."
f_zoo[id, 3] <<- -5
f_zoo[id, 4] <<- 5
f_zoo[id, 5] <<- -2.903534
f_zoo[id, 6] <<- -2.903534
f_zoo[id, 7] <<- -78.33198
f_zoo[id, 8] <<- TRUE
f_zoo[id, 9] <<- 2
f_zoo[id, 10] <<- FALSE
f <<- function(xx) {
sum <- sum(xx^4 - 16*xx^2 + 5*xx)
y <- sum/2
return(y)
}
}
}
f_plotter <- function(f, Name, Bound, Length = 101) {
x1 <- seq(-Bound, Bound, length = Length)
x2 <- seq(-Bound, Bound, length = Length)
X <- as.matrix(expand.grid(x1, x2))
colnames(X) <- c("x1", "x2")
y <- apply(X, 1, f)
df <- data.frame(X, y)
print(wireframe(y ~ x1 * x2, data = df, main = Name, shade = TRUE, scales = list(arrows = FALSE), screen = list(z = -50, x = -70)))
}
initialization <- function(Dimensions, Lower, Upper) {
return(rnorm(n = Dimensions, mean = mean(c(Lower, Upper)), sd = (Upper-Lower)/1000))
}
Here we will use optim's Simulated Annealing by Belisle, which is a stochastic global optimization method but is slow:
id <- 3
f_zoo_select(id)
f_plotter(f, f_zoo[id, "Name"], f_zoo[id, "Upper_Bound"], 101)
gc()
set.seed(11111)
initial_values <- initialization(f_zoo[id, "Dimensions"], f_zoo[id, "Lower_Bound"], f_zoo[id, "Upper_Bound"])
optimized <- optim(initial_values, fn = f, method = "L-BFGS-B", lower = f_zoo[id, "Lower_Bound"], upper = f_zoo[id, "Upper_Bound"], control = list(trace = 3, REPORT = 1, pgtol = 1e-20, factr = 1e-20, lmm = 100))
optimized <- optim(initial_values, fn = f, method = "Nelder-Mead", control = list(trace = 1, abstol = 1e-20, reltol = 1e-20))
optimized <- optim(initial_values, fn = f, method = "SANN", control = list(trace = 1, maxit = 1000000, abstol = 1e-20, reltol = 1e-20, temp = 4, tmax = 5))
optimized <- optim(initial_values, fn = f, method = "CG", control = list(trace = 1, abstol = 1e-20, reltol = 1e-20, type = 1))
optimized <- optim(initial_values, fn = f, method = "BFGS", control = list(trace = 1, abstol = 1e-20, reltol = 1e-20))
optimized$value
abs(optimized$value - f_zoo[id, "Minimum"])
optim_trainer <- function() {
optim_results <- data.frame(matrix(ncol = 5, nrow = 47))
colnames(optim_results) <- c("Name", "Result", "Expected", "Difference", "Timing")
for (id in 1:47) {
time <- System$currentTimeMillis()
f_zoo_select(id)
cat(sprintf("%.2d", id), "/47 in ", sprintf("%7.4f", sum(optim_results[, "Timing"], na.rm = TRUE)), "s: Optimizing ", f_zoo[id, "Name"], ": ...", sep = "")
gc()
set.seed(11111)
initial_values <- initialization(f_zoo[id, "Dimensions"], f_zoo[id, "Lower_Bound"], f_zoo[id, "Upper_Bound"])
#optimized <- optim(initial_values, fn = f, method = "L-BFGS-B", lower = f_zoo[id, "Lower_Bound"], upper = f_zoo[id, "Upper_Bound"], control = list(trace = 0, REPORT = 1, pgtol = 1e-20, factr = 1e-20, lmm = 100))
#optimized <- optim(initial_values, fn = f, method = "Nelder-Mead", control = list(trace = 0, abstol = 1e-20, reltol = 1e-20))
optimized <- optim(initial_values, fn = f, method = "SANN", control = list(trace = 0, maxit = 1000000, abstol = 1e-20, reltol = 1e-20, temp = 4, tmax = 5))
#optimized <- optim(initial_values, fn = f, method = "CG", control = list(trace = 0, abstol = 1e-20, reltol = 1e-20, type = 1))
#optimized <- optim(initial_values, fn = f, method = "BFGS", control = list(trace = 0, abstol = 1e-20, reltol = 1e-20))
optim_results[id, "Name"] <- f_zoo[id, "Name"]
optim_results[id, "Result"] <- optimized$value
optim_results[id, "Expected"] <- f_zoo[id, "Minimum"]
optim_results[id, "Difference"] <- abs(optimized$value - f_zoo[id, "Minimum"])
optim_results[id, "Timing"] <- (System$currentTimeMillis() - time) / 1000
cat("\r", sprintf("%.2d", id), "/47 in ", sprintf("%7.4f", optim_results[id, "Timing"]), " seconds: ", sprintf("%12.6f", optimized$value), ", supposed ", sprintf("%12.6f", f_zoo[id, "Minimum"]), " => ", sprintf("%12.6f", optim_results[id, "Difference"]), " difference [", f_zoo[id, "Name"], "]\n", sep = "")
}
cat("\n", sprintf("%6.4f", mean(optim_results[, "Timing"])), "s +-", sprintf("%6.4f", sd(optim_results[, "Timing"])), "s average computation time.\nAverage difference: ", mean(optim_results[, "Difference"][optim_results[, "Difference"] < 1e5], na.rm = TRUE), " +- ", sd(optim_results[, "Difference"][optim_results[, "Difference"] < 1e5], na.rm = TRUE), ".\n", sum((is.na(optim_results[, "Difference"])) | (optim_results[, "Difference"] > 1e6), na.rm = TRUE), " fatal errors.\n", sum((optim_results[, "Difference"] >= 0.00001) & (optim_results[, "Difference"] < 1e5), na.rm = TRUE), " errors.\n", sum(optim_results[, "Difference"] < 0.00001, na.rm = TRUE), " perfect results.", sep = "")
return(optim_results)
}
optim_results <- optim_trainer()
This is what we get for the test on the Cross-In-Tray function:
> gc()
used (Mb) gc trigger (Mb) max used (Mb)
Ncells 718990 38.4 1168576 62.5 1168576 62.5
Vcells 1365936 10.5 2552219 19.5 2286548 17.5
> set.seed(11111)
> initial_values <- initialization(f_zoo[id, "Dimensions"], f_zoo[id, "Lower_Bound"], f_zoo[id, "Upper_Bound"])
> optimized <- optim(initial_values, fn = f, method = "L-BFGS-B", lower = f_zoo[id, "Lower_Bound"], upper = f_zoo[id, "Upper_Bound"], control = list(trace = 3, REPORT = 1, pgtol = 1e-20, factr = 1e-20, lmm = 100))
N = 2, M = 100 machine precision = 2.22045e-16
At X0, 0 variables are exactly at the bounds
At iterate 0 f= -1.7905 |proj g|= 0.0061087
At iterate 1 f = -1.7905 |proj g|= 0.0049536
At iterate 2 f = -1.7906 |proj g|= 3.2496e-05
At iterate 3 f = -1.7906 |proj g|= 2.0212e-07
At iterate 4 f = -1.7906 |proj g|= 1.7477e-09
At iterate 5 f = -1.7906 |proj g|= 5.5511e-13
Bad direction in the line search;
refresh the lbfgs memory and restart the iteration.
At iterate 6 f = -1.7906 |proj g|= 0
iterations 6
function evaluations 28
segments explored during Cauchy searches 7
BFGS updates skipped 0
active bounds at final generalized Cauchy point 0
norm of the final projected gradient 0
final function value -1.7906
F = -1.7906
final value -1.790602
converged
> optimized <- optim(initial_values, fn = f, method = "Nelder-Mead", control = list(trace = 1, abstol = 1e-20, reltol = 1e-20))
Nelder-Mead direct search function minimizer
function value for initial parameters = -1.790496
Scaled convergence tolerance is 1.7905e-20
Stepsize computed as 0.452315
Exiting from Nelder Mead minimizer
3 function evaluations used
> optimized <- optim(initial_values, fn = f, method = "SANN", control = list(trace = 1, maxit = 1000000, abstol = 1e-20, reltol = 1e-20, temp = 4, tmax = 5))
(truncated...)
iter 995000 value -2.062612
iter 995500 value -2.062612
iter 996000 value -2.062612
iter 996500 value -2.062612
iter 997000 value -2.062612
iter 997500 value -2.062612
iter 998000 value -2.062612
iter 998500 value -2.062612
iter 999000 value -2.062612
iter 999500 value -2.062612
iter 999999 value -2.062612
final value -2.062612
sann stopped after 999999 iterations
> optimized <- optim(initial_values, fn = f, method = "CG", control = list(trace = 1, abstol = 1e-20, reltol = 1e-20, type = 1))
Conjugate gradients function minimizer
Method: Fletcher Reeves
tolerance used in gradient test=2e-30
(truncated...)
parameters 4.49100 4.49100
* i> 60 192 -1.790602
parameters 4.49100 4.49100
***** i> 61 199 -1.790602
parameters 4.49100 4.49100
** i> 62 203 -1.790602
parameters 4.49100 4.49100
********* i> 63 214 -1.790602
parameters 4.49100 4.49100
**64 216 -1.790602
parameters 4.49100 4.49100
i> 65 218 -1.790602
parameters 4.49100 4.49100
***********66 229 -1.790602
parameters 4.49100 4.49100
**********Exiting from conjugate gradients minimizer
239 function evaluations used
67 gradient evaluations used
> optimized <- optim(initial_values, fn = f, method = "BFGS", control = list(trace = 1, abstol = 1e-20, reltol = 1e-20))
initial value -1.790496
final value -1.790532
converged
> optimized$value
[1] -1.790532
> abs(optimized$value - f_zoo[id, "Minimum"])
[1] 0.2720779
When running the trainer, you do get insights about the current state of the benchmarking providing you the elapsed time, the predicted optima, the supposed optima, the difference, and the function name:
This is useful for debugging purposes as it allows you to find out what functions your optimizer cannot fit correctly. Remember that getting 47/47 on these functions is meaningless, as it shows you are able to overfit them perfectly but not a proof of generalization (after all, not many parameters are available to optimize - larger dimensional problems should causes major issues quickly).
This is what happens when you run SANN optim on the full zoo:
01/47 in 8.0668 seconds: 19.900286, supposed 0.000000 => 19.900286 difference [Ackley Function]
02/47 in 5.4058 seconds: 0.130773, supposed 0.000000 => 0.130773 difference [Bukin Function number 6]
03/47 in 6.7198 seconds: -2.062612, supposed -2.062610 => 0.000002 difference [Cross-In-Tray Function]
04/47 in 6.2144 seconds: -0.997581, supposed -1.000000 => 0.002419 difference [Drop-Wave Function]
05/47 in 6.3495 seconds: -66.843717, supposed -959.640700 => 892.796983 difference [Eggholder Function]
06/47 in 4.6033 seconds: -2.873899, supposed -0.869011 => 2.004888 difference [Gramacy & Lee Function]
07/47 in 5.5549 seconds: 0.003090, supposed 0.000000 => 0.003090 difference [Griewank Function]
08/47 in 6.8489 seconds: -5.712245, supposed -19.208500 => 13.496255 difference [Holder Table Function]
09/47 in 24.6565 seconds: -2.193738, supposed -1.500000 => 0.693738 difference [Langermann Function]
10/47 in 11.0249 seconds: 0.000000, supposed 0.000000 => 0.000000 difference [Levy Function]
11/47 in 8.4090 seconds: 0.000004, supposed 0.000000 => 0.000004 difference [Levy Function number 13]
12/47 in 5.2337 seconds: 0.000000, supposed 0.000000 => 0.000000 difference [Rastrigin Function]
13/47 in 6.5048 seconds: 0.000000, supposed 0.000000 => 0.000000 difference [Schaffer Function number 2]
14/47 in 7.6714 seconds: 0.500086, supposed 0.292579 => 0.207507 difference [Schaffer Function number 4]
15/47 in 5.4739 seconds: 830.075197, supposed 0.000000 => 830.075197 difference [Schwefel Function]
16/47 in 8.3319 seconds: -186.730880, supposed -186.730900 => 0.000020 difference [Schubert Function]
17/47 in 6.7768 seconds: 0.000000, supposed 0.000000 => 0.000000 difference [Bohachevsky Function number 1]
18/47 in 19.6089 seconds: 0.000001, supposed 0.000000 => 0.000001 difference [Perm Function 0, d=2, beta=10]
19/47 in 26.5208 seconds: 0.000001, supposed 0.000000 => 0.000001 difference [Rotated HYper-Ellipsoid Function]
20/47 in 3.4785 seconds: 0.000000, supposed 0.000000 => 0.000000 difference [Sphere Function]
21/47 in 4.8014 seconds: 0.000000, supposed 0.000000 => 0.000000 difference [Sum of Different Powers Function]
22/47 in 5.2505 seconds: 0.000001, supposed 0.000000 => 0.000001 difference [Sum Squares Function]
23/47 in 8.0968 seconds: -49.994434, supposed -200.000000 => 150.005566 difference [Trid Function]
24/47 in 5.0946 seconds: 0.000001, supposed 0.000000 => 0.000001 difference [Booth Function]
25/47 in 5.0856 seconds: 0.000000, supposed 0.000000 => 0.000000 difference [Matyas Function]
26/47 in 7.1521 seconds: -724.479527, supposed -1.913300 => 722.566227 difference [McCormick Function]
27/47 in 16.5868 seconds: 0.000437, supposed 0.000000 => 0.000437 difference [Power Sum Function]
28/47 in 6.4025 seconds: 0.000000, supposed 0.000000 => 0.000000 difference [Zakharov Function]
29/47 in 6.4566 seconds: 0.000001, supposed 0.000000 => 0.000001 difference [Three-Hump Camel Function]
30/47 in 7.7280 seconds: -1.031628, supposed -1.031600 => 0.000028 difference [Sixth-Hump Camel Function]
31/47 in 8.2800 seconds: 0.000001, supposed 0.000000 => 0.000001 difference [Dixon-Price Function]
32/47 in 7.0610 seconds: 0.000003, supposed 0.000000 => 0.000003 difference [Rosenbrock Function]
33/47 in 22.1177 seconds: 23.809434, supposed 0.998000 => 22.811434 difference [De Jong Function number 5]
34/47 in 6.0223 seconds: -0.997678, supposed -1.000000 => 0.002322 difference [Easom Function]
35/47 in 6.6287 seconds: -1.997497, supposed -1.801300 => 0.196197 difference [Michalewicz Function]
36/47 in 7.2031 seconds: 0.000001, supposed 0.000000 => 0.000001 difference [Beale Function]
37/47 in 8.5434 seconds: 0.397888, supposed 0.397887 => 0.000001 difference [Branin Function]
38/47 in 10.9881 seconds: 0.002068, supposed 0.000000 => 0.002068 difference [Colville Function]
39/47 in 6.1574 seconds: -510.883737, supposed -6.020740 => 504.862997 difference [Forrester et al. Function]
40/47 in 10.9638 seconds: 3.000010, supposed 3.000000 => 0.000010 difference [Goldstein-Price Function]
41/47 in 24.1832 seconds: -2.927386, supposed -3.862780 => 0.935394 difference [Hartmann 3-Dimensional Function]
42/47 in 26.4498 seconds: -1.091476, supposed -3.135474 => 2.043998 difference [Hartmann 4-Dimensional Function]
43/47 in 27.2223 seconds: -1.592905, supposed -3.223700 => 1.630795 difference [Hartmann 6-Dimensional Function]
44/47 in 20.3054 seconds: 0.000001, supposed 0.000000 => 0.000001 difference [Perm Function d=2, beta=0.5]
45/47 in 104.7935 seconds: 0.179925, supposed 0.000000 => 0.179925 difference [Powell Function]
46/47 in 29.6162 seconds: -0.849542, supposed -10.536400 => 9.686858 difference [Shekel Function]
47/47 in 4.7544 seconds: -64.195612, supposed -78.331980 => 14.136368 difference [Styblinski-Tang Function]
12.4979s +-15.6021s average computation time.
Average difference: 67.8377 +- 212.1686.
0 fatal errors.
27 errors.
20 perfect results.