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
c91a0473
Commit
c91a0473
authored
Nov 21, 2017
by
Davis King
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
more cleanup
parent
1eee5ccd
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
117 additions
and
26 deletions
+117
-26
global_function_search.cpp
dlib/global_optimization/global_function_search.cpp
+94
-18
global_function_search.h
dlib/global_optimization/global_function_search.h
+23
-8
No files found.
dlib/global_optimization/global_function_search.cpp
View file @
c91a0473
...
...
@@ -6,6 +6,9 @@
namespace
dlib
{
// ----------------------------------------------------------------------------------------
namespace
qopt_impl
{
void
fit_qp_mse
(
...
...
@@ -320,6 +323,8 @@ namespace dlib
double
upper_bound
=
0
;
};
// ------------------------------------------------------------------------------------
max_upper_bound_function
pick_next_sample_max_upper_bound_function
(
dlib
::
rand
&
rnd
,
const
upper_bound_function
&
ub
,
...
...
@@ -362,7 +367,11 @@ namespace dlib
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
function_spec
::
function_spec
(
const
matrix
<
double
,
0
,
1
>&
lower_
,
const
matrix
<
double
,
0
,
1
>&
upper_
)
:
lower
(
lower_
),
upper
(
upper_
)
function_spec
::
function_spec
(
const
matrix
<
double
,
0
,
1
>&
lower_
,
const
matrix
<
double
,
0
,
1
>&
upper_
)
:
lower
(
lower_
),
upper
(
upper_
)
{
DLIB_CASSERT
(
lower
.
size
()
==
upper
.
size
());
for
(
size_t
i
=
0
;
i
<
lower
.
size
();
++
i
)
...
...
@@ -374,7 +383,14 @@ namespace dlib
is_integer_variable
.
assign
(
lower
.
size
(),
false
);
}
function_spec
::
function_spec
(
const
matrix
<
double
,
0
,
1
>&
lower
,
const
matrix
<
double
,
0
,
1
>&
upper
,
std
::
vector
<
bool
>
is_integer
)
:
function_spec
(
std
::
move
(
lower
),
std
::
move
(
upper
))
// ----------------------------------------------------------------------------------------
function_spec
::
function_spec
(
const
matrix
<
double
,
0
,
1
>&
lower
,
const
matrix
<
double
,
0
,
1
>&
upper
,
std
::
vector
<
bool
>
is_integer
)
:
function_spec
(
std
::
move
(
lower
),
std
::
move
(
upper
))
{
is_integer_variable
=
std
::
move
(
is_integer
);
DLIB_CASSERT
(
lower
.
size
()
==
(
long
)
is_integer_variable
.
size
());
...
...
@@ -416,6 +432,8 @@ namespace dlib
return
tmp
;
}
// ------------------------------------------------------------------------------------
double
funct_info
::
find_nn
(
const
std
::
vector
<
function_evaluation
>&
evals
,
const
matrix
<
double
,
0
,
1
>&
x
...
...
@@ -435,11 +453,14 @@ namespace dlib
return
best_y
;
}
}
}
// end namespace gopt_impl
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
function_evaluation_request
::
function_evaluation_request
(
function_evaluation_request
&&
item
)
function_evaluation_request
::
function_evaluation_request
(
function_evaluation_request
&&
item
)
{
m_has_been_evaluated
=
item
.
m_has_been_evaluated
;
req
=
item
.
req
;
...
...
@@ -449,21 +470,31 @@ namespace dlib
item
.
m_has_been_evaluated
=
true
;
}
// ----------------------------------------------------------------------------------------
function_evaluation_request
&
function_evaluation_request
::
operator
=
(
function_evaluation_request
&&
item
)
operator
=
(
function_evaluation_request
&&
item
)
{
function_evaluation_request
(
std
::
move
(
item
)).
swap
(
*
this
);
return
*
this
;
}
// ----------------------------------------------------------------------------------------
void
function_evaluation_request
::
swap
(
function_evaluation_request
&
item
)
swap
(
function_evaluation_request
&
item
)
{
std
::
swap
(
m_has_been_evaluated
,
item
.
m_has_been_evaluated
);
std
::
swap
(
req
,
item
.
req
);
std
::
swap
(
info
,
item
.
info
);
}
// ----------------------------------------------------------------------------------------
size_t
function_evaluation_request
::
function_idx
(
)
const
...
...
@@ -478,6 +509,8 @@ namespace dlib
return
req
.
x
;
}
// ----------------------------------------------------------------------------------------
bool
function_evaluation_request
::
has_been_evaluated
(
)
const
...
...
@@ -485,6 +518,8 @@ namespace dlib
return
m_has_been_evaluated
;
}
// ----------------------------------------------------------------------------------------
function_evaluation_request
::
~
function_evaluation_request
()
{
...
...
@@ -498,16 +533,12 @@ namespace dlib
}
}
// ----------------------------------------------------------------------------------------
void
function_evaluation_request
::
set
(
double
y
)
/*!
requires
- has_been_evaluated() == false
ensures
- #has_been_evaluated() == true
!*/
{
DLIB_CASSERT
(
has_been_evaluated
()
==
false
);
std
::
lock_guard
<
std
::
mutex
>
lock
(
*
info
->
m
);
...
...
@@ -559,6 +590,8 @@ namespace dlib
const
function_spec
&
function
)
:
global_function_search
(
std
::
vector
<
function_spec
>
(
1
,
function
))
{}
// ----------------------------------------------------------------------------------------
global_function_search
::
global_function_search
(
const
std
::
vector
<
function_spec
>&
functions_
...
...
@@ -570,12 +603,15 @@ namespace dlib
functions
.
emplace_back
(
std
::
make_shared
<
gopt_impl
::
funct_info
>
(
functions_
[
i
],
i
,
m
));
}
// ----------------------------------------------------------------------------------------
global_function_search
::
global_function_search
(
const
std
::
vector
<
function_spec
>&
functions_
,
const
std
::
vector
<
std
::
vector
<
function_evaluation
>>&
initial_function_evals
,
const
double
relative_noise_magnitude_
)
:
global_function_search
(
functions_
)
)
:
global_function_search
(
functions_
)
{
DLIB_CASSERT
(
functions_
.
size
()
==
initial_function_evals
.
size
());
DLIB_CASSERT
(
relative_noise_magnitude
>=
0
);
...
...
@@ -586,13 +622,17 @@ namespace dlib
}
}
// ----------------------------------------------------------------------------------------
size_t
global_function_search
::
num_functions
()
const
num_functions
(
)
const
{
return
functions
.
size
();
}
// ----------------------------------------------------------------------------------------
void
global_function_search
::
set_seed
(
time_t
seed
...
...
@@ -601,6 +641,8 @@ namespace dlib
rnd
=
dlib
::
rand
(
seed
);
}
// ----------------------------------------------------------------------------------------
void
global_function_search
::
get_function_evaluations
(
std
::
vector
<
function_spec
>&
specs
,
...
...
@@ -617,6 +659,8 @@ namespace dlib
}
}
// ----------------------------------------------------------------------------------------
void
global_function_search
::
get_best_function_eval
(
matrix
<
double
,
0
,
1
>&
x
,
...
...
@@ -634,6 +678,8 @@ namespace dlib
x
=
info
.
best_x
;
}
// ----------------------------------------------------------------------------------------
function_evaluation_request
global_function_search
::
get_next_x
(
)
...
...
@@ -734,9 +780,16 @@ namespace dlib
}
// ----------------------------------------------------------------------------------------
double
global_function_search
::
get_pure_random_search_probability
(
)
const
{
return
pure_random_search_probability
;
}
)
const
{
return
pure_random_search_probability
;
}
// ----------------------------------------------------------------------------------------
void
global_function_search
::
set_pure_random_search_probability
(
...
...
@@ -747,9 +800,16 @@ namespace dlib
pure_random_search_probability
=
prob
;
}
// ----------------------------------------------------------------------------------------
double
global_function_search
::
get_solver_epsilon
(
)
const
{
return
min_trust_region_epsilon
;
}
)
const
{
return
min_trust_region_epsilon
;
}
// ----------------------------------------------------------------------------------------
void
global_function_search
::
set_solver_epsilon
(
...
...
@@ -760,6 +820,8 @@ namespace dlib
min_trust_region_epsilon
=
eps
;
}
// ----------------------------------------------------------------------------------------
double
global_function_search
::
get_relative_noise_magnitude
(
)
const
...
...
@@ -767,6 +829,8 @@ namespace dlib
return
relative_noise_magnitude
;
}
// ----------------------------------------------------------------------------------------
void
global_function_search
::
set_relative_noise_magnitude
(
double
value
...
...
@@ -779,6 +843,8 @@ namespace dlib
f
->
ub
=
upper_bound_function
(
f
->
ub
.
get_points
(),
relative_noise_magnitude
);
}
// ----------------------------------------------------------------------------------------
size_t
global_function_search
::
get_monte_carlo_upper_bound_sample_num
(
)
const
...
...
@@ -786,6 +852,8 @@ namespace dlib
return
num_random_samples
;
}
// ----------------------------------------------------------------------------------------
void
global_function_search
::
set_monte_carlo_upper_bound_sample_num
(
size_t
num
...
...
@@ -795,16 +863,22 @@ namespace dlib
num_random_samples
=
num
;
}
// ----------------------------------------------------------------------------------------
std
::
shared_ptr
<
gopt_impl
::
funct_info
>
global_function_search
::
best_function
()
const
best_function
(
)
const
{
size_t
idx
=
0
;
return
best_function
(
idx
);
}
// ----------------------------------------------------------------------------------------
std
::
shared_ptr
<
gopt_impl
::
funct_info
>
global_function_search
::
best_function
(
size_t
&
idx
)
const
best_function
(
size_t
&
idx
)
const
{
auto
i
=
std
::
max_element
(
functions
.
begin
(),
functions
.
end
(),
[](
const
std
::
shared_ptr
<
gopt_impl
::
funct_info
>&
a
,
const
std
::
shared_ptr
<
gopt_impl
::
funct_info
>&
b
)
{
return
a
->
best_objective_value
<
b
->
best_objective_value
;
});
...
...
@@ -813,6 +887,8 @@ namespace dlib
return
*
i
;
}
// ----------------------------------------------------------------------------------------
bool
global_function_search
::
has_incomplete_trust_region_request
(
)
const
...
...
dlib/global_optimization/global_function_search.h
View file @
c91a0473
...
...
@@ -16,9 +16,16 @@ namespace dlib
struct
function_spec
{
function_spec
(
const
matrix
<
double
,
0
,
1
>&
lower_
,
const
matrix
<
double
,
0
,
1
>&
upper_
);
function_spec
(
const
matrix
<
double
,
0
,
1
>&
lower_
,
const
matrix
<
double
,
0
,
1
>&
upper_
);
function_spec
(
const
matrix
<
double
,
0
,
1
>&
lower
,
const
matrix
<
double
,
0
,
1
>&
upper
,
std
::
vector
<
bool
>
is_integer
);
function_spec
(
const
matrix
<
double
,
0
,
1
>&
lower
,
const
matrix
<
double
,
0
,
1
>&
upper
,
std
::
vector
<
bool
>
is_integer
);
matrix
<
double
,
0
,
1
>
lower
;
matrix
<
double
,
0
,
1
>
upper
;
...
...
@@ -48,7 +55,12 @@ namespace dlib
funct_info
(
const
funct_info
&
)
=
delete
;
funct_info
&
operator
=
(
const
funct_info
&
)
=
delete
;
funct_info
(
const
function_spec
&
spec
,
size_t
function_idx
,
const
std
::
shared_ptr
<
std
::
mutex
>&
m
)
:
spec
(
spec
),
function_idx
(
function_idx
),
m
(
m
)
funct_info
(
const
function_spec
&
spec
,
size_t
function_idx
,
const
std
::
shared_ptr
<
std
::
mutex
>&
m
)
:
spec
(
spec
),
function_idx
(
function_idx
),
m
(
m
)
{
best_x
=
zeros_matrix
(
spec
.
lower
);
}
...
...
@@ -81,12 +93,11 @@ namespace dlib
public
:
function_evaluation_request
()
=
delete
;
function_evaluation_request
(
const
function_evaluation_request
&
)
=
delete
;
function_evaluation_request
&
operator
=
(
const
function_evaluation_request
&
)
=
delete
;
function_evaluation_request
(
function_evaluation_request
&&
item
);
function_evaluation_request
(
function_evaluation_request
&&
item
);
function_evaluation_request
&
operator
=
(
function_evaluation_request
&&
item
);
void
swap
(
function_evaluation_request
&
item
);
...
...
@@ -151,7 +162,8 @@ namespace dlib
global_function_search
(
const
global_function_search
&
)
=
delete
;
global_function_search
&
operator
=
(
const
global_function_search
&
item
)
=
delete
;
size_t
num_functions
()
const
;
size_t
num_functions
(
)
const
;
void
set_seed
(
time_t
seed
...
...
@@ -201,9 +213,12 @@ namespace dlib
private
:
std
::
shared_ptr
<
gopt_impl
::
funct_info
>
best_function
()
const
;
std
::
shared_ptr
<
gopt_impl
::
funct_info
>
best_function
(
)
const
;
std
::
shared_ptr
<
gopt_impl
::
funct_info
>
best_function
(
size_t
&
idx
)
const
;
std
::
shared_ptr
<
gopt_impl
::
funct_info
>
best_function
(
size_t
&
idx
)
const
;
bool
has_incomplete_trust_region_request
(
)
const
;
...
...
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