Boost C++ Libraries Home Libraries People FAQ More

PrevUpHomeNext

Dynamic Coordinate Search with Radial Basis Functions

Synopsis

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

namespace boost::math::optimization {

template <typename ArgumentContainer> struct dycors_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 initial_points = 0;
    size_t candidates = 0;
};

template <typename ArgumentContainer>
void validate_dycors_parameters(dycors_parameters<ArgumentContainer> const &params);

template <typename ArgumentContainer, class Func, class URBG>
ArgumentContainer dycors(const Func cost_function,
                         dycors_parameters<ArgumentContainer> const &params,
                         URBG &gen,
                         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 dycors function searches for a global minimum of a function on a box with DYCORS (DYnamic COordinate search using Response Surface models), the method of Regis and Shoemaker, in its DYCORS-LMSRBF form. Like TuRBO, it is meant for expensive functions and budgets of a few hundred to a few thousand calls, but it was designed for many dimensions, from tens to hundreds.

DYCORS fits a cubic radial basis function surrogate with a linear tail, s(x) = ∑k λk |x - xk|3 + a0 + aT x, to all the points it has evaluated, starting from a symmetric Latin hypercube design of 2(d + 1) points. Each iteration perturbs the best point found so far into a few thousand candidate points, and evaluates the candidate that is best by a weighted combination of its (scaled) surrogate value and its (scaled) distance to the points already evaluated, with the weight on the surrogate cycling through 0.3, 0.5, 0.8 and 0.95. The candidates differ from the best point in only some of their coordinates: each coordinate is perturbed with probability

p(n) = min(20/ d, 1) (1 - ln(n - n0 + 1) / ln(N - n0))

where n is the number of calls so far, n0 the size of the initial design and N the budget, and at least one coordinate is always perturbed. In high dimensions, this keeps the search local even with large steps, and it focuses on fewer coordinates as the budget runs out. The perturbations are normal with standard deviation σ, in units of the sides of the box. σ starts at 0.2, doubles after three improvements in a row, and halves (down to 0.2 × 2-6) after max(d, 5) calls in a row that do not improve on the best value.

DYCORS is a local search with a global model: it has no restarts, and it converges to a local minimum. In the comparison below, in 30 dimensions it is about as good as TuRBO on Ackley, a little better on Rastrigin and a little worse on Levy and Rosenbrock, at a thirtieth of the cost per call or less, and much better on Ackley and Rosenbrock in 10 dimensions, but it stops in a local minimum of Rastrigin and Levy in 10 dimensions where TuRBO, which restarts, keeps improving. Multilevel coordinate search, which is deterministic and spends a microsecond per call, is competitive with both at this budget, helped on Levy and Rosenbrock by its first point, the centre of the box, which is already a good one. For cheap functions, multilevel coordinate search, differential evolution, jSO or CMA-ES are better choices.

Parameters

validate_dycors_parameters throws a std::domain_error if the bounds or initial guess are invalid, and a std::invalid_argument if initial_points is out of range. dycors calls it before the first function evaluation.

The function

template <typename ArgumentContainer, class Func, class URBG>
ArgumentContainer dycors(const Func cost_function,
                         dycors_parameters<ArgumentContainer> const &params,
                         URBG &gen,
                         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. If the computation is cancelled before the first function call, it is the midpoint of the box (or the initial guess).

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, or when cancellation is set. These are checked before every call.

Cost

Each iteration solves for the surrogate's coefficients in O(N2) operations, where N is the number of points evaluated, draws the M candidates in O(Md), and evaluates the surrogate and the distances at them in O(MNk), where k is the average number of coordinates a candidate perturbs: the squared distances from the best point are computed once per iteration, and a candidate only corrects them in its perturbed coordinates. With the defaults, on an Apple M1 Pro core, a call costs on average 0.36 ms in 10 dimensions, 1.4 ms in 30 dimensions and 3.1 ms in 100 dimensions over a budget of 500 calls, on a cheap function (reporting/performance/dycors_performance.cpp). (TuRBO, with its defaults, costs 45 ms and 90 ms per call in 10 and 30 dimensions.) The points, the factor of the interpolation system and the candidates take O(N2 + (N + M)d) memory, with N the budget. All of the linear algebra is hand-rolled, and done in double precision whatever the Real type of the arguments.

Implementation notes

The algorithm and its parameters follow Section 3 of the paper, except for these deliberate differences:

The details that the paper leaves open are:

Only DYCORS-LMSRBF is implemented, not DYCORS-DDS, and only one point is evaluated per iteration.

Examples
#include <boost/math/optimization/dycors.hpp>
#include <cmath>
#include <iostream>
#include <random>
#include <vector>

int main() {
    using boost::math::optimization::dycors;
    using boost::math::optimization::dycors_parameters;
    using ArgType = std::vector<double>;
    // The Ackley function in 10 dimensions, with its minimum 0 at the origin:
    auto ackley = [](ArgType const & x) {
        double const pi = 3.14159265358979323846;
        double a = 0;
        double b = 0;
        for (double t : x) {
            a += t*t;
            b += std::cos(2*pi*t);
        }
        return -20*std::exp(-0.2*std::sqrt(a/10)) - std::exp(b/10) + 20 + std::exp(1.0);
    };
    dycors_parameters<ArgType> params;
    params.lower_bounds.assign(10, -15);
    params.upper_bounds.assign(10, 20);
    params.max_function_calls = 500;
    std::mt19937_64 gen(42);
    auto x = dycors(ackley, params, gen);
    std::cout << "f(x) = " << ackley(x) << "\n";
}

With seed 42 the value is 5.4×10-4. Over 30 other seeds, 23 runs reached values between 1.3×10-4 and 2.0×10-3, and the other 7 stopped in local minima with values between 1.6 and 2.6: DYCORS has no restarts, so a run that has settled in a local minimum stays there.

Comparison

The median, over 20 seeds, of the best value found in 500 calls by DYCORS, TuRBO, multilevel coordinate search (MCS, which is deterministic, so one run), CMA-ES and random search, all with their default parameters, on the Ackley ([-15, 20]d), Rastrigin ([-4, 5]d), Rosenbrock ([-5, 10]d) and Levy ([-5, 5]d) functions, whose minimum is 0:

Function

Dimension

DYCORS

TuRBO

MCS

CMA-ES

random search

Ackley

10

3.3×10-4

1.2

1.7×10-7

2.9

15

Rastrigin

10

30

20

40

59

87

Rosenbrock

10

7.1

53

0.22

87

3.6×104

Levy

10

1.3

0.50

0.72

0.27

5.1

Ackley

30

3.2

3.2

2.5

9.8

17

Rastrigin

30

97

106

144

284

366

Rosenbrock

30

9.8×102

4.3×102

8.1×103

2.1×104

9.0×105

Levy

30

3.1

2.3

2.7

8.2

35

References

PrevUpHomeNext