BayesOpt
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Groups Pages
Installing BayesOpt

Table of Contents

The core of BayesOpt uses standard C/C++ code (C++98) so it can be compiled from many C++ compilers (gcc, clang, MSVC...). The library also include wrappers for Python, Matlab and Octave interfaces which requires extra dependencies or compilation steps. Note that the Python or Matlab/Octave interfaces are not included by default.

Installing in Linux/MacOS:

The compilation is very similar in any *nix system. Following these instructions, the library will be compiled using the default configuration. You can modify that easily as explained in Configure the compilation/install

Getting dependencies:

The easiest way to compile this library is using the cross platform and cross compiler tool CMake.

This code uses Boost libraries for matrix operations (uBlas), random number generation, math functions and smart pointers. Being only include files, Boost does not require any speciall install. Boost can be found in many Linux and MacOS repositories. It can also be downloaded from http://www.boost.org.

Both Python development files (Python.h) and Numpy are needed if you want the Python interface. The library has been tested with Python 2.6 and 2.7. The interface relies on Numpy arrays.

Finally, if you want the Matlab interface, just make sure your C++ compiler is compatible with your Matlab version.

Linux:

For Ubuntu/Debian, the minimum dependencies (C/C++) can be optained by running:

>> sudo apt-get install libboost-dev cmake cmake-curses-gui g++

If you want the Python interface:

>> sudo apt-get install python-dev python-numpy

If you want the Octave interface (note that the octave package does not include all the necessary files):

>> sudo apt-get install octave-headers

And for all dependencies:

>> sudo apt-get install libboost-dev python-dev python-numpy cmake cmake-curses-gui g++ cython octave-headers

MacOS:

This section assumes macports is installed. Similar packages can be found in fink or homebrew. For the minimal install, run:

>> sudo port install boost gcc47 cmake

If you want the Python interface:

>> sudo port install python27 py27-numpy

If you want the Octave interface:

>> sudo port install octave

Again, for all dependencies:

>> sudo port install boost python27 py27-numpy gcc47 cmake py27-cython octave

Compile the library:

In order to compile the source code in a *nix system, run this from a terminal.

>> cmake . 
>> make
>> sudo make install

Important: If you use ccmake instead of cmake you will access a graphical interface to select features such as the include the Python and Matlab interfaces, debug/release mode or if you want to use shared libraries or not. More details about how to configure it can be found in Configure the compilation/install

Building the documentation

If you have doxygen installed on your computer, you can compile the documentation right after compiling the code by running.

>> make doc

Thid documentation will appear in the "doc" subdirectory.

Python interface:

Both Python development files (Python.h) and Numpy are needed if you want the python interface. The library has been tested with Python 2.6 and 2.7. The interface relies on Numpy arrays. If we want to select the option to compile the Python interface we can just run:

>> cmake -DBAYESOPT_PYTHON_INTERFACE=ON . 

or

>> ccmake . 

and select the corresponding option.

Important: Python requires a special module with shared access and nonstandard name. Thus, it will build a separate module called "bayesopt.so". This module can be accessible from Python provided that it is in the PYTHONPATH or sys.path. It cannot be linked to any executable or other libraries. Use libbayesopt.* instead.

MATLAB/Octave interface:

Make sure the library is compiled with the MATLAB_COMPATIBLE option using ccmake. Undex Mac OS they must be shared. Also, configure Matlab/Octave to compile mex files. For example, in Matlab you can run to check the supported compilers:

>> mex -setup

Run the corresponding script compile_matlab.m or compile_octave.m, which can be found in the /matlab/ directory.

If bayesopt or nlopt are compiled as shared libraries, then, at run time, MATLAB/Octave also needs to access to the libraries. For example, LD_LIBRARY_PATH must include the folder where the libraries are. If the install path is the default, you can execute the exportlocalpath.sh script before calling MATLAB.

Issues on libstdc++ linking:


Windows and other systems:

Install this components:

CMake for Windows provides a nice GUI where you can select your favorite C++ compiler (MinGW, Visual Studio, etc.). It will automatically create the necesary configuration files for the compiler (makefile, solution, etc.).

Since Boost they are pure template libraries, they do not require compilation. Just make sure the headers are on the include path. You can also add an entry named BOOST_ROOT in CMake with the corresponding path to the library.

If you do not have a C++ compiler, we recomend MinGW+MSYS. Then, you just need to compile from the command line with:

>> mingw32-make

The most important options/variables are explained in Configure the compilation/install.

MATLAB/Octave interface:

Make sure the library is compiled with the MATLAB_COMPATIBLE option and configure Matlab/Octave to compile mex files. For example, in Matlab you can run to check the supported compilers:

>> mex -setup

Run the corresponding script compile_matlab.m or compile_octave.m, which can be found in the /matlab/ directory.

If bayesopt or nlopt are compiled as shared libraries, then, at run time, MATLAB/Octave also needs to access to the libraries. You can modify the PATH variable or copy the dll files in the same bolder as the generated mexfile.

Important: It is strongly recommended to compile bayesopt with exactly the same compiler that was select for mex files. For a list of the supported compilers for your Matlab version, you can check the online docs at mathworks.

MATLAB and MinGW

Unfortunately, MinGW has never been suported by Matlab. Thus I have also included a Makefile to generate the mex files outside Matlab. You might need to change the MATLABROOT path with the root folder of your Matlab install and copy the dlls. Then, run mingw32-make. Note that mingw32-make only supports 32 bits libraries, so you need a 32 bit version of Matlab. There is a fork of MinGW with 64 bit support under development, but it has not been tested here.

Python interface:

The Python interface has not been tested in Windows because getting the correct dependencies is highly involved. You might need to download and install:

Also, read this article about how to link everything: http://docs.python.org/2/extending/windows.html#building-on-windows


Configure the compilation/install

CMake allows to configure the compilation using some variables (see for example how to compile the Python module in Linux). These variables can be set in Linux/MacOS from the command line with the -D flag:

>> cmake -DVARIABLE=VALUE .

For example

>> cmake -DCMAKE_BUILD_TYPE=Debug .

If you use ccmake in Linux/MacOS or CMake for Windows, you can access to a list of all the variables and their values. Just modify the value of the desired variable.

Compile as shared libraries

We can select if we want BayesOpt and NLOPT compiled as shared libraries

BAYESOPT_BUILD_SHARED=ON 
NLOPT_BUILD_SHARED=ON

In this case, we also need to force rebuild NLOPT (by default it is not compiled if it is found in the system).

Install the library in a different path

CMake allows to select the install path before compilation compilation. You just need to change the CMAKE_INSTALL_PREFIX variable.

CMAKE_INSTALL_PREFIX=/your/desired/path

Minimal installation (fast compilation)

Sobol sequences can be used to for the initial design (see Initialization parameters). In many cases, the performance is similar to latin hypercube sampling, however including the Sobol components increases considerably the library size and the compilation time. Thus, it can be removed from compilation:

BAYESOPT_BUILD_SOBOL=OFF

Similarly, we can avoid to compile the example files and demos:

BAYESOPT_BUILD_EXAMPLES=OFF