Learn R Programming

ChemometricsWithR (version 0.1.13)

SA: Simulated Annealing for variable selection in classification

Description

A set of functions implementing simple variable selection in classification applications using simulated annealing

Usage

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)

Arguments

x

Data matrix: independent variables used by eval.fun

response

Class vector, used by eval.fun

eval.fun

evaluation function. Should take a data matrix, a class vector (or factor), and a subset argument

Tinit

Initial temperature

niter

Maximal number of iterations

cooling

Cooling speed

fraction

Size of the desired subset, as a fraction of the total number of variables

Further arguments to the evaluation function

curr.set

Current trial solution

maxvar

The total number of variables to choose from

size.dev

Parameter governing the variability in size of subsequent subsets

Value

Functions SAfun and SAfun2 both return a list containing the following fields:

best

The best subset

best.q

The quality of the best subset

In addition, the outcome of SAfun2 also contains
qualities

A vector containing quality values of solutions seen throughout the optimization

accepts

A vector containing logicals indicating which solutions were accepted and which were rejected

Details

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.

References

R. Wehrens. "Chemometrics with R - Multivariate Data Analysis in the Natural Sciences and Life Sciences". Springer, Heidelberg, 2011.

See Also

Evaluation, GA

Examples

Run this code
# 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