1 #ifndef VTESTBED_CORE_LIPO_SOLVER_HH     2 #define VTESTBED_CORE_LIPO_SOLVER_HH     8 #include <vtestbed/base/blitz.hh>     9 #include <vtestbed/core/types.hh>    21         template <
class T, 
int N>
    25             using scalar_type = T;
    26             using argument_type = Vector<T,N>;
    30             value_type _constant{T{}};
    31             value_type _funceps = 0;
    32             argument_type _argeps{T{}};
    33             int _max_evaluations = 1000;
    34             int _max_iterations = 1000;
    35             scalar_type _sample_probability{T{}};
    36             bool _estimate_constant = 
true;
    41             inline value_type 
constant()
 const { 
return this->_constant; }
    54             inline void constant(value_type rhs) { this->_constant = rhs; }
    58             inline void max_iterations(
int rhs) { this->_max_iterations = rhs; }
    62             template <
class Func> 
inline argument_type
    63             solve(argument_type lbound, argument_type ubound, Func func)
 const {
    72                 for (
int i=0; i<N; ++i) {
    73                     distribution_type dist(lbound(i), ubound(i));
    80                 points.emplace_back(x);
    82                 values.emplace_back(func(x));
    83                 value_type max_value = values.front();
    89                     for (
int j=0; j<N; ++j) {
    90                         distribution_type dist(lbound(j), ubound(j));
    93                     auto old_nevaluations = nevaluations;
    95                         points.emplace_back(x);
    96                         values.emplace_back(func(x));
   101                         for (
int j=0; j<nevaluations; ++j) {
   102                             value_type new_ubound = values[j] + k*
distance(x,points[j]);
   103                             if (new_ubound < min_ubound) { min_ubound = new_ubound; }
   106                         if (min_ubound >= max_value) {
   107                             value_type func_x = func(x);
   108                             if (func_x > max_value) { max_value = func_x; }
   109                             points.emplace_back(x);
   110                             values.emplace_back(func_x);
   114                     if (old_nevaluations != nevaluations) {
   118                             argument_type points_n = points[nevaluations-1];
   119                             value_type values_n = values[nevaluations-1];
   120                             for (
int j=0; j<nevaluations-1; ++j) {
   122                                 value_type new_k = values[j]-values_n;
   123                                 if (length != 0) { new_k /= 
length; }
   130                 for (
int i=1; i<nevaluations; ++i) {
   131                     if (values[i] > values[max_index]) {
   135                 return points[max_index];
   144 #endif // vim:filetype=cpp 
argument_type argument_precision() const
Argument precision.
 
bool estimate_constant() const
Estimate Lipschitz constant or not.
 
int max_evaluations() const
Maximum number of function evaluations.
 
T length(const blitz::TinyVector< T, N > &x)
Computes vector length without overflow.
 
value_type function_precision() const
Function precision.
 
scalar_type sample_probability() const
Probability of choosing exploration step over exploitation step.
 
value_type constant() const
Lipschitz constant (one for each dimension).
 
int max_iterations() const
Maximum number of iterations of the main loop.
 
Multi-dimensional optimisation of non-convex functions.