Package RCEIM. April 3, 2017

Similar documents
Package UPMASK. April 3, 2017

Package MeanShift. R topics documented: August 29, 2016

Package sbf. R topics documented: February 20, Type Package Title Smooth Backfitting Version Date Author A. Arcagni, L.

Package lhs. R topics documented: January 4, 2018

Package kofnga. November 24, 2015

Package OptimaRegion

Package clustering.sc.dp

Package seg. February 15, 2013

Package glinternet. June 15, 2018

Package areaplot. October 18, 2017

Package RankAggreg. May 15, 2018

Package SSLASSO. August 28, 2018

Package seg. September 8, 2013

Package RAMP. May 25, 2017

Package munfold. R topics documented: February 8, Type Package. Title Metric Unfolding. Version Date Author Martin Elff

Package Rearrangement

Package Grid2Polygons

Package nmslibr. April 14, 2018

Package smoother. April 16, 2015

Package crochet. January 8, 2018

Package beanplot. R topics documented: February 19, Type Package

Package curvhdr. April 16, 2017

Package sglr. February 20, 2015

Package RaPKod. February 5, 2018

Package optimization

Package xwf. July 12, 2018

Package hbm. February 20, 2015

Package hiernet. March 18, 2018

Package r.jive. R topics documented: April 12, Type Package

Package adaptivetau. October 25, 2016

Package hsiccca. February 20, 2015

Package smoothr. April 4, 2018

Package hextri. April 22, 2016

Package RMCriteria. April 13, 2018

Package ClustGeo. R topics documented: July 14, Type Package

Package Daim. February 15, 2013

Package rgcvpack. February 20, Index 6. Fitting Thin Plate Smoothing Spline. Fit thin plate splines of any order with user specified knots

Package DPBBM. September 29, 2016

Package HI. February 19, 2015

Package ebdbnet. February 15, 2013

Package GADAG. April 11, 2017

Package fso. February 19, 2015

1 2 (3 + x 3) x 2 = 1 3 (3 + x 1 2x 3 ) 1. 3 ( 1 x 2) (3 + x(0) 3 ) = 1 2 (3 + 0) = 3. 2 (3 + x(0) 1 2x (0) ( ) = 1 ( 1 x(0) 2 ) = 1 3 ) = 1 3

Package osrm. November 13, 2017

Package densityclust

Package bootlr. July 13, 2015

Package loe. February 9, 2016

Package intcensroc. May 2, 2018

Package parfossil. February 20, 2015

Package Rtsne. April 14, 2017

Package extweibquant

Package mhde. October 23, 2015

Package nprotreg. October 14, 2018

Package mlegp. April 15, 2018

Package activity. September 26, 2016

Package r2d2. February 20, 2015

Package gibbs.met. February 19, 2015

Package glcm. August 29, 2016

Package ECctmc. May 1, 2018

Package rmi. R topics documented: August 2, Title Mutual Information Estimators Version Author Isaac Michaud [cre, aut]

Package robustreg. R topics documented: April 27, Version Date Title Robust Regression Functions

Package asymmetry. February 1, 2018

Package flam. April 6, 2018

Package elmnnrcpp. July 21, 2018

Package MfUSampler. June 13, 2017

Package GauPro. September 11, 2017

Package detpack. R topics documented: December 14, Type Package

Package ExceedanceTools

Package RIFS. February 19, 2015

Package bacon. October 31, 2018

Package JBTools. R topics documented: June 2, 2015

Package ibm. August 29, 2016

Package PUlasso. April 7, 2018

Package cgh. R topics documented: February 19, 2015

Package mixphm. July 23, 2015

Package prettygraphs

Package texteffect. November 27, 2017

Package flsa. February 19, 2015

Package spark. July 21, 2017

Package kdtools. April 26, 2018

Package RobustGaSP. R topics documented: September 11, Type Package

Package sankey. R topics documented: October 22, 2017

Package anidom. July 25, 2017

Package cardidates. February 15, 2013

Package SCORPIUS. June 29, 2018

