Commit e7d9c956 authored by Jean-Baptiste Mouret's avatar Jean-Baptiste Mouret
Browse files

add tolerance as a stopping criterion for nlopt optimizers

parent 05031d5d
......@@ -24,6 +24,10 @@ Optional but highly recommended
./configure --with-cxx --enable-shared --without-python --without-matlab --without-octave
sudo make install
.. caution::
The Debian/Unbuntu NLOpt package does NOT come with C++ bindings. Therefore you need to compile NLOpt yourself. The brew package (OSX) comes with C++ bindings (`brew install homebrew/science/nlop`).
* `libcmaes <https://github.com/beniz/libcmaes>`_. Make sure that you install with **sudo** or configure the **LD_LIBRARY_PATH** accordingly. Be careful that gtest (which is a dependency of libcmaes) needs to be manually compiled **even if you install it with your package manager** (e.g. apt-get). Follow the instructions `here <https://github.com/beniz/libcmaes#build>`_, reproduced for your convenience::
sudo apt-get install libgtest-dev
......
......@@ -55,8 +55,8 @@
#include <nlopt.hpp>
#include <limbo/tools/macros.hpp>
#include <limbo/opt/optimizer.hpp>
#include <limbo/tools/macros.hpp>
namespace limbo {
namespace defaults {
......@@ -64,6 +64,13 @@ namespace limbo {
/// @ingroup opt_defaults
/// number of calls to the optimized function
BO_PARAM(int, iterations, 500);
/// @ingroup opt_defaults
/// tolerance for convergence: stop when an optimization step (or an
/// estimate of the optimum) changes the objective function value by
/// less than tol multiplied by the absolute value of the function
/// value.
/// IGNORED if negative (no tolerance, only maximum iteration)
BO_PARAM(double, fun_tolerance, -1);
};
}
namespace opt {
......@@ -111,6 +118,7 @@ namespace limbo {
Eigen::VectorXd::Map(&x[0], dim) = init;
opt.set_maxeval(Params::opt_nloptgrad::iterations());
opt.set_xtol_rel(Params::opt_nloptgrad::fun_tolerance());
if (bounded) {
opt.set_lower_bounds(std::vector<double>(dim, 0));
......
......@@ -64,6 +64,13 @@ namespace limbo {
/// @ingroup opt_defaults
/// number of calls to the optimized function
BO_PARAM(int, iterations, 500);
/// @ingroup opt_defaults
/// tolerance for convergence: stop when an optimization step (or an
/// estimate of the optimum) changes the objective function value by
/// less than tol multiplied by the absolute value of the function
/// value.
/// IGNORED if negative (no tolerance, only maximum iteration)
BO_PARAM(double, fun_tolerance, -1);
};
}
namespace opt {
......@@ -128,6 +135,7 @@ namespace limbo {
Eigen::VectorXd::Map(&x[0], dim) = init;
opt.set_maxeval(Params::opt_nloptnograd::iterations());
opt.set_xtol_rel(Params::opt_nloptnograd::fun_tolerance());
if (bounded) {
opt.set_lower_bounds(std::vector<double>(dim, 0));
......
......@@ -55,11 +55,11 @@
using namespace limbo;
struct Params {
struct opt_nloptgrad {
struct opt_nloptgrad : public defaults::opt_nloptgrad {
BO_PARAM(int, iterations, 80);
};
struct opt_nloptnograd {
struct opt_nloptnograd : public defaults::opt_nloptnograd {
BO_PARAM(int, iterations, 80);
};
};
......
......@@ -51,13 +51,13 @@ using namespace limbo;
#ifdef USE_NLOPT
struct ParamsGrad {
struct opt_nloptgrad {
struct opt_nloptgrad : public defaults::opt_nloptgrad {
BO_PARAM(int, iterations, 80);
};
};
struct ParamsNoGrad {
struct opt_nloptnograd {
struct opt_nloptnograd : public defaults::opt_nloptnograd {
BO_PARAM(int, iterations, 80);
};
};
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment