Boost C++ Libraries Home Libraries People FAQ More

PrevUpHomeNext

Multilevel Coordinate Search

Synopsis

#include <boost/math/optimization/multilevel_coordinate_search.hpp>

namespace boost::math::optimization {

template <typename ArgumentContainer> struct multilevel_coordinate_search_parameters {
    using Real = typename ArgumentContainer::value_type;
    ArgumentContainer lower_bounds;
    ArgumentContainer upper_bounds;
    ArgumentContainer const * initial_guess = nullptr;
    size_t max_function_calls = 0;
    size_t max_level = 0;
    bool local_search = true;
    size_t max_local_search_steps = 50;
    size_t line_search_points = 15;
};

template <typename ArgumentContainer>
void validate_multilevel_coordinate_search_parameters(multilevel_coordinate_search_parameters<ArgumentContainer> const &params);

template <typename ArgumentContainer, class Func>
ArgumentContainer multilevel_coordinate_search(const Func cost_function,
                                               multilevel_coordinate_search_parameters<ArgumentContainer> const &params,
                                               std::invoke_result_t<Func, ArgumentContainer> target_value
                                                 = std::numeric_limits<std::invoke_result_t<Func, ArgumentContainer>>::quiet_NaN(),
                                               std::atomic<bool> *cancellation = nullptr,
                                               std::atomic<std::invoke_result_t<Func, ArgumentContainer>> *current_minimum_cost = nullptr,
                                               std::vector<std::pair<ArgumentContainer, std::invoke_result_t<Func, ArgumentContainer>>> *queries = nullptr);

} // namespaces

The multilevel_coordinate_search function searches for a global minimum of a function on a box, using the multilevel coordinate search (MCS) algorithm of Huyer and Neumaier. MCS splits the box into smaller boxes along one coordinate at a time, each with a base point at which the function has been evaluated. Every box has a level, which measures how often it has been split; a sweep through the levels splits the box with the smallest function value on each level, so that large unexplored boxes (global search) and boxes with small function values (local search) are both refined. Boxes that reach the maximum level start local searches, which build quadratic models of the function by coordinate searches and minimize them over the box.

Unlike differential evolution, jSO, random search, and CMA-ES, MCS is deterministic: it needs no random number generator and always makes the same function calls. It is single-threaded, and is at its best on smooth functions in a modest number of dimensions, where it often finds the global minimum in a few hundred function calls.

Parameters

validate_multilevel_coordinate_search_parameters throws a std::domain_error if the bounds or initial guess are invalid, and a std::invalid_argument if max_level or line_search_points is out of range. multilevel_coordinate_search calls it before the first function evaluation.

The function

template <typename ArgumentContainer, class Func>
ArgumentContainer multilevel_coordinate_search(const Func cost_function,
                                               multilevel_coordinate_search_parameters<ArgumentContainer> const &params,
                                               std::invoke_result_t<Func, ArgumentContainer> target_value
                                                 = std::numeric_limits<std::invoke_result_t<Func, ArgumentContainer>>::quiet_NaN(),
                                               std::atomic<bool> *cancellation = nullptr,
                                               std::atomic<std::invoke_result_t<Func, ArgumentContainer>> *current_minimum_cost = nullptr,
                                               std::vector<std::pair<ArgumentContainer, std::invoke_result_t<Func, ArgumentContainer>>> *queries = nullptr)

Parameters:

Returns:

The ArgumentContainer corresponding to the minimum cost found by the optimization.

Termination

As in the paper, there is no convergence criterion. The computation stops when the target_value is reached, when max_function_calls calls have been made, when cancellation is set, or when every box has reached max_level. In practice the budget is usually what stops it, so if the minimum value is known, pass it as target_value.

Implementation notes

The global part (the initialization procedure, splitting by rank and by expected gain, and the sweeps through the levels) follows Sections 3 and 4 of the paper, and the local search and the "shopping basket" of local minimizers follow Section 5. There are two departures from the paper in the local search: the univariate line searches are our own (extrapolation until the best point is bracketed, then safeguarded parabolic interpolation) rather than the authors' gls, and the quadratic models are minimized over the box by a small bound-constrained quadratic minimizer (sweeps of exact coordinate minimization, each followed by a Newton step on the free variables via a Cholesky factorization, or a step along a direction of negative curvature when the factorization fails) rather than MINQ. Like MINQ, it finds a local minimizer of a possibly indefinite quadratic. As in Section 4 of the paper, each box stores its history (its parent, the splitting index and the new values along it) rather than its bounds, so the memory used is proportional to the number of function calls, not to the number of calls times the dimension; the bounds and the data for the separable quadratic model are recovered by going back through the ancestors of the box when it is split or starts a local search.

Examples

The six-hump camel function, one of the Dixon-Szego test functions of the paper, has two global minima with value -1.0316284534898774 on the box [-3, 3]×[-2, 2]:

#include <boost/math/optimization/multilevel_coordinate_search.hpp>
#include <array>
#include <iostream>

int main() {
    using boost::math::optimization::multilevel_coordinate_search;
    using boost::math::optimization::multilevel_coordinate_search_parameters;
    using ArgType = std::array<double, 2>;
    auto camel = [](ArgType const & v) {
        double x = v[0];
        double y = v[1];
        return (4 - 2.1*x*x + x*x*x*x/3)*x*x + x*y + (-4 + 4*y*y)*y*y;
    };
    multilevel_coordinate_search_parameters<ArgType> params;
    params.lower_bounds = {-3, -2};
    params.upper_bounds = {3, 2};
    auto x = multilevel_coordinate_search(camel, params);
    std::cout << "f(" << x[0] << ", " << x[1] << ") = " << camel(x) << "\n";
}
References

PrevUpHomeNext