Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
D
dlib
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
钟尚武
dlib
Commits
0d9043bc
Commit
0d9043bc
authored
Nov 23, 2017
by
Davis King
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Renamed find_global_maximum() to find_max_global()
parent
31875cfd
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
56 additions
and
56 deletions
+56
-56
global_optimization.h
dlib/global_optimization.h
+1
-1
find_max_global.h
dlib/global_optimization/find_max_global.h
+20
-20
find_max_global_abstract.h
dlib/global_optimization/find_max_global_abstract.h
+24
-24
global_optimization.cpp
dlib/test/global_optimization.cpp
+11
-11
No files found.
dlib/global_optimization.h
View file @
0d9043bc
...
...
@@ -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
...
...
dlib/global_optimization/find_
global_maximum
.h
→
dlib/global_optimization/find_
max_global
.h
View file @
0d9043bc
...
...
@@ -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
);
}
// ----------------------------------------------------------------------------------------
...
...
dlib/global_optimization/find_
global_maximum
_abstract.h
→
dlib/global_optimization/find_
max_global
_abstract.h
View file @
0d9043bc
...
...
@@ -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
);
}
// ----------------------------------------------------------------------------------------
...
...
dlib/test/global_optimization.cpp
View file @
0d9043bc
...
...
@@ -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
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment