Package zoomgrid. January 3, 2019

Similar documents
Package cattonum. R topics documented: May 2, Type Package Version Title Encode Categorical Features

Package fastdummies. January 8, 2018

Package PSTR. September 25, 2017

Package datasets.load

Package geojsonsf. R topics documented: January 11, Type Package Title GeoJSON to Simple Feature Converter Version 1.3.

Package ggimage. R topics documented: November 1, Title Use Image in 'ggplot2' Version 0.0.7

Package SEMrushR. November 3, 2018

Package ECctmc. May 1, 2018

Package validara. October 19, 2017

Package ggimage. R topics documented: December 5, Title Use Image in 'ggplot2' Version 0.1.0

Package pbmcapply. August 16, 2017

Package jdx. R topics documented: January 9, Type Package Title 'Java' Data Exchange for 'R' and 'rjava'

Package sfc. August 29, 2016

Package messaging. May 27, 2018

Package mixsqp. November 14, 2018

Package semver. January 6, 2017

Package bisect. April 16, 2018

Package spark. July 21, 2017

Package repec. August 31, 2018

Package vip. June 15, 2018

Package GenSA. R topics documented: January 17, Type Package Title Generalized Simulated Annealing Version 1.1.

Package nmslibr. April 14, 2018

Package opencage. January 16, 2018

Package liftr. R topics documented: May 14, Type Package

Package canvasxpress

Package gtrendsr. August 4, 2018

Package gtrendsr. October 19, 2017

Package Numero. November 24, 2018

Package facerec. May 14, 2018

Package gggenes. R topics documented: November 7, Title Draw Gene Arrow Maps in 'ggplot2' Version 0.3.2

Package preprosim. July 26, 2016

Package ecoseries. R topics documented: September 27, 2017

Package rsppfp. November 20, 2018

Package calpassapi. August 25, 2018

Package balance. October 12, 2018

Package editdata. October 7, 2017

Package docxtools. July 6, 2018

Package qualmap. R topics documented: September 12, Type Package

Package elmnnrcpp. July 21, 2018

Package pwrab. R topics documented: June 6, Type Package Title Power Analysis for AB Testing Version 0.1.0

Package WordR. September 7, 2017

Package deductive. June 2, 2017

Package rprojroot. January 3, Title Finding Files in Project Subdirectories Version 1.3-2

Package spelling. December 18, 2017

Package stapler. November 27, 2017

Package filematrix. R topics documented: February 27, Type Package

Package MTLR. March 9, 2019

Package fitur. March 11, 2018

Package subplex. April 5, 2018

Package splithalf. March 17, 2018

Package raker. October 10, 2017

Package crossrun. October 8, 2018

Package slickr. March 6, 2018

Package githubinstall

Package bigreadr. R topics documented: August 13, Version Date Title Read Large Text Files

Package edfreader. R topics documented: May 21, 2017

Package barcoder. October 26, 2018

Package vinereg. August 10, 2018

Package wrswor. R topics documented: February 2, Type Package

Package readxl. April 18, 2017

Package intcensroc. May 2, 2018

Package narray. January 28, 2018

Package CorporaCoCo. R topics documented: November 23, 2017

Package widyr. August 14, 2017

Package CatEncoders. March 8, 2017

Package queuecomputer

Package weco. May 4, 2018

Package shinyfeedback

Package linkspotter. July 22, Type Package

Package cancensus. February 4, 2018

Package desplot. R topics documented: April 3, 2018

Package knitrprogressbar

Package tiler. June 9, 2018

Package TrafficBDE. March 1, 2018

Package MonteCarlo. April 23, 2017

Package regexselect. R topics documented: September 22, Version Date Title Regular Expressions in 'shiny' Select Lists

Package kdtools. April 26, 2018

Package mmpa. March 22, 2017

Package essurvey. August 23, 2018

Package mdftracks. February 6, 2017

Package jstree. October 24, 2017

Package nngeo. September 29, 2018

Package quadprogxt. February 4, 2018

Package triebeard. August 29, 2016

Package pdfsearch. July 10, 2018

Package kirby21.base

Package diffusr. May 17, 2018

