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
5e8e997b
Commit
5e8e997b
authored
Dec 02, 2017
by
Davis King
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added python interface to find_min_global()
parent
e273f515
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
64 additions
and
0 deletions
+64
-0
global_optimization.cpp
tools/python/src/global_optimization.cpp
+64
-0
No files found.
tools/python/src/global_optimization.cpp
View file @
5e8e997b
...
...
@@ -132,6 +132,52 @@ boost::python::tuple py_find_max_global2 (
// ----------------------------------------------------------------------------------------
boost
::
python
::
tuple
py_find_min_global
(
object
f
,
boost
::
python
::
list
bound1
,
boost
::
python
::
list
bound2
,
boost
::
python
::
list
is_integer_variable
,
unsigned
long
num_function_calls
,
double
solver_epsilon
=
0
)
{
DLIB_CASSERT
(
len
(
bound1
)
==
len
(
bound2
));
DLIB_CASSERT
(
len
(
bound1
)
==
len
(
is_integer_variable
));
auto
func
=
[
&
](
const
matrix
<
double
,
0
,
1
>&
x
)
{
return
call_func
(
f
,
x
);
};
auto
result
=
find_min_global
(
func
,
list_to_mat
(
bound1
),
list_to_mat
(
bound2
),
list_to_bool_vector
(
is_integer_variable
),
max_function_calls
(
num_function_calls
),
solver_epsilon
);
return
boost
::
python
::
make_tuple
(
mat_to_list
(
result
.
x
),
result
.
y
);
}
boost
::
python
::
tuple
py_find_min_global2
(
object
f
,
boost
::
python
::
list
bound1
,
boost
::
python
::
list
bound2
,
unsigned
long
num_function_calls
,
double
solver_epsilon
=
0
)
{
DLIB_CASSERT
(
len
(
bound1
)
==
len
(
bound2
));
auto
func
=
[
&
](
const
matrix
<
double
,
0
,
1
>&
x
)
{
return
call_func
(
f
,
x
);
};
auto
result
=
find_min_global
(
func
,
list_to_mat
(
bound1
),
list_to_mat
(
bound2
),
max_function_calls
(
num_function_calls
),
solver_epsilon
);
return
boost
::
python
::
make_tuple
(
mat_to_list
(
result
.
x
),
result
.
y
);
}
// ----------------------------------------------------------------------------------------
void
bind_global_optimization
()
{
/*!
...
...
@@ -244,5 +290,23 @@ ensures \n\
(
arg
(
"f"
),
arg
(
"bound1"
),
arg
(
"bound2"
),
arg
(
"num_function_calls"
),
arg
(
"solver_epsilon"
)
=
0
)
);
}
{
def
(
"find_min_global"
,
&
py_find_min_global
,
"This function is just like find_max_global(), except it performs minimization rather than maximization."
,
(
arg
(
"f"
),
arg
(
"bound1"
),
arg
(
"bound2"
),
arg
(
"is_integer_variable"
),
arg
(
"num_function_calls"
),
arg
(
"solver_epsilon"
)
=
0
)
);
}
{
def
(
"find_min_global"
,
&
py_find_min_global2
,
"This function simply calls the other version of find_min_global() with is_integer_variable set to False for all variables."
,
(
arg
(
"f"
),
arg
(
"bound1"
),
arg
(
"bound2"
),
arg
(
"num_function_calls"
),
arg
(
"solver_epsilon"
)
=
0
)
);
}
}
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