-
Notifications
You must be signed in to change notification settings - Fork 78
using CMA ES in CERN's ROOT
This is support for black-box optimization with CMA-ES from within ROOT (http://root.cern.ch/drupal/).
**This is a work in progress, support for ROOT is under continuous improvement, see https://github.com/beniz/libcmaes/issues/13 **
libcmaes can be used from CERN's ROOT6 as a replacement or addition to Minuit2 optimizer. It is designed to be used from ROOT6 exactly as Minuit2 is used, so code using Minuit2 should be easily run against CMA-ES.
Note: at this early stage, not all features of Minuit2, such as subroutines Contour and Scan, are ported to CMA-ES. This is a work in progress.
Below are instructions for testing it out.
Beware: at the moment support is alpha, this is NO production code
As for now, the only way to use libcmaes is from ROOT6, using the following special repository, and compiling it from sources (1): https://github.com/beniz/root/tree/cmaes4root_master
Proceed with the following steps:
- get and install libcmaes into your home repository (or globally on your system, remove the --prefix option to the configure script below):
git clone https://github.com/beniz/libcmaes.git
cd libcmaes
git checkout dev
./autogen.sh
./configure --prefix=/home/yourusername
make
make install
- get ROOT6 from https://github.com/beniz/root/tree/cmaes4root_master, configure & compile it (this will take a while) (2):
git clone https://github.com/beniz/root.git cmaes4root
cd cmaes4root
git checkout cmaes4root_master
cd root
```
#### Build with autoconf (configure) ####
```
./configure --enable-minuit2 --enable-roofit --enable-python --with-cmaes-incdir=/home/yourusername/include/libcmaes --with-cmaes-libdir=/home/yourusername/lib
make
use make -jx where x is the number of cores on your system in order to minimize the building time.
export PKG_CONFIG_PATH=/home/yourusername/lib/pkgconfig
mkdir mybuild
cd mybuild
cmake ..
make
use make -jx where x is the number of cores on your system in order to minimize the building time.
To run the basic fitting of a Gaussian, originally taken from Minuit2's tutorial files, do:
root
.L tutorials/fit/cmaesGausFit.C++g
cmaesGausFit()
You should see a plot similar to
To quick test competitiveness against Minuit2:
root
.L tutorials/fit/cmaesFitBench.C
cmaesFitBench()
You should witness a plot similar to
To run the current benchmark and visualize results, take the following steps:
root
.L tutorials/fit/cmaesFullBench.C
run_experiments(10)
python math/cmaes/test/cmaesFullBench.py
This should show a series of histograms comparing results from both optimizers on a selection of problems.
There's built-in control for several hyper-parameters and options of CMA-ES:
- several flavors of the algorithm are available, and can be choosen at creation of the Minimizer object:
TVirtualFitter::SetDefaultFitter(``acmaes'');
or
ROOT::Fit::Fitter fitter;
fitter.Config().SetMinimizer(``cmaes'',''acmaes'');
The available algorithms are: cmaes, ipop, bipop, acmaes, aipop, abipop, sepcmaes, sepipop, sepbipop
.
'acmaes' should be the most appropriate in most cases, and 'sepacmaes' when the number of dimensions nears a thousand.
The options below are not required, but can be used by filling up a MinimizerOptions object beforehand:
const char *fitter = "acmaes"
TVirtualFitter::SetDefaultFitter(fitter);
ROOT::Math::IOptions &opts = ROOT::Math::MinimizerOptions::Default(fitter);
opts.SetIntValue("lambda",100);
Options below are not activated by default:
- 'sigma': initial step-size
- 'lambda': number of offsprings at each generation
- 'noisy': flag that updates some hyper-parameters if the objective function is noisy
- 'restarts': maximum number of restarts, only applies to ipop, bipop, aipop, abipop, sepipop and sepbipop
- 'ftarget': the objective function target that stops optimization when reached, useful when the final value is known, e.g. 0
- 'fplot': output file in libcmaes format for later plotting of eigenvalues and state convergence, mostly for debug purposes
- 'lscaling': automatic linear scaling of parameters with auto-selection of step-size sigma, usually recommended if results are not satisfactory
- 'mt_feval': allows for parallel calls of the objective function, faster but the objective function is required to be thread-safe.
libcmaes support within ROOT extends to RooFit without effort.
From Roofit, it is enough to set the Minimizer with
and from PyROOT for example
RooFit.Minimizer("cmaes","acmaes")
For setting CMA-ES custom options, such as 'sigma', 'lambda' or 'lscaling', it is enough to set the options as explained in the non RooFit case:
ROOT::Math::IOptions &opts = ROOT::Math::MinimizerOptions::Default(fitter);
opts.SetIntValue("lambda",100);
and from PyRoot
opt = ROOT.Math.MinimizerOptions.Default("cmaes")
opt.SetIntValue("lambda",100)
(1) more convenient ways will be provided. (2) we recommend building support for both Minuit2 (i.e. for comparison to CMA-ES) and debug.