Commit df46c516 authored by Davis King's avatar Davis King
Browse files

Greatly simplify how all the overloads of find_*_global() are setup.

This also makes it so the num and max_runtime arguments can now appear
in any order.

This does include a minor backwards compatibility break.  Which is
someone passing in initial function evaluations by directly supplying an
initializer list like {function_evaluation({1.1, 0.9}, rosen({1.1, 0.9}))} may have
to do std::vector<function_evaluation>{function_evaluation({1.1, 0.9},
rosen({1.1, 0.9}))} instead or make it a variable.  This is due to C++
not supporting direct use of initializer lists with variadic templates in this
context.  But in any case, I doubt many users do this and it is not hard
for those that do to update as described above.
parent 4c0b8b96
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include <thread> #include <thread>
#include "../threads/thread_pool_extension.h" #include "../threads/thread_pool_extension.h"
#include "../statistics/statistics.h" #include "../statistics/statistics.h"
#include "../enable_if.h"
namespace dlib namespace dlib
{ {
...@@ -122,14 +123,14 @@ template <typename T> static auto go(T&& f, const matrix<double, 0, 1>& a) -> de ...@@ -122,14 +123,14 @@ template <typename T> static auto go(T&& f, const matrix<double, 0, 1>& a) -> de
typename funct typename funct
> >
std::pair<size_t,function_evaluation> find_max_global ( std::pair<size_t,function_evaluation> find_max_global (
double ymult,
thread_pool& tp, thread_pool& tp,
std::vector<funct>& functions, std::vector<funct>& functions,
std::vector<function_spec> specs, std::vector<function_spec> specs,
const max_function_calls num, const max_function_calls num,
const std::chrono::nanoseconds max_runtime, const std::chrono::nanoseconds max_runtime = FOREVER,
double solver_epsilon, double solver_epsilon = 0,
double ymult, std::vector<std::vector<function_evaluation>> initial_function_evals = {}
std::vector<std::vector<function_evaluation>> initial_function_evals
) )
{ {
// Decide which parameters should be searched on a log scale. Basically, it's // Decide which parameters should be searched on a log scale. Basically, it's
...@@ -268,696 +269,367 @@ template <typename T> static auto go(T&& f, const matrix<double, 0, 1>& a) -> de ...@@ -268,696 +269,367 @@ template <typename T> static auto go(T&& f, const matrix<double, 0, 1>& a) -> de
return std::make_pair(function_idx, function_evaluation(x,y/ymult)); return std::make_pair(function_idx, function_evaluation(x,y/ymult));
} }
// This overload allows the order of max_runtime and num to be reversed.
template < template <
typename funct typename funct,
typename ...Args
> >
std::pair<size_t,function_evaluation> find_max_global ( std::pair<size_t,function_evaluation> find_max_global (
std::vector<funct>& functions,
std::vector<function_spec> specs,
const max_function_calls num,
const std::chrono::nanoseconds max_runtime,
double solver_epsilon,
double ymult, double ymult,
const std::vector<std::vector<function_evaluation>>& initial_function_evals thread_pool& tp,
)
{
// disabled, don't use any threads
thread_pool tp(0);
return find_max_global(tp, functions, std::move(specs), num, max_runtime, solver_epsilon, ymult, initial_function_evals);
}
}
// ----------------------------------------------------------------------------------------
template <
typename funct
>
std::pair<size_t,function_evaluation> find_max_global (
std::vector<funct>& functions,
std::vector<function_spec> specs,
const max_function_calls num,
const std::chrono::nanoseconds max_runtime = FOREVER,
double solver_epsilon = 0,
const std::vector<std::vector<function_evaluation>>& initial_function_evals = {}
)
{
return impl::find_max_global(functions, std::move(specs), num, max_runtime, solver_epsilon, +1, initial_function_evals);
}
template <
typename funct
>
std::pair<size_t,function_evaluation> find_min_global (
std::vector<funct>& functions, std::vector<funct>& functions,
std::vector<function_spec> specs, std::vector<function_spec> specs,
const std::chrono::nanoseconds max_runtime,
const max_function_calls num, const max_function_calls num,
const std::chrono::nanoseconds max_runtime = FOREVER,
double solver_epsilon = 0, double solver_epsilon = 0,
const std::vector<std::vector<function_evaluation>>& initial_function_evals = {} Args&& ...args
) )
{ {
return impl::find_max_global(functions, std::move(specs), num, max_runtime, solver_epsilon, -1, initial_function_evals); return find_max_global(ymult, tp, functions, std::move(specs), num, max_runtime, solver_epsilon, std::forward<Args>(args)...);
} }
// This overload allows the num argument to be skipped.
template < template <
typename funct typename funct,
typename ...Args
> >
std::pair<size_t,function_evaluation> find_max_global ( std::pair<size_t,function_evaluation> find_max_global (
double ymult,
thread_pool& tp, thread_pool& tp,
std::vector<funct>& functions, std::vector<funct>& functions,
std::vector<function_spec> specs, std::vector<function_spec> specs,
const max_function_calls num, const std::chrono::nanoseconds max_runtime,
const std::chrono::nanoseconds max_runtime = FOREVER,
double solver_epsilon = 0, double solver_epsilon = 0,
const std::vector<std::vector<function_evaluation>>& initial_function_evals = {} Args&& ...args
) )
{ {
return impl::find_max_global(tp, functions, std::move(specs), num, max_runtime, solver_epsilon, +1, initial_function_evals); return find_max_global(ymult, tp, functions, std::move(specs), max_function_calls(), max_runtime, solver_epsilon, std::forward<Args>(args)...);
} }
// This overload allows the max_runtime argument to be skipped.
template < template <
typename funct typename funct,
typename ...Args
> >
std::pair<size_t,function_evaluation> find_min_global ( std::pair<size_t,function_evaluation> find_max_global (
double ymult,
thread_pool& tp, thread_pool& tp,
std::vector<funct>& functions, std::vector<funct>& functions,
std::vector<function_spec> specs, std::vector<function_spec> specs,
const max_function_calls num, const max_function_calls num,
const std::chrono::nanoseconds max_runtime = FOREVER, double solver_epsilon,
double solver_epsilon = 0, Args&& ...args
const std::vector<std::vector<function_evaluation>>& initial_function_evals = {}
)
{
return impl::find_max_global(tp, functions, std::move(specs), num, max_runtime, solver_epsilon, -1, initial_function_evals);
}
// ----------------------------------------------------------------------------------------
template <
typename funct
>
function_evaluation find_max_global (
funct f,
const matrix<double,0,1>& bound1,
const matrix<double,0,1>& bound2,
const std::vector<bool>& is_integer_variable,
const max_function_calls num,
const std::chrono::nanoseconds max_runtime = FOREVER,
double solver_epsilon = 0,
const std::vector<function_evaluation>& initial_function_evals = {}
)
{
std::vector<funct> functions(1,std::move(f));
std::vector<function_spec> specs(1, function_spec(bound1, bound2, is_integer_variable));
return find_max_global(functions, std::move(specs), num, max_runtime, solver_epsilon, {initial_function_evals}).second;
}
template <
typename funct
>
function_evaluation find_min_global (
funct f,
const matrix<double,0,1>& bound1,
const matrix<double,0,1>& bound2,
const std::vector<bool>& is_integer_variable,
const max_function_calls num,
const std::chrono::nanoseconds max_runtime = FOREVER,
double solver_epsilon = 0,
const std::vector<function_evaluation>& initial_function_evals = {}
)
{
std::vector<funct> functions(1,std::move(f));
std::vector<function_spec> specs(1, function_spec(bound1, bound2, is_integer_variable));
return find_min_global(functions, std::move(specs), num, max_runtime, solver_epsilon, {initial_function_evals}).second;
}
template <
typename funct
>
function_evaluation find_max_global (
thread_pool& tp,
funct f,
const matrix<double,0,1>& bound1,
const matrix<double,0,1>& bound2,
const std::vector<bool>& is_integer_variable,
const max_function_calls num,
const std::chrono::nanoseconds max_runtime = FOREVER,
double solver_epsilon = 0,
const std::vector<function_evaluation>& initial_function_evals = {}
) )
{ {
std::vector<funct> functions(1,std::move(f)); return find_max_global(ymult, tp, functions, std::move(specs), num, FOREVER, solver_epsilon, std::forward<Args>(args)...);
std::vector<function_spec> specs(1, function_spec(bound1, bound2, is_integer_variable));
return find_max_global(tp, functions, std::move(specs), num, max_runtime, solver_epsilon, {initial_function_evals}).second;
} }
// This overload makes the thread_pool argument optional.
template < template <
typename funct typename funct,
typename ...Args
> >
function_evaluation find_min_global ( std::pair<size_t,function_evaluation> find_max_global (
thread_pool& tp, double ymult,
funct f, std::vector<funct>& functions,
const matrix<double,0,1>& bound1, Args&& ...args
const matrix<double,0,1>& bound2,
const std::vector<bool>& is_integer_variable,
const max_function_calls num,
const std::chrono::nanoseconds max_runtime = FOREVER,
double solver_epsilon = 0,
const std::vector<function_evaluation>& initial_function_evals = {}
) )
{ {
std::vector<funct> functions(1,std::move(f)); // disabled, don't use any threads
std::vector<function_spec> specs(1, function_spec(bound1, bound2, is_integer_variable)); thread_pool tp(0);
return find_min_global(tp, functions, std::move(specs), num, max_runtime, solver_epsilon, {initial_function_evals}).second;
}
// ----------------------------------------------------------------------------------------
template < return find_max_global(ymult, tp, functions, std::forward<Args>(args)...);
typename funct
>
function_evaluation find_max_global (
funct f,
const matrix<double,0,1>& bound1,
const matrix<double,0,1>& bound2,
const std::vector<bool>& is_integer_variable,
const max_function_calls num,
double solver_epsilon,
const std::vector<function_evaluation>& initial_function_evals = {}
)
{
return find_max_global(std::move(f), bound1, bound2, is_integer_variable, num, FOREVER, solver_epsilon, initial_function_evals);
} }
template < // The point of normalize() is to handle some of the overloaded argument types in
typename funct // find_max_global() instances below and turn them into the argument types expected by
> // find_max_global() above.
function_evaluation find_min_global ( template <typename T>
funct f, const T& normalize(const T& item) {
const matrix<double,0,1>& bound1, return item;
const matrix<double,0,1>& bound2,
const std::vector<bool>& is_integer_variable,
const max_function_calls num,
double solver_epsilon,
const std::vector<function_evaluation>& initial_function_evals = {}
)
{
return find_min_global(std::move(f), bound1, bound2, is_integer_variable, num, FOREVER, solver_epsilon, initial_function_evals);
} }
template < inline std::vector<std::vector<function_evaluation>> normalize(
typename funct const std::vector<function_evaluation>& initial_function_evals
>
function_evaluation find_max_global (
thread_pool& tp,
funct f,
const matrix<double,0,1>& bound1,
const matrix<double,0,1>& bound2,
const std::vector<bool>& is_integer_variable,
const max_function_calls num,
double solver_epsilon,
const std::vector<function_evaluation>& initial_function_evals = {}
) )
{ {
return find_max_global(tp, std::move(f), bound1, bound2, is_integer_variable, num, FOREVER, solver_epsilon, initial_function_evals); return {initial_function_evals};
} }
template <
typename funct
>
function_evaluation find_min_global (
thread_pool& tp,
funct f,
const matrix<double,0,1>& bound1,
const matrix<double,0,1>& bound2,
const std::vector<bool>& is_integer_variable,
const max_function_calls num,
double solver_epsilon,
const std::vector<function_evaluation>& initial_function_evals = {}
)
{
return find_min_global(tp, std::move(f), bound1, bound2, is_integer_variable, num, FOREVER, solver_epsilon, initial_function_evals);
} }
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
template < template <
typename funct typename funct,
typename ...Args
> >
function_evaluation find_max_global ( std::pair<size_t,function_evaluation> find_max_global (
funct f, std::vector<funct>& functions,
const matrix<double,0,1>& bound1, std::vector<function_spec> specs,
const matrix<double,0,1>& bound2, Args&& ...args
const max_function_calls num,
const std::chrono::nanoseconds max_runtime = FOREVER,
double solver_epsilon = 0,
const std::vector<function_evaluation>& initial_function_evals = {}
) )
{ {
return find_max_global(std::move(f), bound1, bound2, std::vector<bool>(bound1.size(),false), num, max_runtime, solver_epsilon, initial_function_evals); return impl::find_max_global(+1, functions, std::move(specs), std::forward<Args>(args)...);
} }
template < template <
typename funct typename funct,
typename ...Args
> >
function_evaluation find_min_global ( std::pair<size_t,function_evaluation> find_min_global (
funct f, std::vector<funct>& functions,
const matrix<double,0,1>& bound1, std::vector<function_spec> specs,
const matrix<double,0,1>& bound2, Args&& ...args
const max_function_calls num,
const std::chrono::nanoseconds max_runtime = FOREVER,
double solver_epsilon = 0,
const std::vector<function_evaluation>& initial_function_evals = {}
) )
{ {
return find_min_global(std::move(f), bound1, bound2, std::vector<bool>(bound1.size(),false), num, max_runtime, solver_epsilon, initial_function_evals); return impl::find_max_global(-1, functions, std::move(specs), std::forward<Args>(args)...);
} }
template < template <
typename funct typename funct,
typename ...Args
> >
function_evaluation find_max_global ( std::pair<size_t,function_evaluation> find_max_global (
thread_pool& tp, thread_pool& tp,
funct f, std::vector<funct>& functions,
const matrix<double,0,1>& bound1, std::vector<function_spec> specs,
const matrix<double,0,1>& bound2, Args&& ...args
const max_function_calls num,
const std::chrono::nanoseconds max_runtime = FOREVER,
double solver_epsilon = 0,
const std::vector<function_evaluation>& initial_function_evals = {}
) )
{ {
return find_max_global(tp, std::move(f), bound1, bound2, std::vector<bool>(bound1.size(),false), num, max_runtime, solver_epsilon, initial_function_evals); return impl::find_max_global(+1, tp, functions, std::move(specs), std::forward<Args>(args)...);
} }
template < template <
typename funct typename funct,
typename ...Args
> >
function_evaluation find_min_global ( std::pair<size_t,function_evaluation> find_min_global (
thread_pool& tp, thread_pool& tp,
funct f, std::vector<funct>& functions,
const matrix<double,0,1>& bound1, std::vector<function_spec> specs,
const matrix<double,0,1>& bound2, Args&& ...args
const max_function_calls num,
const std::chrono::nanoseconds max_runtime = FOREVER,
double solver_epsilon = 0,
const std::vector<function_evaluation>& initial_function_evals = {}
) )
{ {
return find_min_global(tp, std::move(f), bound1, bound2, std::vector<bool>(bound1.size(),false), num, max_runtime, solver_epsilon, initial_function_evals); return impl::find_max_global(-1, tp, functions, std::move(specs), std::forward<Args>(args)...);
} }
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
// Overloads that take function objects and simple matrix bounds instead of function_specs.
template < template <
typename funct typename funct,
typename ...Args
> >
function_evaluation find_max_global ( function_evaluation find_max_global (
funct f, funct f,
const matrix<double,0,1>& bound1, const matrix<double,0,1>& bound1,
const matrix<double,0,1>& bound2, const matrix<double,0,1>& bound2,
const max_function_calls num, const std::vector<bool>& is_integer_variable,
double solver_epsilon, Args&& ...args
const std::vector<function_evaluation>& initial_function_evals = {}
) )
{ {
return find_max_global(std::move(f), bound1, bound2, std::vector<bool>(bound1.size(),false), num, FOREVER, solver_epsilon, initial_function_evals); std::vector<funct> functions(1,std::move(f));
std::vector<function_spec> specs(1, function_spec(bound1, bound2, is_integer_variable));
return find_max_global(functions, std::move(specs), impl::normalize(args)...).second;
} }
template < template <
typename funct typename funct,
typename ...Args
> >
function_evaluation find_min_global ( function_evaluation find_min_global (
funct f, funct f,
const matrix<double,0,1>& bound1, const matrix<double,0,1>& bound1,
const matrix<double,0,1>& bound2, const matrix<double,0,1>& bound2,
const max_function_calls num, const std::vector<bool>& is_integer_variable,
double solver_epsilon, Args&& ...args
const std::vector<function_evaluation>& initial_function_evals = {}
) )
{ {
return find_min_global(std::move(f), bound1, bound2, std::vector<bool>(bound1.size(),false), num, FOREVER, solver_epsilon, initial_function_evals); std::vector<funct> functions(1,std::move(f));
std::vector<function_spec> specs(1, function_spec(bound1, bound2, is_integer_variable));
return find_min_global(functions, std::move(specs), impl::normalize(args)...).second;
} }
template < template <
typename funct typename funct,
typename ...Args
> >
function_evaluation find_max_global ( function_evaluation find_max_global (
thread_pool& tp, thread_pool& tp,
funct f, funct f,
const matrix<double,0,1>& bound1, const matrix<double,0,1>& bound1,
const matrix<double,0,1>& bound2, const matrix<double,0,1>& bound2,
const max_function_calls num, const std::vector<bool>& is_integer_variable,
double solver_epsilon, Args&& ...args
const std::vector<function_evaluation>& initial_function_evals = {}
) )
{ {
return find_max_global(tp, std::move(f), bound1, bound2, std::vector<bool>(bound1.size(),false), num, FOREVER, solver_epsilon, initial_function_evals); std::vector<funct> functions(1,std::move(f));
std::vector<function_spec> specs(1, function_spec(bound1, bound2, is_integer_variable));
return find_max_global(tp, functions, std::move(specs), impl::normalize(args)...).second;
} }
template < template <
typename funct typename funct,
typename ...Args
> >
function_evaluation find_min_global ( function_evaluation find_min_global (
thread_pool& tp, thread_pool& tp,
funct f, funct f,
const matrix<double,0,1>& bound1, const matrix<double,0,1>& bound1,
const matrix<double,0,1>& bound2, const matrix<double,0,1>& bound2,
const max_function_calls num, const std::vector<bool>& is_integer_variable,
double solver_epsilon, Args&& ...args
const std::vector<function_evaluation>& initial_function_evals = {}
)
{
return find_min_global(tp, std::move(f), bound1, bound2, std::vector<bool>(bound1.size(),false), num, FOREVER, solver_epsilon, initial_function_evals);
}
// ----------------------------------------------------------------------------------------
template <
typename funct
>
function_evaluation find_max_global (
funct f,
const double bound1,
const double bound2,
const max_function_calls num,
const std::chrono::nanoseconds max_runtime = FOREVER,
double solver_epsilon = 0,
const std::vector<function_evaluation>& initial_function_evals = {}
)
{
return find_max_global(std::move(f), matrix<double,0,1>({bound1}), matrix<double,0,1>({bound2}), num, max_runtime, solver_epsilon, initial_function_evals);
}
template <
typename funct
>
function_evaluation find_min_global (
funct f,
const double bound1,
const double bound2,
const max_function_calls num,
const std::chrono::nanoseconds max_runtime = FOREVER,
double solver_epsilon = 0,
const std::vector<function_evaluation>& initial_function_evals = {}
)
{
return find_min_global(std::move(f), matrix<double,0,1>({bound1}), matrix<double,0,1>({bound2}), num, max_runtime, solver_epsilon, initial_function_evals);
}
template <
typename funct
>
function_evaluation find_max_global (
thread_pool& tp,
funct f,
const double bound1,
const double bound2,
const max_function_calls num,
const std::chrono::nanoseconds max_runtime = FOREVER,
double solver_epsilon = 0,
const std::vector<function_evaluation>& initial_function_evals = {}
)
{
return find_max_global(tp, std::move(f), matrix<double,0,1>({bound1}), matrix<double,0,1>({bound2}), num, max_runtime, solver_epsilon, initial_function_evals);
}
template <
typename funct
>
function_evaluation find_min_global (
thread_pool& tp,
funct f,
const double bound1,
const double bound2,
const max_function_calls num,
const std::chrono::nanoseconds max_runtime = FOREVER,
double solver_epsilon = 0,
const std::vector<function_evaluation>& initial_function_evals = {}
)
{
return find_min_global(tp, std::move(f), matrix<double,0,1>({bound1}), matrix<double,0,1>({bound2}), num, max_runtime, solver_epsilon, initial_function_evals);
}
// ----------------------------------------------------------------------------------------
template <
typename funct
>
function_evaluation find_max_global (
funct f,
const double bound1,
const double bound2,
const max_function_calls num,
double solver_epsilon,
const std::vector<function_evaluation>& initial_function_evals = {}
)
{
return find_max_global(std::move(f), matrix<double,0,1>({bound1}), matrix<double,0,1>({bound2}), num, FOREVER, solver_epsilon, initial_function_evals);
}
template <
typename funct
>
function_evaluation find_min_global (
funct f,
const double bound1,
const double bound2,
const max_function_calls num,
double solver_epsilon,
const std::vector<function_evaluation>& initial_function_evals = {}
)
{
return find_min_global(std::move(f), matrix<double,0,1>({bound1}), matrix<double,0,1>({bound2}), num, FOREVER, solver_epsilon, initial_function_evals);
}
template <
typename funct
>
function_evaluation find_max_global (
thread_pool& tp,
funct f,
const double bound1,
const double bound2,
const max_function_calls num,
double solver_epsilon,
const std::vector<function_evaluation>& initial_function_evals = {}
)
{
return find_max_global(tp, std::move(f), matrix<double,0,1>({bound1}), matrix<double,0,1>({bound2}), num, FOREVER, solver_epsilon, initial_function_evals);
}
template <
typename funct
>
function_evaluation find_min_global (
thread_pool& tp,
funct f,
const double bound1,
const double bound2,
const max_function_calls num,
double solver_epsilon,
const std::vector<function_evaluation>& initial_function_evals = {}
) )
{ {
return find_min_global(tp, std::move(f), matrix<double,0,1>({bound1}), matrix<double,0,1>({bound2}), num, FOREVER, solver_epsilon, initial_function_evals); std::vector<funct> functions(1,std::move(f));
std::vector<function_spec> specs(1, function_spec(bound1, bound2, is_integer_variable));
return find_min_global(tp, functions, std::move(specs), impl::normalize(args)...).second;
} }
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
// overloads that are the same as above, but is_integer_variable defaulted to false for all parameters.
template < template <
typename funct typename funct,
typename T,
typename ...Args
> >
function_evaluation find_max_global ( typename disable_if<std::is_same<T,std::vector<bool>>, function_evaluation>::type
find_max_global (
funct f, funct f,
const matrix<double,0,1>& bound1, const matrix<double,0,1>& bound1,
const matrix<double,0,1>& bound2, const matrix<double,0,1>& bound2,
const std::chrono::nanoseconds max_runtime, const T& arg,
double solver_epsilon = 0, Args&& ...args
const std::vector<function_evaluation>& initial_function_evals = {}
) )
{ {
return find_max_global(std::move(f), bound1, bound2, max_function_calls(), max_runtime, solver_epsilon, initial_function_evals); const std::vector<bool> is_integer_variable(bound1.size(),false);
return find_max_global(std::move(f), bound1, bound2, is_integer_variable, arg, impl::normalize(args)...);
} }
template < template <
typename funct typename funct,
typename T,
typename ...Args
> >
function_evaluation find_min_global ( typename disable_if<std::is_same<T,std::vector<bool>>, function_evaluation>::type
find_min_global (
funct f, funct f,
const matrix<double,0,1>& bound1, const matrix<double,0,1>& bound1,
const matrix<double,0,1>& bound2, const matrix<double,0,1>& bound2,
const std::chrono::nanoseconds max_runtime, const T& arg,
double solver_epsilon = 0, Args&& ...args
const std::vector<function_evaluation>& initial_function_evals = {}
) )
{ {
return find_min_global(std::move(f), bound1, bound2, max_function_calls(), max_runtime, solver_epsilon, initial_function_evals); const std::vector<bool> is_integer_variable(bound1.size(),false);
return find_min_global(std::move(f), bound1, bound2, is_integer_variable, arg, impl::normalize(args)...);
} }
template < template <
typename funct typename funct,
typename T,
typename ...Args
> >
function_evaluation find_max_global ( typename disable_if<std::is_same<T,std::vector<bool>>, function_evaluation>::type
find_max_global (
thread_pool& tp, thread_pool& tp,
funct f, funct f,
const matrix<double,0,1>& bound1, const matrix<double,0,1>& bound1,
const matrix<double,0,1>& bound2, const matrix<double,0,1>& bound2,
const std::chrono::nanoseconds max_runtime, const T& arg,
double solver_epsilon = 0, Args&& ...args
const std::vector<function_evaluation>& initial_function_evals = {}
) )
{ {
return find_max_global(tp, std::move(f), bound1, bound2, max_function_calls(), max_runtime, solver_epsilon, initial_function_evals); const std::vector<bool> is_integer_variable(bound1.size(),false);
return find_max_global(tp, std::move(f), bound1, bound2, is_integer_variable, arg, impl::normalize(args)...);
} }
template < template <
typename funct typename funct,
typename T,
typename ...Args
> >
function_evaluation find_min_global ( typename disable_if<std::is_same<T,std::vector<bool>>, function_evaluation>::type
find_min_global (
thread_pool& tp, thread_pool& tp,
funct f, funct f,
const matrix<double,0,1>& bound1, const matrix<double,0,1>& bound1,
const matrix<double,0,1>& bound2, const matrix<double,0,1>& bound2,
const std::chrono::nanoseconds max_runtime, const T& arg,
double solver_epsilon = 0, Args&& ...args
const std::vector<function_evaluation>& initial_function_evals = {}
) )
{ {
return find_min_global(tp, std::move(f), bound1, bound2, max_function_calls(), max_runtime, solver_epsilon, initial_function_evals); const std::vector<bool> is_integer_variable(bound1.size(),false);
return find_min_global(tp, std::move(f), bound1, bound2, is_integer_variable, arg, impl::normalize(args)...);
} }
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
// overloads for a function taking a single scalar.
template < template <
typename funct typename funct,
typename T,
typename ...Args
> >
function_evaluation find_max_global ( function_evaluation find_max_global (
funct f, funct f,
const double bound1, const double bound1,
const double bound2, const double bound2,
const std::chrono::nanoseconds max_runtime, const T& arg,
double solver_epsilon = 0, Args&& ...args
const std::vector<function_evaluation>& initial_function_evals = {}
) )
{ {
return find_max_global(std::move(f), bound1, bound2, max_function_calls(), max_runtime, solver_epsilon, initial_function_evals); return find_max_global(std::move(f), matrix<double,0,1>({bound1}), matrix<double,0,1>({bound2}), arg, impl::normalize(args)...);
} }
template < template <
typename funct typename funct,
typename T,
typename ...Args
> >
function_evaluation find_min_global ( function_evaluation find_min_global (
funct f, funct f,
const double bound1, const double bound1,
const double bound2, const double bound2,
const std::chrono::nanoseconds max_runtime, const T& arg,
double solver_epsilon = 0, Args&& ...args
const std::vector<function_evaluation>& initial_function_evals = {}
) )
{ {
return find_min_global(std::move(f), bound1, bound2, max_function_calls(), max_runtime, solver_epsilon, initial_function_evals); return find_min_global(std::move(f), matrix<double,0,1>({bound1}), matrix<double,0,1>({bound2}), arg, impl::normalize(args)...);
} }
template < template <
typename funct typename funct,
typename T,
typename ...Args
> >
function_evaluation find_max_global ( function_evaluation find_max_global (
thread_pool& tp, thread_pool& tp,
funct f, funct f,
const double bound1, const double bound1,
const double bound2, const double bound2,
const std::chrono::nanoseconds max_runtime, const T& arg,
double solver_epsilon = 0, Args&& ...args
const std::vector<function_evaluation>& initial_function_evals = {}
) )
{ {
return find_max_global(tp, std::move(f), bound1, bound2, max_function_calls(), max_runtime, solver_epsilon, initial_function_evals); return find_max_global(tp, std::move(f), matrix<double,0,1>({bound1}), matrix<double,0,1>({bound2}), arg, impl::normalize(args)...);
} }
template < template <
typename funct typename funct,
typename T,
typename ...Args
> >
function_evaluation find_min_global ( function_evaluation find_min_global (
thread_pool& tp, thread_pool& tp,
funct f, funct f,
const double bound1, const double bound1,
const double bound2, const double bound2,
const std::chrono::nanoseconds max_runtime, const T& arg,
double solver_epsilon = 0, Args&& ...args
const std::vector<function_evaluation>& initial_function_evals = {}
)
{
return find_min_global(tp, std::move(f), bound1, bound2, max_function_calls(), max_runtime, solver_epsilon, initial_function_evals);
}
// ----------------------------------------------------------------------------------------
template <
typename funct
>
function_evaluation find_max_global (
funct f,
const matrix<double,0,1>& bound1,
const matrix<double,0,1>& bound2,
const std::vector<bool>& is_integer_variable,
const std::chrono::nanoseconds max_runtime,
double solver_epsilon = 0,
const std::vector<function_evaluation>& initial_function_evals = {}
)
{
return find_max_global(std::move(f), bound1, bound2, is_integer_variable, max_function_calls(), max_runtime, solver_epsilon, initial_function_evals);
}
template <
typename funct
>
function_evaluation find_min_global (
funct f,
const matrix<double,0,1>& bound1,
const matrix<double,0,1>& bound2,
const std::vector<bool>& is_integer_variable,
const std::chrono::nanoseconds max_runtime,
double solver_epsilon = 0,
const std::vector<function_evaluation>& initial_function_evals = {}
)
{
return find_min_global(std::move(f), bound1, bound2, is_integer_variable, max_function_calls(), max_runtime, solver_epsilon, initial_function_evals);
}
template <
typename funct
>
function_evaluation find_max_global (
thread_pool& tp,
funct f,
const matrix<double,0,1>& bound1,
const matrix<double,0,1>& bound2,
const std::vector<bool>& is_integer_variable,
const std::chrono::nanoseconds max_runtime,
double solver_epsilon = 0,
const std::vector<function_evaluation>& initial_function_evals = {}
)
{
return find_max_global(tp, std::move(f), bound1, bound2, is_integer_variable, max_function_calls(), max_runtime, solver_epsilon, initial_function_evals);
}
template <
typename funct
>
function_evaluation find_min_global (
thread_pool& tp,
funct f,
const matrix<double,0,1>& bound1,
const matrix<double,0,1>& bound2,
const std::vector<bool>& is_integer_variable,
const std::chrono::nanoseconds max_runtime,
double solver_epsilon = 0,
const std::vector<function_evaluation>& initial_function_evals = {}
) )
{ {
return find_min_global(tp, std::move(f), bound1, bound2, is_integer_variable, max_function_calls(), max_runtime, solver_epsilon, initial_function_evals); return find_min_global(tp, std::move(f), matrix<double,0,1>({bound1}), matrix<double,0,1>({bound2}), arg, impl::normalize(args)...);
} }
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
......
...@@ -350,539 +350,13 @@ namespace dlib ...@@ -350,539 +350,13 @@ namespace dlib
to f(). to f().
!*/ !*/
// ---------------------------------------------------------------------------------------- // Finally, there are a bunch of overloads of find_min_global() and find_max_global() that make do
// The following functions are just convenient overloads for calling the above defined // the following for you:
// find_max_global() and find_min_global() routines. // - They make is_integer_variable optional. If you don't provide it then we assume no parameters
// ---------------------------------------------------------------------------------------- // are integers.
// - The order of num and max_runtime can be exchanged. You can also leave one of these arguments
template < // out so long as you provide the other.
typename funct // - If f() takes just a single double then bound1 and bound2 can also just be doubles.
>
function_evaluation find_max_global (
funct f,
const matrix<double,0,1>& bound1,
const matrix<double,0,1>& bound2,
const std::vector<bool>& is_integer_variable,
const max_function_calls num,
double solver_epsilon,
const std::vector<function_evaluation>& initial_function_evals = {}
)
{
return find_max_global(std::move(f), bound1, bound2, is_integer_variable, num, FOREVER, solver_epsilon, initial_function_evals);
}
template <
typename funct
>
function_evaluation find_min_global (
funct f,
const matrix<double,0,1>& bound1,
const matrix<double,0,1>& bound2,
const std::vector<bool>& is_integer_variable,
const max_function_calls num,
double solver_epsilon,
const std::vector<function_evaluation>& initial_function_evals = {}
)
{
return find_min_global(std::move(f), bound1, bound2, is_integer_variable, num, FOREVER, solver_epsilon, initial_function_evals);
}
template <
typename funct
>
function_evaluation find_max_global (
thread_pool& tp,
funct f,
const matrix<double,0,1>& bound1,
const matrix<double,0,1>& bound2,
const std::vector<bool>& is_integer_variable,
const max_function_calls num,
double solver_epsilon,
const std::vector<function_evaluation>& initial_function_evals = {}
)
{
return find_max_global(tp, std::move(f), bound1, bound2, is_integer_variable, num, FOREVER, solver_epsilon, initial_function_evals);
}
template <
typename funct
>
function_evaluation find_min_global (
thread_pool& tp,
funct f,
const matrix<double,0,1>& bound1,
const matrix<double,0,1>& bound2,
const std::vector<bool>& is_integer_variable,
const max_function_calls num,
double solver_epsilon,
const std::vector<function_evaluation>& initial_function_evals = {}
)
{
return find_min_global(tp, std::move(f), bound1, bound2, is_integer_variable, num, FOREVER, solver_epsilon, initial_function_evals);
}
// ----------------------------------------------------------------------------------------
template <
typename funct
>
function_evaluation find_max_global (
funct f,
const matrix<double,0,1>& bound1,
const matrix<double,0,1>& bound2,
const max_function_calls num,
const std::chrono::nanoseconds max_runtime = FOREVER,
double solver_epsilon = 0,
const std::vector<function_evaluation>& initial_function_evals = {}
)
{
return find_max_global(std::move(f), bound1, bound2, std::vector<bool>(bound1.size(),false), num, max_runtime, solver_epsilon, initial_function_evals);
}
template <
typename funct
>
function_evaluation find_min_global (
funct f,
const matrix<double,0,1>& bound1,
const matrix<double,0,1>& bound2,
const max_function_calls num,
const std::chrono::nanoseconds max_runtime = FOREVER,
double solver_epsilon = 0,
const std::vector<function_evaluation>& initial_function_evals = {}
)
{
return find_min_global(std::move(f), bound1, bound2, std::vector<bool>(bound1.size(),false), num, max_runtime, solver_epsilon, initial_function_evals);
}
template <
typename funct
>
function_evaluation find_max_global (
thread_pool& tp,
funct f,
const matrix<double,0,1>& bound1,
const matrix<double,0,1>& bound2,
const max_function_calls num,
const std::chrono::nanoseconds max_runtime = FOREVER,
double solver_epsilon = 0,
const std::vector<function_evaluation>& initial_function_evals = {}
)
{
return find_max_global(tp, std::move(f), bound1, bound2, std::vector<bool>(bound1.size(),false), num, max_runtime, solver_epsilon, initial_function_evals);
}
template <
typename funct
>
function_evaluation find_min_global (
thread_pool& tp,
funct f,
const matrix<double,0,1>& bound1,
const matrix<double,0,1>& bound2,
const max_function_calls num,
const std::chrono::nanoseconds max_runtime = FOREVER,
double solver_epsilon = 0,
const std::vector<function_evaluation>& initial_function_evals = {}
)
{
return find_min_global(tp, std::move(f), bound1, bound2, std::vector<bool>(bound1.size(),false), num, max_runtime, solver_epsilon, initial_function_evals);
}
// ----------------------------------------------------------------------------------------
template <
typename funct
>
function_evaluation find_max_global (
funct f,
const matrix<double,0,1>& bound1,
const matrix<double,0,1>& bound2,
const max_function_calls num,
double solver_epsilon,
const std::vector<function_evaluation>& initial_function_evals = {}
)
{
return find_max_global(std::move(f), bound1, bound2, std::vector<bool>(bound1.size(),false), num, FOREVER, solver_epsilon, initial_function_evals);
}
template <
typename funct
>
function_evaluation find_min_global (
funct f,
const matrix<double,0,1>& bound1,
const matrix<double,0,1>& bound2,
const max_function_calls num,
double solver_epsilon,
const std::vector<function_evaluation>& initial_function_evals = {}
)
{
return find_min_global(std::move(f), bound1, bound2, std::vector<bool>(bound1.size(),false), num, FOREVER, solver_epsilon, initial_function_evals);
}
template <
typename funct
>
function_evaluation find_max_global (
thread_pool& tp,
funct f,
const matrix<double,0,1>& bound1,
const matrix<double,0,1>& bound2,
const max_function_calls num,
double solver_epsilon,
const std::vector<function_evaluation>& initial_function_evals = {}
)
{
return find_max_global(tp, std::move(f), bound1, bound2, std::vector<bool>(bound1.size(),false), num, FOREVER, solver_epsilon, initial_function_evals);
}
template <
typename funct
>
function_evaluation find_min_global (
thread_pool& tp,
funct f,
const matrix<double,0,1>& bound1,
const matrix<double,0,1>& bound2,
const max_function_calls num,
double solver_epsilon,
const std::vector<function_evaluation>& initial_function_evals = {}
)
{
return find_min_global(tp, std::move(f), bound1, bound2, std::vector<bool>(bound1.size(),false), num, FOREVER, solver_epsilon, initial_function_evals);
}
// ----------------------------------------------------------------------------------------
template <
typename funct
>
function_evaluation find_max_global (
funct f,
const double bound1,
const double bound2,
const max_function_calls num,
const std::chrono::nanoseconds max_runtime = FOREVER,
double solver_epsilon = 0,
const std::vector<function_evaluation>& initial_function_evals = {}
)
{
return find_max_global(std::move(f), matrix<double,0,1>({bound1}), matrix<double,0,1>({bound2}), num, max_runtime, solver_epsilon, initial_function_evals);
}
template <
typename funct
>
function_evaluation find_min_global (
funct f,
const double bound1,
const double bound2,
const max_function_calls num,
const std::chrono::nanoseconds max_runtime = FOREVER,
double solver_epsilon = 0,
const std::vector<function_evaluation>& initial_function_evals = {}
)
{
return find_min_global(std::move(f), matrix<double,0,1>({bound1}), matrix<double,0,1>({bound2}), num, max_runtime, solver_epsilon, initial_function_evals);
}
template <
typename funct
>
function_evaluation find_max_global (
thread_pool& tp,
funct f,
const double bound1,
const double bound2,
const max_function_calls num,
const std::chrono::nanoseconds max_runtime = FOREVER,
double solver_epsilon = 0,
const std::vector<function_evaluation>& initial_function_evals = {}
)
{
return find_max_global(tp, std::move(f), matrix<double,0,1>({bound1}), matrix<double,0,1>({bound2}), num, max_runtime, solver_epsilon, initial_function_evals);
}
template <
typename funct
>
function_evaluation find_min_global (
thread_pool& tp,
funct f,
const double bound1,
const double bound2,
const max_function_calls num,
const std::chrono::nanoseconds max_runtime = FOREVER,
double solver_epsilon = 0,
const std::vector<function_evaluation>& initial_function_evals = {}
)
{
return find_min_global(tp, std::move(f), matrix<double,0,1>({bound1}), matrix<double,0,1>({bound2}), num, max_runtime, solver_epsilon, initial_function_evals);
}
// ----------------------------------------------------------------------------------------
template <
typename funct
>
function_evaluation find_max_global (
funct f,
const double bound1,
const double bound2,
const max_function_calls num,
double solver_epsilon,
const std::vector<function_evaluation>& initial_function_evals = {}
)
{
return find_max_global(std::move(f), matrix<double,0,1>({bound1}), matrix<double,0,1>({bound2}), num, FOREVER, solver_epsilon, initial_function_evals);
}
template <
typename funct
>
function_evaluation find_min_global (
funct f,
const double bound1,
const double bound2,
const max_function_calls num,
double solver_epsilon,
const std::vector<function_evaluation>& initial_function_evals = {}
)
{
return find_min_global(std::move(f), matrix<double,0,1>({bound1}), matrix<double,0,1>({bound2}), num, FOREVER, solver_epsilon, initial_function_evals);
}
template <
typename funct
>
function_evaluation find_max_global (
thread_pool& tp,
funct f,
const double bound1,
const double bound2,
const max_function_calls num,
double solver_epsilon,
const std::vector<function_evaluation>& initial_function_evals = {}
)
{
return find_max_global(tp, std::move(f), matrix<double,0,1>({bound1}), matrix<double,0,1>({bound2}), num, FOREVER, solver_epsilon, initial_function_evals);
}
template <
typename funct
>
function_evaluation find_min_global (
thread_pool& tp,
funct f,
const double bound1,
const double bound2,
const max_function_calls num,
double solver_epsilon,
const std::vector<function_evaluation>& initial_function_evals = {}
)
{
return find_min_global(tp, std::move(f), matrix<double,0,1>({bound1}), matrix<double,0,1>({bound2}), num, FOREVER, solver_epsilon, initial_function_evals);
}
// ----------------------------------------------------------------------------------------
template <
typename funct
>
function_evaluation find_max_global (
funct f,
const matrix<double,0,1>& bound1,
const matrix<double,0,1>& bound2,
const std::chrono::nanoseconds max_runtime,
double solver_epsilon = 0,
const std::vector<function_evaluation>& initial_function_evals = {}
)
{
return find_max_global(std::move(f), bound1, bound2, max_function_calls(), max_runtime, solver_epsilon, initial_function_evals);
}
template <
typename funct
>
function_evaluation find_min_global (
funct f,
const matrix<double,0,1>& bound1,
const matrix<double,0,1>& bound2,
const std::chrono::nanoseconds max_runtime,
double solver_epsilon = 0,
const std::vector<function_evaluation>& initial_function_evals = {}
)
{
return find_min_global(std::move(f), bound1, bound2, max_function_calls(), max_runtime, solver_epsilon, initial_function_evals);
}
template <
typename funct
>
function_evaluation find_max_global (
thread_pool& tp,
funct f,
const matrix<double,0,1>& bound1,
const matrix<double,0,1>& bound2,
const std::chrono::nanoseconds max_runtime,
double solver_epsilon = 0,
const std::vector<function_evaluation>& initial_function_evals = {}
)
{
return find_max_global(tp, std::move(f), bound1, bound2, max_function_calls(), max_runtime, solver_epsilon, initial_function_evals);
}
template <
typename funct
>
function_evaluation find_min_global (
thread_pool& tp,
funct f,
const matrix<double,0,1>& bound1,
const matrix<double,0,1>& bound2,
const std::chrono::nanoseconds max_runtime,
double solver_epsilon = 0,
const std::vector<function_evaluation>& initial_function_evals = {}
)
{
return find_min_global(tp, std::move(f), bound1, bound2, max_function_calls(), max_runtime, solver_epsilon, initial_function_evals);
}
// ----------------------------------------------------------------------------------------
template <
typename funct
>
function_evaluation find_max_global (
funct f,
const double bound1,
const double bound2,
const std::chrono::nanoseconds max_runtime,
double solver_epsilon = 0,
const std::vector<function_evaluation>& initial_function_evals = {}
)
{
return find_max_global(std::move(f), bound1, bound2, max_function_calls(), max_runtime, solver_epsilon, initial_function_evals);
}
template <
typename funct
>
function_evaluation find_min_global (
funct f,
const double bound1,
const double bound2,
const std::chrono::nanoseconds max_runtime,
double solver_epsilon = 0,
const std::vector<function_evaluation>& initial_function_evals = {}
)
{
return find_min_global(std::move(f), bound1, bound2, max_function_calls(), max_runtime, solver_epsilon, initial_function_evals);
}
template <
typename funct
>
function_evaluation find_max_global (
thread_pool& tp,
funct f,
const double bound1,
const double bound2,
const std::chrono::nanoseconds max_runtime,
double solver_epsilon = 0,
const std::vector<function_evaluation>& initial_function_evals = {}
)
{
return find_max_global(tp, std::move(f), bound1, bound2, max_function_calls(), max_runtime, solver_epsilon, initial_function_evals);
}
template <
typename funct
>
function_evaluation find_min_global (
thread_pool& tp,
funct f,
const double bound1,
const double bound2,
const std::chrono::nanoseconds max_runtime,
double solver_epsilon = 0,
const std::vector<function_evaluation>& initial_function_evals = {}
)
{
return find_min_global(tp, std::move(f), bound1, bound2, max_function_calls(), max_runtime, solver_epsilon, initial_function_evals);
}
// ----------------------------------------------------------------------------------------
template <
typename funct
>
function_evaluation find_max_global (
funct f,
const matrix<double,0,1>& bound1,
const matrix<double,0,1>& bound2,
const std::vector<bool>& is_integer_variable,
const std::chrono::nanoseconds max_runtime,
double solver_epsilon = 0,
const std::vector<function_evaluation>& initial_function_evals = {}
)
{
return find_max_global(std::move(f), bound1, bound2, is_integer_variable, max_function_calls(), max_runtime, solver_epsilon, initial_function_evals);
}
template <
typename funct
>
function_evaluation find_min_global (
funct f,
const matrix<double,0,1>& bound1,
const matrix<double,0,1>& bound2,
const std::vector<bool>& is_integer_variable,
const std::chrono::nanoseconds max_runtime,
double solver_epsilon = 0,
const std::vector<function_evaluation>& initial_function_evals = {}
)
{
return find_min_global(std::move(f), bound1, bound2, is_integer_variable, max_function_calls(), max_runtime, solver_epsilon, initial_function_evals);
}
template <
typename funct
>
function_evaluation find_max_global (
thread_pool& tp,
funct f,
const matrix<double,0,1>& bound1,
const matrix<double,0,1>& bound2,
const std::vector<bool>& is_integer_variable,
const std::chrono::nanoseconds max_runtime,
double solver_epsilon = 0,
const std::vector<function_evaluation>& initial_function_evals = {}
)
{
return find_max_global(tp, std::move(f), bound1, bound2, is_integer_variable, max_function_calls(), max_runtime, solver_epsilon, initial_function_evals);
}
template <
typename funct
>
function_evaluation find_min_global (
thread_pool& tp,
funct f,
const matrix<double,0,1>& bound1,
const matrix<double,0,1>& bound2,
const std::vector<bool>& is_integer_variable,
const std::chrono::nanoseconds max_runtime,
double solver_epsilon = 0,
const std::vector<function_evaluation>& initial_function_evals = {}
)
{
return find_min_global(tp, std::move(f), bound1, bound2, is_integer_variable, max_function_calls(), max_runtime, solver_epsilon, initial_function_evals);
}
// ----------------------------------------------------------------------------------------
} }
......
...@@ -172,7 +172,7 @@ namespace ...@@ -172,7 +172,7 @@ namespace
DLIB_TEST_MSG(max(abs(true_x-result.x)) < 1e-5, max(abs(true_x-result.x))); DLIB_TEST_MSG(max(abs(true_x-result.x)) < 1e-5, max(abs(true_x-result.x)));
print_spinner(); print_spinner();
result = find_max_global(rosen, {0.1, 0.1}, {2, 2}, max_function_calls(100), 0, {function_evaluation({1.1, 0.9}, rosen({1.1, 0.9}))}); result = find_max_global(rosen, {0.1, 0.1}, {2, 2}, max_function_calls(100), 0, std::vector<function_evaluation>{function_evaluation({1.1, 0.9}, rosen({1.1, 0.9}))});
dlog << LINFO << "rosen: " << trans(result.x); dlog << LINFO << "rosen: " << trans(result.x);
DLIB_TEST_MSG(max(abs(true_x-result.x)) < 1e-5, max(abs(true_x-result.x))); DLIB_TEST_MSG(max(abs(true_x-result.x)) < 1e-5, max(abs(true_x-result.x)));
print_spinner(); print_spinner();
...@@ -182,11 +182,22 @@ namespace ...@@ -182,11 +182,22 @@ namespace
DLIB_TEST_MSG(max(abs(true_x-result.x)) < 1e-5, max(abs(true_x-result.x))); DLIB_TEST_MSG(max(abs(true_x-result.x)) < 1e-5, max(abs(true_x-result.x)));
print_spinner(); print_spinner();
result = find_max_global(rosen, {0.1, 0.1}, {2, 2}, std::chrono::seconds(5), 0.0);
dlog << LINFO << "rosen: " << trans(result.x);
DLIB_TEST_MSG(max(abs(true_x-result.x)) < 1e-5, max(abs(true_x-result.x)));
print_spinner();
result = find_max_global(rosen, {0.1, 0.1}, {2, 2}, {false,false}, max_function_calls(100)); result = find_max_global(rosen, {0.1, 0.1}, {2, 2}, {false,false}, max_function_calls(100));
dlog << LINFO << "rosen: " << trans(result.x); dlog << LINFO << "rosen: " << trans(result.x);
DLIB_TEST_MSG(max(abs(true_x-result.x)) < 1e-5, max(abs(true_x-result.x))); DLIB_TEST_MSG(max(abs(true_x-result.x)) < 1e-5, max(abs(true_x-result.x)));
print_spinner(); print_spinner();
result = find_max_global(rosen, {0.1, 0.1}, {2, 2}, {false,false}, max_function_calls(100), 0.0);
dlog << LINFO << "rosen: " << trans(result.x);
DLIB_TEST_MSG(max(abs(true_x-result.x)) < 1e-5, max(abs(true_x-result.x)));
print_spinner();
result = find_max_global(rosen, {0.1, 0.1}, {0.9, 0.9}, {false,false}, max_function_calls(140)); result = find_max_global(rosen, {0.1, 0.1}, {0.9, 0.9}, {false,false}, max_function_calls(140));
true_x = {0.9, 0.81}; true_x = {0.9, 0.81};
dlog << LINFO << "rosen, bounded at 0.9: " << trans(result.x); dlog << LINFO << "rosen, bounded at 0.9: " << trans(result.x);
......
Markdown is supported
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