Skip to content
Siddhant Raghuvanshi edited this page Apr 10, 2022 · 3 revisions

StochOptim - an R wrapper for stochastic and global optimization tools

Background

R has a number of tools for what is termed optimization. This is the process of finding the minimum (or maximum) of a function of a vector parameters, b, and exogenous data, Y, by varying the values of the elements of b to attain the least (or greatest) value of the function. There may be other conditions, or constraints imposed. Note that we can maximize a function by minimizing (-1) times that function, and we will generally minimize.

Many of the R optimization tools, either in the base distribution or in packages, particularly those in the official CRAN (https://cran.r-project.org) or other collections, are for functions that have just one optimum in a region. Other tools try to find the best of several multiple minima or the global minimum. Most of these tools use stochastic methods.

Many programmers have contributed over better than half a century to the development of optimization tools. This has led to a wide variety of ways in which the tools are invoked. In R, a wide variety of calling sequences exist for the different methods. This is burdensome for users. If they have prepared a function to minimize, they must learn and code a different call for each method.

To ease this burden, wrapper programs can be prepared that are invoked by a standard syntax within which a single argument (possibly augmented by some control parameters) selects one of a set of optimization solvers. This is the case for the package optimx for a number of optimization solvers that deal with finding a local minimum, possibly subject to lower and upper bounds on the objective function parameters. Moreover, there is the facility to use the "opm()" function to try several solvers in a single call and generate a comparison table of results.

For stochastic/global optimization solvers, there is no such wrapper as yet. The creation of such a wrapper is the goal of this proposal.

Related work

The optimx package gives an example of a wrapper that is closest to the goal of the current proposal, but which is intended for finding local minima of functions, possibly with bounds constraints..

The Global and Stochastic Optimization section of the CRAN Task View: Optimization and Mathematical Programming presents a compendium of possible methods for this project.

Mullen, K. M. (2014). Continuous Global Optimization in R. Journal of Statistical Software, 60(6), 1–45.

There is also the R Optimization Infrastructure (ROI), but this uses a rather different approach and is less a wrapper than a set of interfaces.

Details of your coding project

This project will attempt to provide a common calling structure for a number of stochastic optimization tools already available for R.

We believe that the output of this project would be an R package similar in structure to optimx. That is, besides obeying R general package requirements, it should have tools to

  • execute one of a set of stochastic optimizers using a standard syntax, given an appropriate character string "method" that specifies the particular solver; in optimx the function optimr() closely follows the syntax of the base R funtion optim() in this regard

  • execute a set of methods in a vector of character strings in "method" and return a data frame with the results. The opm() function of optimx serves this purpose, and returns a table of results that can include some post-solution tests of the solutions, such as the Kuhn-Karush-Tucker optimality conditions.

Furthermore, the project should generate documentation to guide the addition of other solvers to the set covered by the StochOptim package. In particular, in the development of optimx, a table of the comparable options and controls for each solver was very useful in deciding common identifiers for these and suitable (and comparable) defaults to be passed to the solvers from the wrapper. For example, there is often a limit placed on the number of times the objective function may be evaluated before a method is terminated. optimx uses maxfeval as the identifier for this limit, but individual solvers use other names, or sometimes none at all, thereby complicating the comparison of results unless special steps are taken to capture this quantity.

It is hoped to begin work on a table of controls and options before this project commences, as the mentors believe this aspect of the work can be a source of much wasted time.

Expected impact

optimx has proved helpful in allowing developers of other packages to offer multiple solvers with their programs with minimal extra effort. We believe a wrapper for stochastic optimizers will be at least as helpful.

It is also likely that a wrapper will permit better comparison, understanding, and benchmarking of stochastic optimization tools in R.

No tool of this type exists at the moment to our knowledge.

Mentors

John C. Nash, [email protected]

Paulo Cortez, [email protected]

Hans Werner Borchers, [email protected]

Tests

Contributors, please contact mentors after completing at least some of the tests below.

All tests should be answered in an Rmarkdown file (part of the test is to see that you can do this). All program code should be in R. Comments may be in point form (i.e., bullets).

1. Coding functions

Prepare R code for three of the unconstrained test functions in GO Test Problems that allow dimension greater than 4

Rated: Easy

2. optim()

Try to minimize these with the base R optim() function. Be sure to document what you do.

Rated: Easy

3. optimx

Check that your code from part 2 will run with the optimr() wrapper. Then run several (at least 4) solvers at once with the opm() function. Justify your choice of solvers for each of the problems. Comment briefly on the output.

Rated: Moderate

4. Stochastic solvers

Choose at least three stochastic optimization solvers from the suggestions in Global and Stochastic Optimization section of the CRAN Task View: Optimization and Mathematical Programming and apply these to your test problems. Comment briefly on why you chose particular solvers, on any issues in setting up your calculations and on the output observed.

Rated: Moderate

5. Volcano function

Prepare R code for the volcano function of two parameters b=c(x,y) that is defined as

f(d) = (10 - 0.5*d) + sin(2*d) where d is the square norm distance from x=1, y=5.

What are the likely issues in minimizing this function over the two dimensions? A [3D] perspective plot may help you. Do solvers have trouble getting sensible results for this function?

Rated: Moderate

Solutions of tests

Contributors, please post a link to your test results here.

EXAMPLE CONTRIBUTOR 1 NAME, LINK TO GITHUB PROFILE, LINK TO TEST RESULTS.

EXAMPLE CONTRIBUTOR 2 NAME, LINK TO GITHUB PROFILE, LINK TO TEST RESULTS.

|1| Prahas Ranjan,[Github],[Link to Test Results].

|2| Siddhant Raghuvanshi, [Github], [Link to Test Results].

Useful links

R GSOC FAQ https://github.com/rstats-gsoc/gsoc2022/wiki/R-GSOC-FAQ