Package kerasformula

Package geogrid. August 19, 2018

Package future.apply

Package embed. November 19, 2018

Package robotstxt. November 12, 2017

Package sessioninfo. June 21, 2017

Package FSelectorRcpp

Package effectr. January 17, 2018

Package lumberjack. R topics documented: July 20, 2018

Package fastqcr. April 11, 2017

Package censusapi. August 19, 2018

Package datapasta. January 24, 2018

Package mgc. April 13, 2018

Transcription:

Package zoomgrid January 3, 2019 Type Package Title Grid Search Algorithm with a Zoom Version 1.0.0 Description Provides the grid search algorithm with a zoom. The grid search algorithm with a zoom aims to help solving difficult optimization problem where there are many local optima inside the domain of the target function. It offers suitable initial or starting value for the following optimization procedure, provided that the global optimum exists in the neighbourhood of the initial or starting value. The grid search algorithm with a zoom saves time tremendously in cases with highdimensional arguments. Depends R (>= 3.0.0) License GPL-3 Encoding UTF-8 LazyData true RoxygenNote 6.1.1 URL https://github.com/yukai-yang/zoomgrid BugReports https://github.com/yukai-yang/zoomgrid/issues Imports parallel Suggests knitr, rmarkdown VignetteBuilder knitr NeedsCompilation no Author Yukai Yang [aut, cre] (<https://orcid.org/0000-0002-2623-8549>) Maintainer Yukai Yang <yukai.yang@statistik.uu.se> Repository CRAN Date/Publication 2019-01-03 17:00:03 UTC 1

2 build_grid R topics documented: build_grid.......................................... 2 grid_search......................................... 3 grid_search_check..................................... 6 zoomgrid.......................................... 8 Index 10 build_grid Build the grid for the grid search algorithm with a zoom. Description This function builds the grid for the grid search algorithm with a zoom. Usage build_grid(...) Arguments... a sequence of vectors or lists containing the information about the grid to be built, see Usage and Details. Details The argument... is a sequence of vectors or lists contatining the information about the grid to be built. Each element in the sequence is either a vector or a list taking one of the following forms - x, if x is already an sequence of the grid points for the corresponding argument. - c(from=, to=, by=) - c(from=, to=, length=) - list(from=, to=, by=) - list(from=, to=, length=) where - from: the min of the argument of the target function - to: the max of the argument of the target function - by: the increment of the sequence - length: desired length. There are many different ways to organize the points on the grid for certain argument of the target function, the user can make them freely and input directly by build_grid(x,...). Notice that x does not need to be increasing, as the function will sort it. The design that x does not need to be increasing makes it convenient for the user to interpolate more points at some region without considering to sort it all the time.

grid_search 3 When by is provided, the length will be ignored. So if the user wanna specify the length, please do not use by. The order of the sequence... matters as it represents the order of the corresponding arguments of the target function to be optimized. Value a new object of the class GRID with the grid ready for the grid search with a zoom. The object contains the following components: grid size npar the grid number of points in the grid number of arguments or parameters Author(s) Yukai Yang, <yukai.yang@statistik.uu.se> See Also grid_search_check, grid_search Examples vx = 1:5 build_grid(vx, c(from=1, to=2, by=.2), list(from=3, to=4, length=5)) grid_search Carry out the grid search algorithm with a zoom. Description This function carries out the grid search algorithm with a zoom. Usage grid_search(fun, grid, MoreArgs = NULL, zoom = 0, decay = 0.5, num = 1, parallel = FALSE, cores = NULL, silent = TRUE)