Package qboxplot. November 12, qboxplot... 1 qboxplot.stats Index 5. Quantile-Based Boxplots

Package clustvarsel. April 9, 2018

Package rhor. July 9, 2018

Package NetworkRiskMeasures

Package mrm. December 27, 2016

Package RStorm. R topics documented: February 19, Type Package

Graph tool instructions and R code

Package mmtsne. July 28, 2017

Package gains. September 12, 2017

Package pomdp. January 3, 2019

Package pvclust. October 23, 2015

Package SimilaR. June 21, 2018

Package sciplot. February 15, 2013

Package ipft. January 4, 2018

Continuous-time stochastic simulation of epidemics in R

Transcription:

Type Package Package RCEIM April 3, 2017 Title R Cross Entropy Inspired Method for Optimization Version 0.3 Date 2017-04-03 Author Alberto Krone-Martins Maintainer Alberto Krone-Martins <algol@sim.ul.pt> An implementation of a stochastic heuristic method for performing multidimensional function optimization. The method is inspired in the Cross- Entropy Method. It does not relies on derivatives, neither imposes particularly strong requirements into the function to be optimized. Additionally, it takes profit from multi-core processing to enable optimization of time-consuming functions. License GPL (>= 2) Suggests parallel NeedsCompilation no Repository CRAN Date/Publication 2017-04-03 20:19:16 UTC R topics documented: RCEIM-package...................................... 2 ceimopt........................................... 4 enforcedomainonparameters................................ 6 overploterrorpolygon.................................... 7 plotelitedistrib....................................... 8 sortdataframe........................................ 9 testfunoptimization.................................... 10 testfunoptimization2d................................... 11 Index 12 1

2 RCEIM-package RCEIM-package An R Cross Entropy Inspired Method for Optimization RCEIM Details RCEIM is a package implementing a stochastic heuristic method for performing multidimensional function optimization. The method is inspired in the Cross-Entropy Method. Package: RCEIM Type: Package Version: 0.3 Date: 2015-02-19 License: GPL (>= 2) RCEIM implements a simple stochastic heuristic method for optimization in the function ceimopt. This method starts from a random population of solutions, computes the values of the function and selects a fraction of these solutions - the elite members. Afterwards, based on the elite members it creates a gaussian distribution, samples new random solutions from it, and iterates until convergence is reached (this is controlled by an epsilon parameter) or other stopping criteria is fulfilled (such as the maximum number of iterations). One advantage of this method is that it does not impose strong conditions on the function to be optimized. The function must written as an R function, but it does not need to be continuous, differentiable, neither analytic. Moreover, the method is ready for multicore processing, enabling the optimization of time-consuming functions. -0.5 0.0 0.5 1.0 y -10-5 0 5 10-10 -5 0 5 10-10 -5 0 5 10 x x

RCEIM-package 3 Two examples of 1D and 2D functions that can be used as test problems for RCEIM (defined in testfunoptimization and testfunoptimization2d) are represented in the above figures. Alberto Krone-Martins, Laurent Gallucio Maintainer: Alberto Krone-Martins <algol@sim.ul.pt> See Also ceimopt # Solve a simple optimization problem and shows the results po <- ceimopt(optimfunction=function(x){(x[1]+1)^2+(x[2]+2)^2, maxiter=100, epsilon=0.3, nparams=2) plotelitedistrib(po$elitemembers) rm(po) # A harder problem in 1D po <- ceimopt(optimfunction="testfunoptimization", maxiter=10, epsilon=0.3, nparams=1, verbose=true) xx <- seq(-10,10,by=0.01) plot(xx, testfunoptimization(xx), type="l", xlab="x", ylab="") points(po$bestmember[1], po$bestmember[2], col="red") rm(list=c('xx','po')) # A harder problem in 2D po <- ceimopt(optimfunction="testfunoptimization2d", maxiter=20, epsilon=0.3, nparams=2, verbose=true) xx <- seq(-10,10,by=0.1) yy <- seq(-10,10,by=0.1) zz <- matrix(nrow=length(yy), ncol=length(xx)) for(i in 1:length(xx)){ for(j in 1:length(yy)){ zz[i,j] <- testfunoptimization2d( c(xx[i],yy[j]) ) image(xx,yy,zz, col=gray((50:100)/100), xlab="x", ylab="y") contour(xx,yy,zz, add=true) points(po$bestmember[1], po$bestmember[2], col="red", pch=19, cex=0.5) rm(list=c('xx','yy','zz')) # Example of multicore processing slowfunction <- function(x) { p<-runif(50000) return((x+3)^2) system.time(po <- ceimopt(optimfunction="slowfunction", maxiter=10,

