Description Usage Arguments Value Examples
Simulated Annealing is a black-box, derivative-free optimization algorithm that iterates via stochastic search in the neighborhood of current position.
1 2 3 4 5 6 7 8 9 10 |
func |
a function to be minimized. |
size |
a length-2 vector containing dimension information (p,r). |
n.start |
number of runs, i.e., algorithm is executed |
stepsize |
size of random walk on each component. |
maxiter |
maximum number of iterations for each run. |
cooling |
triplet for cooling schedule. See the section for the usage. |
init.val |
if |
print.progress |
a logical; |
a named list containing:
minimized function value.
a (p\times r) matrix that attains the cost
.
frequency of acceptance moves.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | ## Optimization for eigen-decomposition
# Let's find top-3 eigenvalues
set.seed(121) # set seed
A = cov(matrix(rnorm(100*5), ncol=5)) # define covariance
myfunc <- function(p){ # cost function
return(sum(-diag(t(p)%*%A%*%p)))
}
# Solve the optimization problem
Aout = stopt.SA(myfunc, size=c(5,3), n.start=40, maxiter=500)
# Compute 3 Eigenvalues
# 1. use computed basis
abase = Aout$solution
eig3sol = sort(diag(t(abase)%*%A%*%abase), decreasing=TRUE)
# 2. use 'eigen' function
eig3dec = sort(eigen(A)$values, decreasing=TRUE)[1:3]
# Visualize
opar <- par(no.readonly=TRUE)
yran = c(min(min(eig3sol),min(eig3dec))*0.95,
max(max(eig3sol),max(eig3dec))*1.05)
plot(1:3, eig3sol, type="b", col="red", pch=19, ylim=yran,
xlab="index", ylab="eigenvalue", main="compare top 3 eigenvalues")
lines(1:3, eig3dec, type="b", col="blue", pch=19)
legend(1, 1, legend=c("optimization","decomposition"), col=c("red","blue"),
lty=rep(1,2), pch=19)
par(opar)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.