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
ec7a4af1
Commit
ec7a4af1
authored
Nov 23, 2017
by
Davis King
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
A bit of cleanup and documentation
parent
e7e5d238
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
254 additions
and
17 deletions
+254
-17
find_global_maximum.h
dlib/global_optimization/find_global_maximum.h
+0
-0
find_global_maximum_abstract.h
dlib/global_optimization/find_global_maximum_abstract.h
+0
-0
global_function_search.cpp
dlib/global_optimization/global_function_search.cpp
+8
-6
global_function_search.h
dlib/global_optimization/global_function_search.h
+9
-11
global_function_search_abstract.h
dlib/global_optimization/global_function_search_abstract.h
+237
-0
No files found.
dlib/global_optimization/find_global_maximum.h
View file @
ec7a4af1
This diff is collapsed.
Click to expand it.
dlib/global_optimization/find_global_maximum_abstract.h
0 → 100644
View file @
ec7a4af1
This diff is collapsed.
Click to expand it.
dlib/global_optimization/global_function_search.cpp
View file @
ec7a4af1
...
...
@@ -368,10 +368,10 @@ namespace dlib
// ----------------------------------------------------------------------------------------
function_spec
::
function_spec
(
const
matrix
<
double
,
0
,
1
>&
lower_
,
const
matrix
<
double
,
0
,
1
>&
upper_
matrix
<
double
,
0
,
1
>
bound1
,
matrix
<
double
,
0
,
1
>
bound2
)
:
lower
(
lower_
),
upper
(
upper_
)
lower
(
std
::
move
(
bound1
)),
upper
(
std
::
move
(
bound2
)
)
{
DLIB_CASSERT
(
lower
.
size
()
==
upper
.
size
());
for
(
size_t
i
=
0
;
i
<
lower
.
size
();
++
i
)
...
...
@@ -386,11 +386,11 @@ namespace dlib
// ----------------------------------------------------------------------------------------
function_spec
::
function_spec
(
const
matrix
<
double
,
0
,
1
>&
lower
,
const
matrix
<
double
,
0
,
1
>&
upper
,
matrix
<
double
,
0
,
1
>
bound1
,
matrix
<
double
,
0
,
1
>
bound2
,
std
::
vector
<
bool
>
is_integer
)
:
function_spec
(
std
::
move
(
lower
),
std
::
move
(
upper
))
function_spec
(
std
::
move
(
bound1
),
std
::
move
(
bound2
))
{
is_integer_variable
=
std
::
move
(
is_integer
);
DLIB_CASSERT
(
lower
.
size
()
==
(
long
)
is_integer_variable
.
size
());
...
...
@@ -597,6 +597,7 @@ namespace dlib
const
std
::
vector
<
function_spec
>&
functions_
)
{
DLIB_CASSERT
(
functions_
.
size
()
>
0
);
m
=
std
::
make_shared
<
std
::
mutex
>
();
functions
.
reserve
(
functions_
.
size
());
for
(
size_t
i
=
0
;
i
<
functions_
.
size
();
++
i
)
...
...
@@ -613,6 +614,7 @@ namespace dlib
)
:
global_function_search
(
functions_
)
{
DLIB_CASSERT
(
functions_
.
size
()
>
0
);
DLIB_CASSERT
(
functions_
.
size
()
==
initial_function_evals
.
size
());
DLIB_CASSERT
(
relative_noise_magnitude
>=
0
);
relative_noise_magnitude
=
relative_noise_magnitude_
;
...
...
dlib/global_optimization/global_function_search.h
View file @
ec7a4af1
...
...
@@ -3,6 +3,7 @@
#ifndef DLIB_GLOBAL_FuNCTION_SEARCH_Hh_
#define DLIB_GLOBAL_FuNCTION_SEARCH_Hh_
#include "global_function_search_abstract.h"
#include <vector>
#include "../matrix.h"
#include <mutex>
...
...
@@ -17,13 +18,13 @@ namespace dlib
struct
function_spec
{
function_spec
(
const
matrix
<
double
,
0
,
1
>&
lower_
,
const
matrix
<
double
,
0
,
1
>&
upper_
matrix
<
double
,
0
,
1
>
bound1
,
matrix
<
double
,
0
,
1
>
bound2
);
function_spec
(
const
matrix
<
double
,
0
,
1
>&
lower
,
const
matrix
<
double
,
0
,
1
>&
upper
,
matrix
<
double
,
0
,
1
>
bound1
,
matrix
<
double
,
0
,
1
>
bound2
,
std
::
vector
<
bool
>
is_integer
);
...
...
@@ -116,12 +117,6 @@ namespace dlib
void
set
(
double
y
);
/*!
requires
- has_been_evaluated() == false
ensures
- #has_been_evaluated() == true
!*/
private
:
...
...
@@ -143,7 +138,7 @@ namespace dlib
{
public
:
global_function_search
()
=
de
lete
;
global_function_search
()
=
de
fault
;
explicit
global_function_search
(
const
function_spec
&
function
...
...
@@ -162,6 +157,9 @@ namespace dlib
global_function_search
(
const
global_function_search
&
)
=
delete
;
global_function_search
&
operator
=
(
const
global_function_search
&
item
)
=
delete
;
global_function_search
(
global_function_search
&&
item
)
=
default
;
global_function_search
&
operator
=
(
global_function_search
&&
item
)
=
default
;
size_t
num_functions
(
)
const
;
...
...
dlib/global_optimization/global_function_search_abstract.h
0 → 100644
View file @
ec7a4af1
// Copyright (C) 2017 Davis E. King (davis@dlib.net)
// License: Boost Software License See LICENSE.txt for the full license.
#undef DLIB_GLOBAL_FuNCTION_SEARCH_ABSTRACT_Hh_
#ifdef DLIB_GLOBAL_FuNCTION_SEARCH_ABSTRACT_Hh_
#include <vector>
#include "../matrix.h"
#include "upper_bound_function_abstract.h"
namespace
dlib
{
// ----------------------------------------------------------------------------------------
struct
function_spec
{
/*!
WHAT THIS OBJECT REPRESENTS
This object is a simple struct that lets you define the valid inputs to a
multivariate function. It lets you define bounds constraints for each
variable as well as say if a variable is integer valued or not. Therefore,
an instance of this struct says that a function takes upper.size() input
variables, where the ith variable must be in the range [lower(i) upper(i)]
and be an integer if is_integer_variable[i]==true.
!*/
function_spec
(
matrix
<
double
,
0
,
1
>
bound1
,
matrix
<
double
,
0
,
1
>
bound2
);
/*!
requires
- bound1.size() == bound2.size()
- for all valid i: bound1(i) != bound2(i)
ensures
- #is_integer_variable.size() == bound1.size()
- #lower.size() == bound1.size()
- #upper.size() == bound1.size()
- for all valid i:
- #is_integer_variable[i] == false
- #lower(i) == min(bound1(i), bound2(i))
- #upper(i) == max(bound1(i), bound2(i))
!*/
function_spec
(
matrix
<
double
,
0
,
1
>
lower
,
matrix
<
double
,
0
,
1
>
upper
,
std
::
vector
<
bool
>
is_integer
);
/*!
requires
- bound1.size() == bound2.size() == is_integer.size()
- for all valid i: bound1(i) != bound2(i)
ensures
- #is_integer_variable.size() == bound1.size()
- #lower.size() == bound1.size()
- #upper.size() == bound1.size()
- for all valid i:
- #is_integer_variable[i] == is_integer[i]
- #lower(i) == min(bound1(i), bound2(i))
- #upper(i) == max(bound1(i), bound2(i))
!*/
matrix
<
double
,
0
,
1
>
lower
;
matrix
<
double
,
0
,
1
>
upper
;
std
::
vector
<
bool
>
is_integer_variable
;
};
// ----------------------------------------------------------------------------------------
class
function_evaluation_request
{
/*!
WHAT THIS OBJECT REPRESENTS
!*/
public
:
// You can't make or copy this object, the only way to get one is from the
// global_function_search class via get_next_x().
function_evaluation_request
()
=
delete
;
function_evaluation_request
(
const
function_evaluation_request
&
)
=
delete
;
function_evaluation_request
&
operator
=
(
const
function_evaluation_request
&
)
=
delete
;
// You can however move and swap this object.
function_evaluation_request
(
function_evaluation_request
&&
item
);
function_evaluation_request
&
operator
=
(
function_evaluation_request
&&
item
);
/*!
moving from item causes item.has_been_evaluated() == true, TODO, clarify
!*/
void
swap
(
function_evaluation_request
&
item
);
/*!
ensures
- swaps the state of *this and item
!*/
~
function_evaluation_request
(
);
/*!
ensures
- frees all resources associated with this object.
!*/
size_t
function_idx
(
)
const
;
const
matrix
<
double
,
0
,
1
>&
x
(
)
const
;
bool
has_been_evaluated
(
)
const
;
void
set
(
double
y
);
/*!
requires
- has_been_evaluated() == false
ensures
- #has_been_evaluated() == true
!*/
};
// ----------------------------------------------------------------------------------------
class
global_function_search
{
/*!
WHAT THIS OBJECT REPRESENTS
!*/
public
:
global_function_search
(
);
/*!
ensures
- #num_functions() == 0
!*/
// This object can't be copied.
global_function_search
(
const
global_function_search
&
)
=
delete
;
global_function_search
&
operator
=
(
const
global_function_search
&
item
)
=
delete
;
global_function_search
(
global_function_search
&&
item
)
=
default
;
global_function_search
&
operator
=
(
global_function_search
&&
item
)
=
default
;
/*!
ensures
- moves the state of item into *this
- #item.num_functions() == 0
!*/
explicit
global_function_search
(
const
function_spec
&
function
);
explicit
global_function_search
(
const
std
::
vector
<
function_spec
>&
functions_
);
global_function_search
(
const
std
::
vector
<
function_spec
>&
functions_
,
const
std
::
vector
<
std
::
vector
<
function_evaluation
>>&
initial_function_evals
,
const
double
relative_noise_magnitude
=
0
.
001
);
size_t
num_functions
(
)
const
;
void
set_seed
(
time_t
seed
);
void
get_function_evaluations
(
std
::
vector
<
function_spec
>&
specs
,
std
::
vector
<
std
::
vector
<
function_evaluation
>>&
function_evals
)
const
;
void
get_best_function_eval
(
matrix
<
double
,
0
,
1
>&
x
,
double
&
y
,
size_t
&
function_idx
)
const
;
/*!
requires
- num_functions() != 0
!*/
function_evaluation_request
get_next_x
(
);
/*!
requires
- num_functions() != 0
!*/
double
get_pure_random_search_probability
(
)
const
;
void
set_pure_random_search_probability
(
double
prob
);
double
get_solver_epsilon
(
)
const
;
void
set_solver_epsilon
(
double
eps
);
double
get_relative_noise_magnitude
(
)
const
;
void
set_relative_noise_magnitude
(
double
value
);
size_t
get_monte_carlo_upper_bound_sample_num
(
)
const
;
void
set_monte_carlo_upper_bound_sample_num
(
size_t
num
);
};
// ----------------------------------------------------------------------------------------
}
#endif // DLIB_GLOBAL_FuNCTION_SEARCH_ABSTRACT_Hh_
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