Commit 0d9043bc authored by Davis King's avatar Davis King

Renamed find_global_maximum() to find_max_global()

parent 31875cfd
......@@ -5,7 +5,7 @@
#include "global_optimization/upper_bound_function.h"
#include "global_optimization/global_function_search.h"
#include "global_optimization/find_global_maximum.h"
#include "global_optimization/find_max_global.h"
#endif // DLIB_GLOBAL_OPTIMIZATIOn_HEADER
......
......@@ -3,7 +3,7 @@
#ifndef DLIB_FiND_GLOBAL_MAXIMUM_hH_
#define DLIB_FiND_GLOBAL_MAXIMUM_hH_
#include "find_global_maximum_abstract.h"
#include "find_max_global_abstract.h"
#include "global_function_search.h"
#include "../metaprogramming.h"
#include <utility>
......@@ -115,7 +115,7 @@ template <typename T> static auto go(T&& f, const matrix<double, 0, 1>& a) -> de
template <
typename funct
>
std::pair<size_t,function_evaluation> find_global_maximum (
std::pair<size_t,function_evaluation> find_max_global (
std::vector<funct>& functions,
const std::vector<function_spec>& specs,
const max_function_calls num,
......@@ -148,7 +148,7 @@ template <typename T> static auto go(T&& f, const matrix<double, 0, 1>& a) -> de
template <
typename funct
>
function_evaluation find_global_maximum (
function_evaluation find_max_global (
funct f,
const matrix<double,0,1>& bound1,
const matrix<double,0,1>& bound2,
......@@ -160,7 +160,7 @@ template <typename T> static auto go(T&& f, const matrix<double, 0, 1>& a) -> de
{
std::vector<funct> functions(1,std::move(f));
std::vector<function_spec> specs(1, function_spec(bound1, bound2, is_integer_variable));
return find_global_maximum(functions, specs, num, max_runtime, solver_epsilon).second;
return find_max_global(functions, specs, num, max_runtime, solver_epsilon).second;
}
// ----------------------------------------------------------------------------------------
......@@ -168,7 +168,7 @@ template <typename T> static auto go(T&& f, const matrix<double, 0, 1>& a) -> de
template <
typename funct
>
function_evaluation find_global_maximum (
function_evaluation find_max_global (
funct f,
const matrix<double,0,1>& bound1,
const matrix<double,0,1>& bound2,
......@@ -177,7 +177,7 @@ template <typename T> static auto go(T&& f, const matrix<double, 0, 1>& a) -> de
double solver_epsilon
)
{
return find_global_maximum(std::move(f), bound1, bound2, std::vector<bool>(bound1.size(),false), num, FOREVER, solver_epsilon);
return find_max_global(std::move(f), bound1, bound2, std::vector<bool>(bound1.size(),false), num, FOREVER, solver_epsilon);
}
// ----------------------------------------------------------------------------------------
......@@ -185,7 +185,7 @@ template <typename T> static auto go(T&& f, const matrix<double, 0, 1>& a) -> de
template <
typename funct
>
function_evaluation find_global_maximum (
function_evaluation find_max_global (
funct f,
const matrix<double,0,1>& bound1,
const matrix<double,0,1>& bound2,
......@@ -194,7 +194,7 @@ template <typename T> static auto go(T&& f, const matrix<double, 0, 1>& a) -> de
double solver_epsilon = 1e-11
)
{
return find_global_maximum(std::move(f), bound1, bound2, std::vector<bool>(bound1.size(),false), num, max_runtime, solver_epsilon);
return find_max_global(std::move(f), bound1, bound2, std::vector<bool>(bound1.size(),false), num, max_runtime, solver_epsilon);
}
// ----------------------------------------------------------------------------------------
......@@ -202,7 +202,7 @@ template <typename T> static auto go(T&& f, const matrix<double, 0, 1>& a) -> de
template <
typename funct
>
function_evaluation find_global_maximum (
function_evaluation find_max_global (
funct f,
const matrix<double,0,1>& bound1,
const matrix<double,0,1>& bound2,
......@@ -210,7 +210,7 @@ template <typename T> static auto go(T&& f, const matrix<double, 0, 1>& a) -> de
double solver_epsilon
)
{
return find_global_maximum(std::move(f), bound1, bound2, std::vector<bool>(bound1.size(),false), num, FOREVER, solver_epsilon);
return find_max_global(std::move(f), bound1, bound2, std::vector<bool>(bound1.size(),false), num, FOREVER, solver_epsilon);
}
// ----------------------------------------------------------------------------------------
......@@ -218,7 +218,7 @@ template <typename T> static auto go(T&& f, const matrix<double, 0, 1>& a) -> de
template <
typename funct
>
function_evaluation find_global_maximum (
function_evaluation find_max_global (
funct f,
const double bound1,
const double bound2,
......@@ -227,7 +227,7 @@ template <typename T> static auto go(T&& f, const matrix<double, 0, 1>& a) -> de
double solver_epsilon = 1e-11
)
{
return find_global_maximum(std::move(f), matrix<double,0,1>({bound1}), matrix<double,0,1>({bound2}), num, max_runtime, solver_epsilon);
return find_max_global(std::move(f), matrix<double,0,1>({bound1}), matrix<double,0,1>({bound2}), num, max_runtime, solver_epsilon);
}
// ----------------------------------------------------------------------------------------
......@@ -235,7 +235,7 @@ template <typename T> static auto go(T&& f, const matrix<double, 0, 1>& a) -> de
template <
typename funct
>
function_evaluation find_global_maximum (
function_evaluation find_max_global (
funct f,
const double bound1,
const double bound2,
......@@ -243,7 +243,7 @@ template <typename T> static auto go(T&& f, const matrix<double, 0, 1>& a) -> de
double solver_epsilon
)
{
return find_global_maximum(std::move(f), matrix<double,0,1>({bound1}), matrix<double,0,1>({bound2}), num, FOREVER, solver_epsilon);
return find_max_global(std::move(f), matrix<double,0,1>({bound1}), matrix<double,0,1>({bound2}), num, FOREVER, solver_epsilon);
}
// ----------------------------------------------------------------------------------------
......@@ -251,7 +251,7 @@ template <typename T> static auto go(T&& f, const matrix<double, 0, 1>& a) -> de
template <
typename funct
>
function_evaluation find_global_maximum (
function_evaluation find_max_global (
funct f,
const matrix<double,0,1>& bound1,
const matrix<double,0,1>& bound2,
......@@ -259,7 +259,7 @@ template <typename T> static auto go(T&& f, const matrix<double, 0, 1>& a) -> de
double solver_epsilon = 1e-11
)
{
return find_global_maximum(std::move(f), bound1, bound2, max_function_calls(), max_runtime, solver_epsilon);
return find_max_global(std::move(f), bound1, bound2, max_function_calls(), max_runtime, solver_epsilon);
}
// ----------------------------------------------------------------------------------------
......@@ -267,7 +267,7 @@ template <typename T> static auto go(T&& f, const matrix<double, 0, 1>& a) -> de
template <
typename funct
>
function_evaluation find_global_maximum (
function_evaluation find_max_global (
funct f,
const double bound1,
const double bound2,
......@@ -275,7 +275,7 @@ template <typename T> static auto go(T&& f, const matrix<double, 0, 1>& a) -> de
double solver_epsilon = 1e-11
)
{
return find_global_maximum(std::move(f), bound1, bound2, max_function_calls(), max_runtime, solver_epsilon);
return find_max_global(std::move(f), bound1, bound2, max_function_calls(), max_runtime, solver_epsilon);
}
// ----------------------------------------------------------------------------------------
......@@ -283,7 +283,7 @@ template <typename T> static auto go(T&& f, const matrix<double, 0, 1>& a) -> de
template <
typename funct
>
function_evaluation find_global_maximum (
function_evaluation find_max_global (
funct f,
const matrix<double,0,1>& bound1,
const matrix<double,0,1>& bound2,
......@@ -292,7 +292,7 @@ template <typename T> static auto go(T&& f, const matrix<double, 0, 1>& a) -> de
double solver_epsilon = 1e-11
)
{
return find_global_maximum(std::move(f), bound1, bound2, is_integer_variable, max_function_calls(), max_runtime, solver_epsilon);
return find_max_global(std::move(f), bound1, bound2, is_integer_variable, max_function_calls(), max_runtime, solver_epsilon);
}
// ----------------------------------------------------------------------------------------
......
......@@ -53,7 +53,7 @@ namespace dlib
/*!
WHAT THIS OBJECT REPRESENTS
This is a simple typed integer class used to strongly type the "max number
of function calls" argument to find_global_maximum().
of function calls" argument to find_max_global().
!*/
......@@ -73,7 +73,7 @@ namespace dlib
template <
typename funct
>
std::pair<size_t,function_evaluation> find_global_maximum (
std::pair<size_t,function_evaluation> find_max_global (
std::vector<funct>& functions,
const std::vector<function_spec>& specs,
const max_function_calls num,
......@@ -101,7 +101,7 @@ namespace dlib
The goal is to maximize the following objective function:
max_{i,x_i}: functions[i](x_i)
subject to the constraints on x_i defined by specs[i].
Once found, the return value of find_global_maximum() is:
Once found, the return value of find_max_global() is:
make_pair(i, function_evaluation(x_i,functions[i](x_i))).
That is, we search for the settings of i and x that return the largest output
and return those settings.
......@@ -115,7 +115,7 @@ namespace dlib
far. That is, once a local maxima is identified to about solver_epsilon
accuracy, the algorithm will spend all its time exploring the functions to
find other local maxima to investigate.
- find_global_maximum() runs until one of the following is true:
- find_max_global() runs until one of the following is true:
- The total number of calls to the provided functions is == num.max_calls
- More than max_runtime time has elapsed since the start of this function.
!*/
......@@ -125,7 +125,7 @@ namespace dlib
template <
typename funct
>
function_evaluation find_global_maximum (
function_evaluation find_max_global (
funct f,
const matrix<double,0,1>& bound1,
const matrix<double,0,1>& bound2,
......@@ -153,7 +153,7 @@ namespace dlib
The goal is to maximize the following objective function:
f(x)
subject to the constraints on x defined by function_spec(bound1,bound2,is_integer_variable).
Once found, the return value of find_global_maximum() is:
Once found, the return value of find_max_global() is:
function_evaluation(x,f(x))).
That is, we search for the setting of x that returns the largest output and
return that setting.
......@@ -167,20 +167,20 @@ namespace dlib
far. That is, once a local maxima is identified to about solver_epsilon
accuracy, the algorithm will spend all its time exploring the function to
find other local maxima to investigate.
- find_global_maximum() runs until one of the following is true:
- find_max_global() runs until one of the following is true:
- The total number of calls to f() is == num.max_calls
- More than max_runtime time has elapsed since the start of this function.
!*/
// ----------------------------------------------------------------------------------------
// The following functions are just convenient overloads for calling the above defined
// find_global_maximum() routines.
// find_max_global() routines.
// ----------------------------------------------------------------------------------------
template <
typename funct
>
function_evaluation find_global_maximum (
function_evaluation find_max_global (
funct f,
const matrix<double,0,1>& bound1,
const matrix<double,0,1>& bound2,
......@@ -189,7 +189,7 @@ namespace dlib
double solver_epsilon
)
{
return find_global_maximum(std::move(f), bound1, bound2, std::vector<bool>(bound1.size(),false), num, FOREVER, solver_epsilon);
return find_max_global(std::move(f), bound1, bound2, std::vector<bool>(bound1.size(),false), num, FOREVER, solver_epsilon);
}
// ----------------------------------------------------------------------------------------
......@@ -197,7 +197,7 @@ namespace dlib
template <
typename funct
>
function_evaluation find_global_maximum (
function_evaluation find_max_global (
funct f,
const matrix<double,0,1>& bound1,
const matrix<double,0,1>& bound2,
......@@ -206,7 +206,7 @@ namespace dlib
double solver_epsilon = 1e-11
)
{
return find_global_maximum(std::move(f), bound1, bound2, std::vector<bool>(bound1.size(),false), num, max_runtime, solver_epsilon);
return find_max_global(std::move(f), bound1, bound2, std::vector<bool>(bound1.size(),false), num, max_runtime, solver_epsilon);
}
// ----------------------------------------------------------------------------------------
......@@ -214,7 +214,7 @@ namespace dlib
template <
typename funct
>
function_evaluation find_global_maximum (
function_evaluation find_max_global (
funct f,
const matrix<double,0,1>& bound1,
const matrix<double,0,1>& bound2,
......@@ -222,7 +222,7 @@ namespace dlib
double solver_epsilon
)
{
return find_global_maximum(std::move(f), bound1, bound2, std::vector<bool>(bound1.size(),false), num, FOREVER, solver_epsilon);
return find_max_global(std::move(f), bound1, bound2, std::vector<bool>(bound1.size(),false), num, FOREVER, solver_epsilon);
}
// ----------------------------------------------------------------------------------------
......@@ -230,7 +230,7 @@ namespace dlib
template <
typename funct
>
function_evaluation find_global_maximum (
function_evaluation find_max_global (
funct f,
const double bound1,
const double bound2,
......@@ -239,7 +239,7 @@ namespace dlib
double solver_epsilon = 1e-11
)
{
return find_global_maximum(std::move(f), matrix<double,0,1>({bound1}), matrix<double,0,1>({bound2}), num, max_runtime, solver_epsilon);
return find_max_global(std::move(f), matrix<double,0,1>({bound1}), matrix<double,0,1>({bound2}), num, max_runtime, solver_epsilon);
}
// ----------------------------------------------------------------------------------------
......@@ -247,7 +247,7 @@ namespace dlib
template <
typename funct
>
function_evaluation find_global_maximum (
function_evaluation find_max_global (
funct f,
const double bound1,
const double bound2,
......@@ -255,7 +255,7 @@ namespace dlib
double solver_epsilon
)
{
return find_global_maximum(std::move(f), matrix<double,0,1>({bound1}), matrix<double,0,1>({bound2}), num, FOREVER, solver_epsilon);
return find_max_global(std::move(f), matrix<double,0,1>({bound1}), matrix<double,0,1>({bound2}), num, FOREVER, solver_epsilon);
}
// ----------------------------------------------------------------------------------------
......@@ -263,7 +263,7 @@ namespace dlib
template <
typename funct
>
function_evaluation find_global_maximum (
function_evaluation find_max_global (
funct f,
const matrix<double,0,1>& bound1,
const matrix<double,0,1>& bound2,
......@@ -271,7 +271,7 @@ namespace dlib
double solver_epsilon = 1e-11
)
{
return find_global_maximum(std::move(f), bound1, bound2, max_function_calls(), max_runtime, solver_epsilon);
return find_max_global(std::move(f), bound1, bound2, max_function_calls(), max_runtime, solver_epsilon);
}
// ----------------------------------------------------------------------------------------
......@@ -279,7 +279,7 @@ namespace dlib
template <
typename funct
>
function_evaluation find_global_maximum (
function_evaluation find_max_global (
funct f,
const double bound1,
const double bound2,
......@@ -287,7 +287,7 @@ namespace dlib
double solver_epsilon = 1e-11
)
{
return find_global_maximum(std::move(f), bound1, bound2, max_function_calls(), max_runtime, solver_epsilon);
return find_max_global(std::move(f), bound1, bound2, max_function_calls(), max_runtime, solver_epsilon);
}
// ----------------------------------------------------------------------------------------
......@@ -295,7 +295,7 @@ namespace dlib
template <
typename funct
>
function_evaluation find_global_maximum (
function_evaluation find_max_global (
funct f,
const matrix<double,0,1>& bound1,
const matrix<double,0,1>& bound2,
......@@ -304,7 +304,7 @@ namespace dlib
double solver_epsilon = 1e-11
)
{
return find_global_maximum(std::move(f), bound1, bound2, is_integer_variable, max_function_calls(), max_runtime, solver_epsilon);
return find_max_global(std::move(f), bound1, bound2, is_integer_variable, max_function_calls(), max_runtime, solver_epsilon);
}
// ----------------------------------------------------------------------------------------
......
......@@ -154,60 +154,60 @@ namespace
// ----------------------------------------------------------------------------------------
void test_find_global_maximum(
void test_find_max_global(
)
{
print_spinner();
auto rosen = [](const matrix<double,0,1>& x) { return -1*( 100*std::pow(x(1) - x(0)*x(0),2.0) + std::pow(1 - x(0),2)); };
auto result = find_global_maximum(rosen, {0, 0}, {2, 2}, max_function_calls(100), 0);
auto result = find_max_global(rosen, {0, 0}, {2, 2}, max_function_calls(100), 0);
matrix<double,0,1> true_x = {1,1};
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_global_maximum(rosen, {0, 0}, {2, 2}, max_function_calls(100));
result = find_max_global(rosen, {0, 0}, {2, 2}, max_function_calls(100));
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_global_maximum(rosen, {0, 0}, {2, 2}, std::chrono::seconds(5));
result = find_max_global(rosen, {0, 0}, {2, 2}, std::chrono::seconds(5));
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_global_maximum(rosen, {0, 0}, {2, 2}, {false,false}, max_function_calls(100));
result = find_max_global(rosen, {0, 0}, {2, 2}, {false,false}, max_function_calls(100));
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_global_maximum(rosen, {0, 0}, {0.9, 0.9}, {false,false}, max_function_calls(100));
result = find_max_global(rosen, {0, 0}, {0.9, 0.9}, {false,false}, max_function_calls(100));
true_x = {0.9, 0.81};
dlog << LINFO << "rosen, bounded at 0.9: " << trans(result.x);
DLIB_TEST_MSG(max(abs(true_x-result.x)) < 1e-5, max(abs(true_x-result.x)));
print_spinner();
result = find_global_maximum([](double x){ return -std::pow(x-2,2.0); }, -10, 10, max_function_calls(10), 0);
result = find_max_global([](double x){ return -std::pow(x-2,2.0); }, -10, 10, max_function_calls(10), 0);
dlog << LINFO << "(x-2)^2: " << trans(result.x);
DLIB_TEST(result.x.size()==1);
DLIB_TEST(std::abs(result.x - 2) < 1e-9);
print_spinner();
result = find_global_maximum([](double x){ return -std::pow(x-2,2.0); }, -10, 1, max_function_calls(10));
result = find_max_global([](double x){ return -std::pow(x-2,2.0); }, -10, 1, max_function_calls(10));
dlog << LINFO << "(x-2)^2, bound at 1: " << trans(result.x);
DLIB_TEST(result.x.size()==1);
DLIB_TEST(std::abs(result.x - 1) < 1e-9);
print_spinner();
result = find_global_maximum([](double x){ return -std::pow(x-2,2.0); }, -10, 1, std::chrono::seconds(2));
result = find_max_global([](double x){ return -std::pow(x-2,2.0); }, -10, 1, std::chrono::seconds(2));
dlog << LINFO << "(x-2)^2, bound at 1: " << trans(result.x);
DLIB_TEST(result.x.size()==1);
DLIB_TEST(std::abs(result.x - 1) < 1e-9);
print_spinner();
result = find_global_maximum([](double a, double b){ return -complex_holder_table(a,b);},
result = find_max_global([](double a, double b){ return -complex_holder_table(a,b);},
{-10, -10}, {10, 10}, max_function_calls(300), 0);
dlog << LINFO << "complex_holder_table y: "<< result.y;
DLIB_TEST_MSG(std::abs(result.y - 21.9210397) < 0.0001, std::abs(result.y - 21.9210397));
......@@ -232,7 +232,7 @@ namespace
test_upper_bound_function(0.0, 1e-6);
test_upper_bound_function(0.0, 1e-1);
test_global_function_search();
test_find_global_maximum();
test_find_max_global();
}
} a;
......
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