4 grid_search Arguments FUN grid MoreArgs zoom decay num parallel cores silent the target function to be minimized. an object of the class GRID from build_grid. a list of other arguments to FUN, see mapply. number of (additional) rounds or layers of the zoom-in, 0 by default. a number in between 0 and 1 representing the decay rate of the grid sizes of the zoom. number of points to return, i.e. the smallest num points, 1 by default the minimum. a boolean indicating if the parallel computation is carried out, by default FALSE. The number of cores to use, i.e. at most how many child processes will be run simultaneously. For details, see mcmapply in parallel package. a boolean indicating if the information regarding the omputation is printed. Details The target function FUN to be minimized is a scalar real valued function with multiple arguments. The maximization can be achieved by multiplying -1 to the original function, and then input the new function to FUN. The grid must be created by using the function build_grid function in the package. Any other invariant arugments to the function FUN can be specified in MoreArgs by using a list with variable names. The common grid search first build a grid within some bounded area. And then the target function will be evaluated at each point in the grid. The points that produce the smallest num target function values shall be returned. zoom = 0 implies that no zoom-in will be applied and the corresponding grid search is the common one introduced above, while any integer zoom > 0 implies that the zoom-in will be applied in the grid search. When a grid search with a zoom is applied, zoom > 0 is actually the number of rounds or layers of the algorithm, and therefore the grid search algorithm with a zoom consists of grid searches, where n = num and z = zoom. n 0 + n 1 + n 2 +... + n z As mentioned above, in each grid search, num is the number of points that will be returned. And therefore, in the end, there will be points returned, where n = num and z = zoom. n 1 + n 2 + n 3 +... + n z+1 Each time when the algorithm zooms in, it will automatically build subgrids based on the points that have been found in the super gird search. Due to the exhaustive property of the grid search algorithm, it is desirable to make fewer points in the subgrid. The decay rate decay provides the opportunity to control the number of points in the subgrids. The number of points for each argument of the target function in the subgrid will be max [ Int (decay N), 3 ].

grid_search 5 Value Parallel computation is implemented in the function, which can be activated by setting parallel = TRUE. cores, which represents the number of cores, works only when parallel = TRUE. By default cores=null implies that the function will detect the number of cores and use it. The boolean silent controls if there will be output in the console. a list containing the results from the grid search with a zoom. The list contains the following components: par points the approximate global minimizer all the local minimizer points found by the grid search with a zoom Author(s) See Also Yukai Yang, <yukai.yang@statistik.uu.se> build_grid, grid_search_check Examples # Rastrigin function ndim = 2 # number of dimension na = 10 # parameter A # vx in [-5.12, 5.12] # minimizer = rep(0, ndim) # minimum = 0 Rastrigin <- function(vx) return(na * ndim + sum(vx*vx - na * cos(2*pi*vx))) # set seed and initialize the initial or starting value set.seed(1) par = runif(ndim, -5.12, 5.12) cat("start from", par) # results from different optimization algorithms optim(par = par, Rastrigin, method='nelder-mead') optim(par = par, Rastrigin, method='bfgs') optim(par = par, Rastrigin, method='l-bfgs-b') optim(par = par, Rastrigin, method='sann') # a toy example # build the grid first bin = c(from=-5.12, to=5.12, by=.5) grid = build_grid(bin,bin) # so this is a relatively sparse grid

6 grid_search_check # serial computation ret0 = grid_search(rastrigin, grid, silent=false) ret0$par # We can build a finer grid bin = c(from=-5.12, to=5.12, by=.1) grid = build_grid(bin,bin) # serial computation ret1 = grid_search(rastrigin, grid, silent=false) ret1$par # parallel computation ret2 = grid_search(rastrigin, grid, num=2, parallel=true, silent=false) ret2$par # grid search with a zoom! ret3 = grid_search(rastrigin, grid, zoom=2, num=2, parallel=true, silent=false) ret3$par grid_search_check Check the time consumed by running the grid search algorithm with a zoom. Description Usage This function checks the time consumed by running the grid search algorithm with a zoom as well as some other conditions. grid_search_check(fun, grid, MoreArgs = NULL, zoom = 0, decay = 0.5, num = 1, parallel = FALSE, cores = NULL, silent = TRUE) Arguments FUN grid MoreArgs zoom decay num the target function to be minimized. an object of the class GRID from build_grid. a list of other arguments to FUN, see mapply. number of (additional) rounds or layers of the zoom-in, 0 by default. a number in between 0 and 1 representing the decay rate of the grid sizes of the zoom. number of points to return, i.e. the smallest num points, 1 by default the minimum.