4 ceimopt Ntot=100, epsilon=0.3, nparams=1, verbose=false, parallel=false)) print(po$bestmember) system.time(po <- ceimopt(optimfunction="slowfunction", maxiter=10, Ntot=100, epsilon=0.3, nparams=1, verbose=false, parallel=true)) print(po$bestmember) rm(po) ceimopt A Cross Entropy Inspired Method for Optimization This is a Cross-Entropy Inspired Method for optimization. ceimopt(optimfunction = "testfunoptimization", nparams = 1, minimize = TRUE, Ntot = 1000, N_elite = floor(ntot/4), N_super = 1, alpha = 1, epsilon = 0.1, q = 2, maxiter = 50, waitgen = maxiter, boundaries = t(matrix(rep(c(-10, 10), nparams), ncol = nparams)),plotconvergence = FALSE, chaosgen = maxiter, handiterative = FALSE, verbose = FALSE, plotresultdistribution = FALSE, parallelversion = FALSE) OptimFunction nparams minimize Ntot N_elite N_super alpha epsilon q maxiter waitgen A string with the name of the function that will be optimized. An integer with the number of parameters of the function that will be optimized. A boolean indicating if the OptimFunction should be minimized or maximized. An integer with the number of individuals per iteration. An integer with the number of elite individuals, or in other words, the individuals used to define the individuals of the new iteration. An integer with the number of super-individuals, or those individuals with the best fitness values, that are directly replicated to the next iteration. A parameter of the CE method used to control the convergence rate, and to prevent early convergence. A convergence control parameter: if the maximum st.dev. of the parameters of the elite individuals divided by its average value is smaller than this number, the method considers that it converged. A parameter of the CE method used to control the convergence rate, and to prevent early convergence. The maximum number of iterations that the method will run before stop. The number of iterations that the method will wait: after "waitgen" without any improvement in the best individual, the method gives up and return the best individual as an answer.

ceimopt 5 boundaries A matrix with as many rows as there are parameters and two columns the first column stores the minimum value, while the second, the maximum. plotconvergence A flag to indicate if the user wants to visually check the convergence of the method. chaosgen handiterative The number of iterations before the method replaces all the solutions, but the super-individuals, by a new random trial. A flag to indicate if the user wants to press enter between the each generation. verbose A flag to indicate if the user wants to receive some convergence and distribution information printed on the screen. plotresultdistribution A flag to indicate if the user wants to see the resulting distribution of elite members (black curve), the value of the fittest member (red line) and of the average member (blue line), for each parameter. parallelversion A flag to indicate if the user wants to use all the cores in his/her computer to compute the fitness functions. Details This is a simple stochastic heuristic method for optimization. It starts from a random population of points, computes the values of the function and selects a fraction of the points - the elite members. Then, based on these fittest points, it constructs a gaussian distribution, samples new random points from it, and iterates until convergence is reached (this is controlled by the epsilon parameter) or other stopping criteria is fulfilled (such as the maximum number of iterations). The method does not impose strong conditions on the function to be optimized. The function must written as an R function, but it does not need to be neither continuous, differentiable or analytic. Moreover, the method is ready for multicore processing, enabling the optimization of time-consuming functions. A list that contains: BestMember Convergence Criteria Iterations EliteMembers The parameters and the fitness value of the best member. A boolean indicating if the method reached convergence. Stopping criterion. The amount of iterations. The parameters and fitness values of the elite members at the last iteration. Alberto Krone-Martins

