Skip to content

Using Surrogates for expensive objective functions

beniz edited this page Nov 17, 2014 · 8 revisions

A surrogate is a replacement model of the true original objective function. This surrogate can be learnt by using a machine learning algorithm from a reduced number of points collected from calls to the true objective function.

Surrogates are mostly useful when calling the true objective function is expensive. They provide a way to optimize the function while drastically reducing the overall number of calls.

Libcmaes supports surrogates and provide an easy way of setting them up. In libcmaes, the use of a surrogate requires two pieces:

  • a strategy, that defines how and when to train the surrogate model, and when to exploit it. Libcmaes provides a few well-tested strategies from the literature. Experienced users can easily craft custom ones;

  • a machine learning algorithm, and libcmaes provides a ranking SVM implementation. Other machine algorithms can be plugged to the framework without much difficulties.

This means that for non-expert users, it is rather straightforward to use surrogate in order to optimize expensive objective functions.

Quick start

Compile the libcmaes normally.

There's a ready to use / copy implementation of an effective surrogate strategy with ranking SVM available from the lib:

./examples/sample_code_surrogate_rsvm --help

The source code is in examples/surrogates/sample-code-surrogate-rsvm.cc. The code derives the ACMSurrogateStrategy class and binds it to the ranking SVM implementation from rankingsvm.hpp

You can first try to reproduce the results below:

  • Fsphere no exploitation fsphere_surr_noexploit To reproduce:
./examples/sample_code_surrogate_rsvm -fname fsphere -ftarget 1e-10 -sigma0 0.5 -x0 2 -dim 10 -fplot surr.dat --no_exploit
python tests/cma_multiplt_surr.py surr.dat
  • Fsphere with surrogate exploitation fsphere_surr To reproduce:
./examples/sample_code_surrogate_rsvm -fname fsphere -ftarget 1e-10 -sigma0 0.5 -x0 2 -dim 10 -fplot surr.dat
python tests/cma_multiplt_surr.py surr.dat
  • Rosenbrock no exploitation rosenbrock_surr_noexploit To reproduce:
./examples/sample_code_surrogate_rsvm -fname rosenbrock -ftarget 1e-10 -sigma0 0.5 -x0 2 -dim 10 -fplot surr.dat --no_exploit
python tests/cma_multiplt_surr.py surr.dat
  • Rosenbrock with surrogate exploitation rosenbrock_surr

To reproduce:

./examples/sample_code_surrogate_rsvm -fname rosenbrock -ftarget 1e-10 -sigma0 0.5 -x0 2 -dim 10 -fplot surr.dat
python tests/cma_multiplt_surr.py surr.dat
  • Elli no exploitation elli_surr_noexploit To reproduce:
./examples/sample_code_surrogate_rsvm -fname elli -ftarget 1e-10 -sigma0 2 -x0 2 -dim 10 -fplot surr.dat --no_exploit
python tests/cma_multiplt_surr.py surr.dat
  • Elli with surrogate exploitation elli_surr To reproduce:
./examples/sample_code_surrogate_rsvm -fname elli -ftarget 1e-10 -sigma0 0.5 -x0 2 -dim 10 -fplot surr.dat
python tests/cma_multiplt_surr.py surr.dat

The next step is to replace the existing test functions with your own objective function and to first test how well the surrogate will be for this function. To do this, first run in test mode, i.e. with no exploitation of the model:

/examples/sample_code_surrogate_rsvm --no_exploit

or with the API:

optim.set_exploit(true)

This test mode trains the surrogate at every step of the optimization algorithm and reports on its error on each new set of points obtained from the true objective function. If your objective function is very expensive, you may just let it run for a few steps and / or test how well the ranking SVM does by sampling points from within your full function domain and running SVM on it. For applying the later, see the examples/surrogates/test-rsvm.cc file.

Using an external / custom machine learning algorithm

Using an external machine learning algorithm as surrogate requires a high-level understanding of the strategy framework within libcmaes.

A surrogate strategy derives from an optimization strategy, and add two new functions to it: train() and predict().

To use any machine learning algorithm as surrogate requires deriving one of the surrogate strategies, and filling up both train() and predict() functions.

Defining new strategies for surrogate training & exploitation

New strategies can be implemented by deriving one of the existing surrogate strategies. See src/surrogatestrategy.h and src/surrogatestrategy.cc for working examples.