# # High dimensional function for lecture "Numerical Optimization". # # Author: Sangkyun Lee (sangkyun.lee@tu-dortmund.de) # # # A high-dim function # #n = 1000 if(!exists("n")) { stop("Error! Define a variable named 'n' and set it to a multiple of 10") } if(!exists("mode")) { stop("Error! Define a variable named 'mode' and set it to either 1 (unique) or 2 (clustered) to choose different Hessian matrices") } set.seed(1271) H = matrix(runif(n^2), n, n) Q = qr.Q(qr(H), complete=TRUE) if(mode==1) { J = diag( sqrt(seq(1,sqrt(n),length.out=n)) ) %*% t(Q) } else { J = diag( sqrt(rep( seq(1,sqrt(n),length.out=5),n/5)) )%*% t(Q) } JJ = t(J)%*%J; if(exists("plot.eig")) { plot(sort(eigen(JJ, only.values=TRUE)$values), type="p", pch=20, ylab="Eigenvalues of the Hessian", cex=.5) } c = vec(runif(n))/n; f <- function(x) { if (!(class(x)=="matrix" && nrow(x)==ncol(J) && ncol(x)==1)) { print("Error in f(x): x must be nx1 matrix"); return (NULL); } val = J %*% x - c; val = .5 * t(val) %*% val return(as.numeric(val)); } g <- function(x) { if (!(class(x)=="matrix" && nrow(x)==ncol(J) && ncol(x)==1)) { print("Error in f(x): x must be nx1 matrix"); return (NULL); } val = JJ%*%x - t(J)%*%c return(val) } H <- function(x) { if (!(class(x)=="matrix" && nrow(x)==ncol(J) && ncol(x)==1)) { print("Error in f(x): x must be nx1 matrix"); return (NULL); } val = JJ return(val) }