6 enforcedomainonparameters # Solve a simple optimization problem and shows the results po <- ceimopt(optimfunction=function(x){(x[1]+1)^2+(x[2]+2)^2, maxiter=100, epsilon=0.3, nparams=2) plotelitedistrib(po$elitemembers) rm(po) # A harder problem in 1D po <- ceimopt(optimfunction="testfunoptimization", maxiter=10, epsilon=0.3, nparams=1, verbose=true) xx <- seq(-10,10,by=0.01) plot(xx, testfunoptimization(xx), type="l", xlab="x", ylab="") points(po$bestmember[1], po$bestmember[2], col="red") rm(list=c('xx','po')) # A harder problem in 2D po <- ceimopt(optimfunction="testfunoptimization2d", maxiter=20, epsilon=0.3, nparams=2, verbose=true) xx <- seq(-10,10,by=0.1) yy <- seq(-10,10,by=0.1) zz <- matrix(nrow=length(yy), ncol=length(xx)) for(i in 1:length(xx)){ for(j in 1:length(yy)){ zz[i,j] <- testfunoptimization2d( c(xx[i],yy[j]) ) image(xx,yy,zz, col=gray((50:100)/100), xlab="x", ylab="y") contour(xx,yy,zz, add=true) points(po$bestmember[1], po$bestmember[2], col="red", pch=19, cex=0.5) rm(list=c('xx','yy','zz')) # Example of multicore processing slowfunction <- function(x) { p<-runif(50000) return((x+3)^2) system.time(po <- ceimopt(optimfunction="slowfunction", maxiter=10, Ntot=100, epsilon=0.3, nparams=1, verbose=false, parallel=false)) print(po$bestmember) system.time(po <- ceimopt(optimfunction="slowfunction", maxiter=10, Ntot=100, epsilon=0.3, nparams=1, verbose=false, parallel=true)) print(po$bestmember) rm(po) enforcedomainonparameters Enforce domain boundaries

overploterrorpolygon 7 A small function to assure that the domains are respected during the optimization process. If any of them not respected, the ofending parameters are replaced by the value of the nearest border. enforcedomainonparameters(paramsarray, domain) paramsarray domain The array with the parameters to check. The domain boudaries. The parameter array, with ofending values replaced if necessary. Alberto Krone-Martins # Creates a random set of parameters in an interval larger than a certain domain # and apply the enforcedomainonparameters function and represent graphically # the parameters before and after the function. paramarr <- matrix((runif(100)-0.5)/0.5*13, nrow=50) domain <- matrix(c(-10, -10, 10, 10), ncol=2) newparamarr <- enforcedomainonparameters(paramarr, domain) plot(paramarr[,1], paramarr[,2], xlab="x", ylab="y", main="black: input\n red: output") points(newparamarr[,1], newparamarr[,2], col="red", pch=19, cex=0.7) overploterrorpolygon Overplot an error polygon A simple function to overplot an error polygon around a curve. Note that the error is considered as symmetric, and exclusively on y. The polygon will be created from the coordinate tuples (x, (y err y )) and (x, (y + err y )). overploterrorpolygon(x, y, err_y, col = "grey", logplot = FALSE,...)

8 plotelitedistrib x y A vector containing the x coordinate of the data. A vector containing the y coordinate of the data. err_y A vector containing the error in y. col logplot The color that will be used for filling the polygon. A boolean indicating if the plot is in logscale.... Further arguments to be passed to polygon(). A polygon is overplotted in the active graphics device. Alberto Krone-Martins # Shows a simple random curve and overplots a randomly created error bar. xx <- 1:10 yy <- (1:10)/5 + 4 + (runif(10)-0.5)/0.5*2 plot(xx, yy, type="l", xlab="x", ylab="y", ylim=c(0,10)) err_yy <- 1.5 + (runif(10)-0.5)/0.5 overploterrorpolygon(xx,yy,err_yy, col=rgb(0,0,1,0.3), border=na) plotelitedistrib Plot the distribution of elite members A simple function to create distribution plots of the elite members after the optimization procedure. The distribution is graphically represented using a kernel density estimation. Aditionally, this function also indicates the best and average members. plotelitedistrib(elite) elite A matrix containing parameters of the elite members. A graphic representation of the elite members and also of the best and average members.

