
A set of functions implementing simple variable selection in classification applications using simulated annealing
SAfun(x, response, eval.fun, Tinit, niter = 100,
cooling = 0.05, fraction = 0.3, ...)
SAfun2(x, response, eval.fun, Tinit, niter = 100,
cooling = 0.05, fraction = 0.3, ...)SAstep(curr.set, maxvar, fraction = .3, size.dev = 1)
Data matrix: independent variables used by eval.fun
Class vector, used by eval.fun
evaluation function. Should take a data matrix, a class vector (or factor), and a subset argument
Initial temperature
Maximal number of iterations
Cooling speed
Size of the desired subset, as a fraction of the total number of variables
Further arguments to the evaluation function
Current trial solution
The total number of variables to choose from
Parameter governing the variability in size of subsequent subsets
Functions SAfun
and SAfun2
both return a list
containing the following fields:
The best subset
The quality of the best subset
A vector containing quality values of solutions seen throughout the optimization
A vector containing logicals indicating which solutions were accepted and which were rejected
Simulated Annealing (SA) starts with a random subset, and
proceeds by random moves in the solution space. In this
implementation, a new solution may deviate in length at most
size.dev
variables: at most two variables may be swapped in or
out at each step. If a step is an improvement, it is unconditionally
accepted. If not, acceptance is a stochastic process depending on the
current temperature - with high temperatures, "bad" moves are more
likely to be accepted than with low temperatures. The process stops
after a predefined number of iterations.
R. Wehrens. "Chemometrics with R - Multivariate Data Analysis in the Natural Sciences and Life Sciences". Springer, Heidelberg, 2011.
# NOT RUN {
if (require("pls")) {
data(gasoline, package = "pls")
## usually more than 50 iterations are needed
SAobj <- SAfun(gasoline$NIR, gasoline$octane,
eval.fun = pls.cvfun, Tinit = 3,
fraction = .02, niter = 50, ncomp = 2)
SAobj
} else {
cat("Package pls not available.\nInstall it by typing 'install.packages(\"pls\")'")
}
# }
Run the code above in your browser using DataLab