# First release of mlrMBO – the toolbox for (Bayesian) Black-Box Optimization

**mlr-org**, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)

Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

We are happy to finally announce the first release of **mlrMBO** on cran after a quite long development time.

For the theoretical background and a nearly complete overview of mlrMBOs capabilities you can check our paper on **mlrMBO** that we presubmitted to arxiv.

The key features of **mlrMBO** are:

- Global optimization of expensive Black-Box functions.
- Mulit-Criteria Optimization.
- Parallelization through multi-point proposals.
- Support for optimization over categorical variables using random forests as a surrogate.

For examples covering different scenarios we have Vignettes that are also available as an online documentation.

For **mlr** users **mlrMBO** is especially interesting for hyperparameter optimization.

**mlrMBO** for **mlr** hyperparameter tuning was already used in an earlier blog post.

Nonetheless we want to provide a small toy example to demonstrate the work flow of **mlrMBO** in this post.

### Example

First, we define an objective function that we are going to minimize:

To define the objective function we use `makeSingleObjectiveFunction`

from the neat package **smoof**, which gives us the benefit amongst others to be able to directly visualize the function.

*If you happen to be in need of functions to optimize and benchmark your optimization algorithm I recommend you to have a look at the package!*

Let’s start with the configuration of the optimization:

The optimization has to so start with an initial design.

**mlrMBO** can automatically create one but here we are going to use a randomly sampled LHS design of our own:

The points demonstrate how the initial design already covers the search space but is missing the area of the global minimum.

Before we can start the Bayesian optimization we have to set the surrogate learner to *Kriging*.

Therefore we use an *mlr* regression learner.

In fact, with *mlrMBO* you can use any regression learner integrated in *mlr* as a surrogate allowing for many special optimization applications.

*Note:* **mlrMBO** can automatically determine a good surrogate learner based on the search space defined for the objective function.

For a purely numeric domain it would have chosen *Kriging* as well with some slight modifications to make it a bit more stable against numerical problems that can occur during optimization.

Finally, we can start the optimization run:

We can see that we have found the global optimum of $y = -0.414964$ at $x = (-1.35265,0)$ quite sufficiently.

Let’s have a look at the points mlrMBO evaluated.

Therefore we can use the `OptPath`

which stores all information about all evaluations during the optimization run:

It is interesting to see, that for this run the algorithm first went to the local minimum on the top right in the 6th and 7th iteration but later, thanks to the explorative character of the *Expected Improvement*, found the real global minimum.

### Comparison

That is all good, but how do other optimization strategies perform?

#### Grid Search

Grid search is seldom a good idea.

But especially for hyperparameter tuning it is still used.

Probably because it kind of gives you the feeling that you know what is going on and have not left out any important area of the search space.

In reality the grid is usually so sparse that it leaves important areas untouched as you can see in this example:

It is no surprise, that the grid search could not cover the search space well enough and we only reach a bad result.

#### What about a simple random search?

With the random search you could always be lucky but in average the optimum is not reached if smarter optimization strategies work well.

#### A fair comarison

… for stochastic optimization algorithms can only be achieved by repeating the runs.

**mlrMBO** is stochastic as the initial design is generated randomly and the fit of the Kriging surrogate is also not deterministic.

Furthermore we should include other optimization strategies like a genetic algorithm and direct competitors like `rBayesOpt`

.

An extensive benchmark is available in our **mlrMBO** paper.

The examples here are just meant to demonstrate the package.

### Engage

If you want to contribute to **mlrMBO** we ware always open to suggestions and pull requests on github.

You are also invited to fork the repository and build and extend your own optimizer based on our toolbox.

**leave a comment**for the author, please follow the link and comment on their blog:

**mlr-org**.

R-bloggers.com offers

**daily e-mail updates**about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.

Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.