sortdataframe 9 Alberto Krone-Martins See Also ceimopt # Solve a simple 2D problem and show the distribution of the parameters po <- ceimopt(optimfunction=function(x){(x[1]+1)^2+(x[2]+2)^2, maxiter=100, epsilon=0.1, nparams=2) plotelitedistrib(po$elitemembers) rm(po) sortdataframe Sorting a data frame by a key A simple function to sort a data frame based on a certain keyword. This function was posted by r-fanatic at a dzone forum (the webpage is not available anymore). sortdataframe(x, key,...) x The data frame to be sorted. key The key by which the data frame will be sorted.... Further arguments to be passed to the order function. The sorted data frame. r-fanatic References The original webpage where r-fanatic posted the code is not available as of 3rd April 2017.

10 testfunoptimization # Create a simple data frame and order using the "B" key ppp <- data.frame(a=1:10,b=10:1) ppp sortdataframe(ppp,"b") ppp testfunoptimization 1D test problem for RCEIM An one-dimension problem for testing optimization methods. This function was created for demonstrating the RCEIM package. It has the form: f(x) = exp( ((x 2) 2 )) + 0.9 exp( ((x + 2) 2 )) + 0.5 sin(8 x) + 0.25 cos(2 x) testfunoptimization(x) x The point where the function is computed. The value of the function at x. Alberto Krone-Martins See Also testfunoptimization2d # Create a graphical representation of the problem with a line plot xx <- seq(-10,10,by=0.01) plot(xx, testfunoptimization(xx), type="l", xlab="x", ylab="") rm(list=c('xx'))

testfunoptimization2d 11 testfunoptimization2d 2D test problem for RCEIM A two-dimensional problem for testing optimization methods. This function was created for demonstrating the RCEIM package. It has the form: f(x 1, x 2 ) = (x 1 4) 2 + (x 2 + 2) 2 50 (x 1 + 2) 2 + (x 2 + 4) 2 90 exp( (x 1 2) 2 ) 0.9 exp( (x 2 + 2) 2 ) 0.5 sin(8 x 1 ) 0.25 cos(2 x 2 ) testfunoptimization2d(x) +0.25 sin( x 1 x 2 ) + 0.5 cos( x 2 x 1 2 2.5 ) x a vector with the point where the function is computed. The value of the function at the requested point (x_1, x_2). See Also Alberto Krone-Martins testfunoptimization # Create a graphical representation of the problem with a contour plot xx <- seq(-10,10,by=0.1) yy <- seq(-10,10,by=0.1) zz <- matrix(nrow=length(yy), ncol=length(xx)) for(i in 1:length(xx)){ for(j in 1:length(yy)){ zz[i,j] <- testfunoptimization2d( c(xx[i],yy[j]) ) image(xx,yy,zz, col=gray((50:100)/100), xlab="x", ylab="y") contour(xx,yy,zz, add=true) rm(list=c('xx','yy','zz'))

Index Topic aplot overploterrorpolygon, 7 Topic design testfunoptimization, 10 testfunoptimization2d, 11 Topic methods sortdataframe, 9 Topic misc enforcedomainonparameters, 6 plotelitedistrib, 8 sortdataframe, 9 testfunoptimization, 10 testfunoptimization2d, 11 Topic optimize ceimopt, 4 RCEIM-package, 2 Topic package RCEIM-package, 2 ceimopt, 2, 3, 4, 9 enforcedomainonparameters, 6 overploterrorpolygon, 7 plotelitedistrib, 8 RCEIM (RCEIM-package), 2 RCEIM-package, 2 sortdataframe, 9 testfunoptimization, 3, 10, 11 testfunoptimization2d, 3, 10, 11 12