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
60a4af67
Commit
60a4af67
authored
Mar 17, 2018
by
Davis King
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added more unit tests
parent
2cff3f4e
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
1 deletion
+33
-1
test_global_optimization.py
tools/python/test/test_global_optimization.py
+33
-1
No files found.
tools/python/test/test_global_optimization.py
View file @
60a4af67
from
dlib
import
find_max_global
,
find_min_global
import
dlib
from
pytest
import
raises
from
math
import
sin
,
cos
,
pi
,
exp
,
sqrt
,
pow
def
test_global_optimization_nargs
():
...
...
@@ -23,9 +25,39 @@ def test_global_optimization_nargs():
find_min_global
(
lambda
a
,
b
,
c
,
d
,
*
args
:
0
,
[
0
,
0
,
0
],
[
1
,
1
,
1
],
10
)
def
F
(
a
,
b
):
return
-
pow
(
a
-
2
,
2.0
)
-
pow
(
b
-
4
,
2.0
);
def
G
(
x
):
return
2
-
pow
(
x
-
5
,
2.0
);
def
test_global_function_search
():
spec_F
=
dlib
.
function_spec
([
-
10
,
-
10
],
[
10
,
10
])
spec_G
=
dlib
.
function_spec
([
-
2
],
[
6
])
opt
=
dlib
.
global_function_search
([
spec_F
,
spec_G
])
for
i
in
range
(
15
):
next
=
opt
.
get_next_x
()
#print("next x is for function {} and has coordinates {}".format(next.function_idx, next.x))
if
(
next
.
function_idx
==
0
):
a
=
next
.
x
[
0
]
b
=
next
.
x
[
1
]
next
.
set
(
F
(
a
,
b
))
else
:
x
=
next
.
x
[
0
]
next
.
set
(
G
(
x
))
[
x
,
y
,
function_idx
]
=
opt
.
get_best_function_eval
()
#print("\nbest function was {}, with y of {}, and x of {}".format(function_idx,y,x))
assert
(
abs
(
y
-
2
)
<
1e-7
)
assert
(
abs
(
x
[
0
]
-
5
)
<
1e-7
)
assert
(
function_idx
==
1
)
from
math
import
sin
,
cos
,
pi
,
exp
,
sqrt
def
holder_table
(
x0
,
x1
):
return
-
abs
(
sin
(
x0
)
*
cos
(
x1
)
*
exp
(
abs
(
1
-
sqrt
(
x0
*
x0
+
x1
*
x1
)
/
pi
)))
...
...
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