grid_search_check 7 parallel cores silent a boolean indicating if the parallel computation is carried out, by default FALSE. The number of cores to use, i.e. at most how many child processes will be run simultaneously. For details, see mcmapply in parallel package. a boolean indicating if the information regarding the computation is printed. Details Value The running of this function takes only several seconds. So it is recommended to run this function before grid_search to check the approximate time consumed by grid_search by using exactly the same arguments. This function is extremely useful when the user is going to run grid_search on some supercomputing server and need to know approximately how long time it will take in order to specify the corresponding settings according to some batch system like SLURM for example. The boolean silent controls if there will be output in the console. For details, see grid_search. a number of the time in seconds. Author(s) See Also Yukai Yang, <yukai.yang@statistik.uu.se> build_grid, grid_search Examples # Rastrigin function ndim = 2 # number of dimension na = 10 # parameter A # vx in [-5.12, 5.12] # minimizer = rep(0, ndim) # minimum = 0 Rastrigin <- function(vx) return(na * ndim + sum(vx*vx - na * cos(2*pi*vx))) # a toy example # build the grid first bin = c(from=-5.12, to=5.12, by=.5) grid = build_grid(bin,bin) # so this is a relatively sparse grid # serial computation ret0 = grid_search(rastrigin, grid, silent=false) ret0$par

8 zoomgrid # If we expand the grid to allow for more points bin = c(from=-5.12, to=5.12, by=.1) grid = build_grid(bin,bin) # run the check before the grid search ret1 = grid_search_check(rastrigin, grid, silent=false) ret1 = grid_search(rastrigin, grid, silent=false) zoomgrid zoomgrid: a package implementing the grid search algorithm with a zoom. Description Details The package implements the grid search algorithm with a zoom. The grid search aims to help solving difficult optimization problem where there are many local optimizers inside the domain of the target function or the parameter space of the log-likelihood function. It offers suitable initial or starting value for the following optimization procedure provided that the global optimum exists in the neighbourhood of the initial or starting value. And therefore the grid search does not do optimization. But if the grid is fine enough, the result approximates the optimizer. The grid search algorithm consists of two steps: firstly, it builds a grid with many points which discretize the domain of the target function; secondly, it evaluates the target function at these points in the grid and find the point which produces the smallest (minimization) or largest (maximization) function value. A fine grid is needed in order for a satisfactory result (initial or starting value of the following optimization, or an approximation of the optimizer). For cases with multiple (high-dimensional) arguments, the grid may contain too many points to evaluate the target function within a reasonably short time period. Thus, a grid search algorithm with a zoom is implemented as an option in the package. The grid search algorithm with a zoom does not require a very find grid, but a grid with a zoom-in mechanism. Based on the algorithm introduced above, the user of the package can choose to zoom in around the neighbourhoods the first n smallest (minimization) or largest (maximization) points obtained from the first round grid search. A much finer grid will be built in the neighbourhoods these points, and the grid search will continue. The grid search with a zoom stops after k rounds and gives a final result. The result is equivalent to that from a grid search based on (one round) a very fine grid, if the true global optimum is in the neighbourhoods of the n points from the first round grid search. By doing so, the grid search algorithm with a zoom saves time tremendously in cases with high-dimenstional arguments. Note that the user specifies n and k beforehand. Parallel computation, which requires the parallel package, is implemented and is an option in the package.

zoomgrid 9 Author and Maintainer Yukai Yang Department of Statistics, Uppsala University <yukai.yang@statistik.uu.se> References Yang, Yukai (2012, 1.5.4) "Modelling Nonlinear Vector Economic Time Series", PhD thesis, Aarhus University, Department of economics and business and CREATES. functions in the package build_grid build the grid for the following grid search algorithm. grid_search_check check the time consumed by running the grid search algorithm with a zoom. grid_search conduct the grid search algorithm with a zoom.

Index Topic algorithms build_grid, 2 grid_search, 3 grid_search_check, 6 build_grid, 2, 4 7, 9 grid_search, 3, 3, 7, 9 grid_search_check, 3, 5, 6, 9 mapply, 4, 6 zoomgrid, 8 zoomgrid-package (zoomgrid), 8 10