gridSearch(NMOF)
gridSearch()所属R语言包:NMOF
Grid Search
网格搜索
译者:生物统计家园网 机器人LoveR
描述----------Description----------
Evaluate a function for a given list of possible arguments.
评估一个可能的参数列表的功能。
用法----------Usage----------
gridSearch(fun, levels, ..., lower, upper, npar = 1L, n = 5L,
printDetail = TRUE,
method = NULL,
mc.control = list(), cl = NULL,
keepNames = FALSE, asList = FALSE)
参数----------Arguments----------
参数:fun
a function of the form fun(x, ...), with x being a numeric vector or a list of numeric vectors (of length one)
函数的形式fun(x, ...),与x是一个数值向量或列表的数字向量(长度为1)
参数:levels
a list of levels for the arguments (see Examples)
一个级别的参数列表(见例)
参数:...
objects passed to fun
对象传递给fun
参数:lower
a numeric vector. Ignored if levels are explicitly specified.
一个数值向量。如果忽略水平显式指定的。
参数:upper
a numeric vector. Ignored if levels are explicitly specified.
一个数值向量。如果忽略水平显式指定的。
参数:npar
the number of parameters. Must be supplied if lower and upper are to be expanded; see Details. Ignored when levels are explicitly specified, or when lower/upper are used and at least one has lenght greater than one. See Examples.
的参数的数目。如果lower和upper是要扩大;详细,必须提供。忽略levels被明确指定,或者当lower/upper和至少一个长度大于1。请参阅示例。
参数:n
the number of levels. Default is 5. Ignored if levels are explicitly specified.
的级别数。默认值是5。如果忽略水平显式指定的。
参数:printDetail
print information on the number of objective function evaluations
打印信息的数量目标函数评价
参数:method
can be loop (the default), multicore or snow. See Details.
可以loop(默认值),multicore或snow。查看详细信息。
参数:mc.control
a list containing settings that will be passed to mclapply if method is multicore. Must be a list of named elements; see the documentation of mclapply in pkgmulticore.
一个列表,其中包含设置将被传递给mclapply如果method是multicore。命名的元素必须是一个列表,看到的文档mclapply在pkgmulticore。
参数:cl
default is NULL. If method snow is used, this must be a cluster object or an integer (the number of cores).
默认是NULL。如果方法snow时,这必须是一个的聚类对象或一个整数(核心)。
参数:keepNames
logical: should the names of levels be kept?
logical:应的名字levels保持?
参数:asList
does fun expect a list? Default is FALSE.
不fun期待一个列表?默认是FALSE。
Details
详细信息----------Details----------
A grid search can be used to find "good" parameter values for a function. In principle, a grid search has an obvious deficiency: as the length of x (the first argument to fun) increases, the number of necessary function evaluations grows exponentially. Note that gridSearch will not warn about an unreasonable number of function evaluations, but if printDetail is TRUE it will print the required number of function evaluations.
可以使用一个网格搜索,找到“好”的参数值的函数。原则上,一个网格搜索有一个明显的缺陷的长度x(fun)增加的第一个参数,必要的功能评价的数量呈指数级增长。请注意,gridSearch不发出警告的功能评估不合理的,但如果printDetail是TRUE将打印所需的功能评估。
In practice, grid search is often better than its reputation. If a function takes only a few parameters, it is often a reasonable approach to find "good" parameter values.
在实践中,往往是更好的网格搜索比它的名声。如果一个函数只需要几分钟的参数,它往往是一种合理的方法,找到“好”的参数值。
The function uses the mechanism of expand.grid to create the list of parameter combinations for which fun is evaluated; it calls lapply to evaluate fun if method == "loop" (the default).
该函数使用的机制,它调用expand.grid创建列表中的参数组合,fun被评为lapply评估fun如果method == "loop"(默认情况下)。
If method == "multicore", the function mclapply from package multicore is used. Further settings for mclapply can be passed through the list mc.control. If multicore is chosen but not available, then method will be set to loop and a warning is issued. If method == "snow", the function clusterApply from package snow is used. In this case, the argument cl must either be a cluster object (see the documentation of clusterApply) or an integer. If an integer, a cluster will be set up via makeCluster(c(rep("localhost", cl)), type = "SOCK") (and stopCluster is called when the function is exited). If snow is chosen but not available or cl is not specified, then method will be set to loop and a warning is issued.
如果method == "multicore",功能mclapply从软件包multicore使用。进一步的设置为mclapply可以通过列表中mc.control。如果multicore选择,但不可用,那么method将被设置为loop和发出警告。如果method == "snow",功能clusterApply从软件包snow使用。在这种情况下,参数cl必须是聚类对象(请参阅文档clusterApply)或整数。如果一个整数,将成立一个聚类,通过makeCluster(c(rep("localhost", cl)), type = "SOCK")(stopCluster当函数被调用退出)。如果snow选择,但不可用或cl没有指定,那么method将被设置为loop和发出警告。
值----------Value----------
A list.
一个列表。
参数:minfun
the minimum of fun.
最小fun。
参数:minlevels
the levels that give this minimum.
给这个最小的水平。
参数:values
a list. All the function values of fun.
一个列表。所有的函数值fun。
参数:levels
a list. All the levels for which fun was evaluated.
一个列表。所有的水平fun进行评价。
(作者)----------Author(s)----------
Enrico Schumann
参考文献----------References----------
http://www.elsevierdirect.com/product.jsp?isbn=9780123756626
Package. http://enricoschumann.net/NMOF.htm
实例----------Examples----------
testFun <- function(x) x[1L] + x[2L]^2
sol <- gridSearch(fun = testFun, levels = list(1:2, c(2, 3, 5)))
sol$minfun
sol$minlevels
## specify all levels[#指定各级]
levels <- list(a = 1:2, b = 1:3)
res <- gridSearch(testFun, levels)
res$minfun
sol$minlevels
## specify lower, upper and npar[#指定上下及的NPar]
lower <- 1; upper <- 3; npar <- 2
res <- gridSearch(testFun, lower = lower, upper = upper, npar = npar)
res$minfun
sol$minlevels
## specify lower, upper, npar and n[#指定下,上,NPAR和n,]
lower <- 1; upper <- 3; npar <- 2; n <- 4
res <- gridSearch(testFun, lower = lower, upper = upper, npar = npar, n = n)
res$minfun
sol$minlevels
## specify lower, upper and n[#指定下,上和n]
lower <- c(1,1); upper <- c(3,3); n <- 4
res <- gridSearch(testFun, lower = lower, upper = upper, n = n)
res$minfun
sol$minlevels
## specify lower, upper (auto-expanded) and n[#指定下,上(自动扩展)和N]
lower <- c(1,1); upper <- 3; n <- 4
res <- gridSearch(testFun, lower = lower, upper = upper, n = n)
res$minfun
sol$minlevels
转载请注明:出自 生物统计家园网(http://www.biostatistic.net)。
注:
注1:为了方便大家学习,本文档为生物统计家园网机器人LoveR翻译而成,仅供个人R语言学习参考使用,生物统计家园保留版权。
注2:由于是机器人自动翻译,难免有不准确之处,使用时仔细对照中、英文内容进行反复理解,可以帮助R语言的学习。
注3:如遇到不准确之处,请在本贴的后面进行回帖,我们会逐渐进行修订。
|