# NOT RUN {
n <- 1000
k <- 6
# Randomly generated matrix M
W <- matrix(rnorm(n^2), n, n)
W <- t(W) %*% W
# Randomly generated orthonormal initial matrix
X0 <- matrix(rnorm(n*k), n, k)
X0 <- qr.Q(qr(X0))
# The objective function and its gradient
fun <- function(X, W){
F <- - sum(diag(t(X) %*% W %*% X))
G <- - 2*(W %*% X)
return(list(F = F, G = G))
}
# Options list
opts<-list(record = 0, maxiter = 1000, xtol = 1e-5, gtol = 1e-5, ftol = 1e-8)
# Main part
output <- OptStiefelGBB(X0, fun, opts, W)
X <- output$X
out <- output$out
# }
Run the code above in your browser using DataLab