R : Copyright 2005, The R Foundation for Statistical Computing Version 2.1.1 (2005-06-20), ISBN 3-900051-07-0 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for a HTML browser interface to help. Type 'q()' to quit R. > ### *
> ### > attach(NULL, name = "CheckExEnv") > assign(".CheckExEnv", as.environment(2), pos = length(search())) # base > ## add some hooks to label plot pages for base and grid graphics > setHook("plot.new", ".newplot.hook") > setHook("persp", ".newplot.hook") > setHook("grid.newpage", ".gridplot.hook") > > assign("cleanEx", + function(env = .GlobalEnv) { + rm(list = ls(envir = env, all.names = TRUE), envir = env) + RNGkind("default", "default") + set.seed(1) + options(warn = 1) + delayedAssign("T", stop("T used instead of TRUE"), + assign.env = .CheckExEnv) + delayedAssign("F", stop("F used instead of FALSE"), + assign.env = .CheckExEnv) + sch <- search() + newitems <- sch[! sch %in% .oldSearch] + for(item in rev(newitems)) + eval(substitute(detach(item), list(item=item))) + missitems <- .oldSearch[! .oldSearch %in% sch] + if(length(missitems)) + warning("items ", paste(missitems, collapse=", "), + " have been removed from the search path") + }, + env = .CheckExEnv) > assign("..nameEx", "__{must remake R-ex/*.R}__", env = .CheckExEnv) # for now > assign("ptime", proc.time(), env = .CheckExEnv) > grDevices::postscript("race-Examples.ps") > assign("par.postscript", graphics::par(no.readonly = TRUE), env = .CheckExEnv) > options(contrasts = c(unordered = "contr.treatment", ordered = "contr.poly")) > options(warn = 1) > library('race') > > assign(".oldSearch", search(), env = .CheckExEnv) > assign(".oldNS", loadedNamespaces(), env = .CheckExEnv) > cleanEx(); ..nameEx <- "race" > > ### * race > > flush(stderr()); flush(stdout()) > > ### Name: race > ### Title: Racing methods for the selection of the best > ### Aliases: race > ### Keywords: design htest optimize > > ### ** Examples > > # The wrapper and init functions for this example are defined in the > # file examples/example-wrapper.R in the installation directory of the > # package. Please, have a look at such file before implementing your > # own wrapper. > # This example require the package `nnet' > if (require(nnet)&&require(datasets)){ + example.wrapper<-file.path(system.file(package="race"), + "examples","example-wrapper.R") + # Run the race + race(example.wrapper) + + # If the package `rpvm' is installed on your system and if PVM is + # properly installed and configured, you can try the following: + #race(example.wrapper,no.slaves=6) + } Loading required package: nnet Racing methods for the selection of the best Copyright (C) 2003 Mauro Birattari This software comes with ABSOLUTELY NO WARRANTY Race name.........................Model Selection: nnet on iris Number of candidates.........................................50 Number of available tasks....................................15 Max number of experiments.............................unlimited Statistical test..................................Friedman test Tasks seen before discarding..................................5 Initialization function......................................ok Parallel Virtual Machine.....................................no This is a very simple example that shows how to use the 'race' package. By using a 15-fold cross-validation, we optimize the structure of a neural network. In this example, we optimize the number of nodes and the decay. See the help of function 'nnet' in the homonymous package. We limit here the number of iteration of the training process for didactical reasons. Markers: x No test is performed. - The test is performed and some candidates are discarded. = The test is performed but no candidate is discarded. +-+-----------+-----------+-----------+-----------+-----------+ | | Task| Alive| Best| Mean best| Exp so far| +-+-----------+-----------+-----------+-----------+-----------+ |x| 1| 50| 6| 0| 50| |x| 2| 50| 6| 0| 100| |x| 3| 50| 18| 0| 150| |x| 4| 50| 18| 0.025| 200| |-| 5| 25| 18| 0.02| 250| |=| 6| 25| 18| 0.01667| 275| |=| 7| 25| 18| 0.02857| 300| |=| 8| 25| 18| 0.0375| 325| |=| 9| 25| 18| 0.04444| 350| |=| 10| 25| 44| 0.09| 375| |=| 11| 25| 18| 0.07273| 400| |=| 12| 25| 47| 0.08333| 425| |=| 13| 25| 47| 0.09231| 450| |=| 14| 25| 47| 0.1| 475| |=| 15| 25| 47| 0.1| 500| +-+-----------+-----------+-----------+-----------+-----------+ Selected candidate: 47 mean value: 0.1 Description of the selected candidate: size decay 47 7 5e-04 > > > > cleanEx(); ..nameEx <- "race.describe" > > ### * race.describe > > flush(stderr()); flush(stdout()) > > ### Name: race.describe > ### Title: Describe a candidate > ### Aliases: race.describe > ### Keywords: misc > > ### ** Examples > > # Please have a look at the function `race.describe' > # defined in the file `example-wrapper.R': > local({ + source(file.path(system.file(package="race"), + "examples","example-wrapper.R"),local=TRUE); + print(race.describe)}) function (candidate, data) return(data$candidates[candidate, ]) > > > > cleanEx(); ..nameEx <- "race.info" > > ### * race.info > > flush(stderr()); flush(stdout()) > > ### Name: race.info > ### Title: Provide information on the race > ### Aliases: race.info > ### Keywords: misc > > ### ** Examples > > # Please have a look at the function `race.info' > # defined in the file `example-wrapper.R': > local({ + source(file.path(system.file(package="race"), + "examples","example-wrapper.R"),local=TRUE); + print(race.info)}) function (data) return(list(race.name = "Model Selection: nnet on iris", no.candidates = (data$no.candidates), no.tasks = data$no.tasks, extra = paste("This is a very simple example that shows", "how to use the 'race' package.", "By using a", paste(data$no.tasks, "-fold", sep = ""), "cross-validation,", "we optimize the structure of a neural network.", "In this example, we optimize the number of nodes", "and the decay. See the help of function 'nnet'", "in the homonymous package.", "We limit here the number of iteration of the", "training process for didactical reasons."))) > > > > cleanEx(); ..nameEx <- "race.init" > > ### * race.init > > flush(stderr()); flush(stdout()) > > ### Name: race.init > ### Title: Initialization function > ### Aliases: race.init > ### Keywords: misc > > ### ** Examples > > # Please have a look at the function `race.init' > # defined in the file `example-wrapper.R': > local({ + source(file.path(system.file(package="race"), + "examples","example-wrapper.R"),local=TRUE); + print(race.init)}) function () { library(nnet) data(iris) k <- 15 n <- nrow(iris) if (exists(".Random.seed")) save.seed <- .Random.seed set.seed(0) smpl <- sample(n) if (exists("save.seed", inherits = FALSE)) assign(".Random.seed", save.seed, envir = globalenv()) else rm(".Random.seed", envir = globalenv()) msk <- k * c(0:(ceiling(n/k) - 1)) candidates <- expand.grid(size = c(1:10), decay = c(1:5) * 1e-04) return(list(no.candidates = nrow(candidates), no.tasks = k, msk = msk, smpl = smpl, iris = iris, candidates = candidates)) } > > > > cleanEx(); ..nameEx <- "race.wrapper" > > ### * race.wrapper > > flush(stderr()); flush(stdout()) > > ### Name: race.wrapper > ### Title: Test a candidate on a task > ### Aliases: race.wrapper > ### Keywords: misc > > ### ** Examples > > # Please have a look at the function `race.wrapper' > # defined in the file `example-wrapper.R': > local({ + source(file.path(system.file(package="race"), + "examples","example-wrapper.R"),local=TRUE); + print(race.wrapper)}) function (candidate, task, data) { idx <- data$smpl[task + data$msk] training.set <- data$iris[-idx, ] if (.Platform$OS.type == "unix") { dev.null <- file("/dev/null", open = "w") sink(dev.null) } nn <- nnet(Species ~ ., data = training.set, maxit = 10, size = data$candidates[candidate, "size"], decay = data$candidates[candidate, "decay"]) if (.Platform$OS.type == "unix") { sink(NULL) close(dev.null) } unseen.input <- data$iris[idx, 1:4] target.output <- as.character(data$iris$Species[idx]) predicted.output <- predict(nn, unseen.input, type = "class") return(mean(predicted.output != target.output)) } > > > > ### *