Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
BayesianOptimization
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
shamith2
BayesianOptimization
Commits
60ea0eae
Commit
60ea0eae
authored
5 years ago
by
shamith2
Browse files
Options
Downloads
Patches
Plain Diff
Update compare.py
parent
cceab1af
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
compare.py
+120
-121
120 additions, 121 deletions
compare.py
with
120 additions
and
121 deletions
compare.py
+
120
−
121
View file @
60ea0eae
import
sys
from
matplotlib
import
pyplot
as
my_plt
from
matplotlib
import
patches
as
my_patch
import
numpy
as
np
import
pickle
import
json
import
pandas
as
pd
import
subprocess
from
HyperSphere.BO.run_BO
import
BO
from
fmfnBO.runBO
import
fmfnBO
from
HyperSphere.test_functions.benchmarks
import
*
from
target
import
*
def
compare_plots
(
hs_files
,
fmfn_files
):
# data file
data_config_filename
=
hs_files
+
'
/data_config.pkl
'
f_name
,
log_file
,
plot_file
=
fmfn_files
# HyperSphere
with
open
(
data_config_filename
,
'
rb
'
)
as
data_config_file
:
for
key
,
val
in
pickle
.
load
(
data_config_file
).
items
():
if
key
==
'
output
'
:
y1
=
val
.
data
.
numpy
()
if
key
==
'
x_input
'
:
x1
=
val
.
data
.
numpy
()
x1
=
x1
[:,
0
]
# fmfn/BayesianOptimization
# read from file
with
open
(
log_file
,
"
r
"
)
as
f
:
file_data
=
f
.
read
()
# add trailing commas for each line
with
open
(
log_file
,
"
r
"
)
as
f
:
lines
=
f
.
readlines
()
first_line
=
lines
[
0
]
file_lines
=
[
''
.
join
([
'
,
'
,
line
.
strip
(),
'
\n
'
])
for
line
in
lines
[
1
:]]
# encaspulate the data
with
open
(
plot_file
,
"
w+
"
)
as
f
:
f
.
write
(
'
{
'
+
'
\n
'
+
'
'
+
'"
logs
"'
+
'
:
'
+
'
'
+
'
[
'
+
'
\n
'
)
f
.
writelines
(
first_line
)
f
.
writelines
(
file_lines
)
f
.
write
(
"
"
+
"
]
"
+
"
\n
"
+
"
}
"
)
# load data for visualization
with
open
(
plot_file
)
as
json_file
:
data
=
pd
.
DataFrame
(
json
.
load
(
json_file
)[
'
logs
'
])
_x
=
data
[
'
params
'
].
to_list
()
dim
=
len
(
_x
[
0
].
values
())
x_list
=
[[]
for
i
in
range
(
dim
)]
for
x_
in
_x
:
for
i
in
range
(
dim
):
x_list
[
i
].
append
(
tuple
(
x_
.
values
())[
i
])
x_n_eval
=
np
.
arange
(
1
,
len
(
lines
)
+
1
,
1
)
# x_input
x2
=
x_list
[
0
]
# y = f(x)
y2
=
data
[
'
target
'
].
to_numpy
()
# visualization
my_plt
.
figure
(
'
HyperSphere vs fmfn
'
)
my_plt
.
title
(
f
"
function =
{
f_name
}
:: evaluations = 50
"
)
red
=
my_patch
.
Patch
(
color
=
'
red
'
,
label
=
'
HyperSphere
'
)
blue
=
my_patch
.
Patch
(
color
=
'
blue
'
,
label
=
'
fmfn
'
)
my_plt
.
legend
(
handles
=
[
red
,
blue
])
my_plt
.
plot
(
x1
,
y1
,
'
r
'
)
my_plt
.
plot
(
x2
,
y2
,
'
b
'
)
my_plt
.
axhline
(
y
=-
106.76
)
# optima
my_plt
.
show
()
if
__name__
==
'
__main__
'
:
# parameters
geometry
=
'
sphere
'
func
=
'
birdy
'
fmfn_func
=
'
neg_birdy
'
d
=
'
2
'
e
=
'
50
'
# subprocess
hs
=
subprocess
.
Popen
(
args
=
[
'
python
'
,
'
HyperSphere/BO/run_BO.py
'
,
'
-g
'
,
geometry
,
'
--parallel
'
,
'
-f
'
,
func
,
'
-d
'
,
d
,
'
-e
'
,
e
],
stdout
=
subprocess
.
PIPE
,
universal_newlines
=
True
)
while
True
:
output
=
hs
.
stdout
.
readline
()
if
output
not
in
[
'
'
,
'
\n
'
,
''
]:
hs_files
=
output
print
(
output
.
strip
())
return_code
=
hs
.
poll
()
if
return_code
is
not
None
:
break
fmfn
=
subprocess
.
Popen
(
args
=
[
'
python
'
,
'
fmfnBO/runBO.py
'
,
'
-f
'
,
str
(
fmfn_func
),
'
-d
'
,
str
(
d
),
'
-e
'
,
str
(
e
)],
stdout
=
subprocess
.
PIPE
,
universal_newlines
=
True
)
while
True
:
output
=
fmfn
.
stdout
.
readline
()
if
output
not
in
[
'
'
,
'
\n
'
,
''
]:
fmfn_files
=
output
print
(
output
.
strip
())
return_code
=
fmfn
.
poll
()
if
return_code
is
not
None
:
break
# clean up hs_files
hs_files
=
hs_files
.
strip
(
'
\n
'
)
# clean up fmfn_files
fmfn_files
=
[
line
.
strip
().
strip
(
"
(
"
).
strip
(
"
)
"
).
strip
(
"'"
)
for
line
in
fmfn_files
.
strip
(
"
\n
"
).
split
(
"
,
"
)]
# compare
compare_plots
(
hs_files
,
fmfn_files
)
import
sys
from
matplotlib
import
pyplot
as
my_plt
from
matplotlib
import
patches
as
my_patch
import
numpy
as
np
import
pickle
import
json
import
pandas
as
pd
import
subprocess
from
HyperSphere.BO.run_BO
import
BO
from
fmfnBO.runBO
import
fmfnBO
from
HyperSphere.test_functions.benchmarks
import
*
from
target
import
*
def
compare_plots
(
hs_files
,
fmfn_files
):
# data file
data_config_filename
=
hs_files
+
'
/data_config.pkl
'
f_name
,
log_file
,
plot_file
=
fmfn_files
# HyperSphere
with
open
(
data_config_filename
,
'
rb
'
)
as
data_config_file
:
for
key
,
val
in
pickle
.
load
(
data_config_file
).
items
():
if
key
==
'
output
'
:
y1
=
val
.
data
.
numpy
()
if
key
==
'
x_input
'
:
x1
=
val
.
data
.
numpy
()
x1
=
x1
[:,
0
]
# fmfn/BayesianOptimization
# read from file
with
open
(
log_file
,
"
r
"
)
as
f
:
file_data
=
f
.
read
()
# add trailing commas for each line
with
open
(
log_file
,
"
r
"
)
as
f
:
lines
=
f
.
readlines
()
first_line
=
lines
[
0
]
file_lines
=
[
''
.
join
([
'
,
'
,
line
.
strip
(),
'
\n
'
])
for
line
in
lines
[
1
:]]
# encaspulate the data
with
open
(
plot_file
,
"
w+
"
)
as
f
:
f
.
write
(
'
{
'
+
'
\n
'
+
'
'
+
'"
logs
"'
+
'
:
'
+
'
'
+
'
[
'
+
'
\n
'
)
f
.
writelines
(
first_line
)
f
.
writelines
(
file_lines
)
f
.
write
(
"
"
+
"
]
"
+
"
\n
"
+
"
}
"
)
# load data for visualization
with
open
(
plot_file
)
as
json_file
:
data
=
pd
.
DataFrame
(
json
.
load
(
json_file
)[
'
logs
'
])
_x
=
data
[
'
params
'
].
to_list
()
dim
=
len
(
_x
[
0
].
values
())
x_list
=
[[]
for
i
in
range
(
dim
)]
for
x_
in
_x
:
for
i
in
range
(
dim
):
x_list
[
i
].
append
(
tuple
(
x_
.
values
())[
i
])
x_n_eval
=
np
.
arange
(
1
,
len
(
lines
)
+
1
,
1
)
# x_input
x2
=
x_list
[
0
]
# y = f(x)
y2
=
data
[
'
target
'
].
to_numpy
()
# visualization
my_plt
.
figure
(
'
HyperSphere vs fmfn
'
)
my_plt
.
title
(
f
"
function =
{
f_name
}
:: evaluations = 50
"
)
red
=
my_patch
.
Patch
(
color
=
'
red
'
,
label
=
'
HyperSphere
'
)
blue
=
my_patch
.
Patch
(
color
=
'
blue
'
,
label
=
'
fmfn
'
)
my_plt
.
legend
(
handles
=
[
red
,
blue
])
my_plt
.
plot
(
x1
,
y1
,
'
r
'
)
my_plt
.
plot
(
x2
,
y2
,
'
b
'
)
my_plt
.
axhline
(
y
=-
106.76
)
# optima
my_plt
.
show
()
if
__name__
==
'
__main__
'
:
# parameters
geometry
=
'
cube
'
func
=
'
birdy
'
d
=
'
2
'
e
=
'
50
'
# subprocess
hs
=
subprocess
.
Popen
(
args
=
[
'
python
'
,
'
HyperSphere/BO/run_BO.py
'
,
'
-g
'
,
geometry
,
'
--parallel
'
,
'
-f
'
,
func
,
'
-d
'
,
d
,
'
-e
'
,
e
],
stdout
=
subprocess
.
PIPE
,
universal_newlines
=
True
)
while
True
:
output
=
hs
.
stdout
.
readline
()
if
output
not
in
[
'
'
,
'
\n
'
,
''
]:
hs_files
=
output
print
(
output
.
strip
())
return_code
=
hs
.
poll
()
if
return_code
is
not
None
:
break
fmfn
=
subprocess
.
Popen
(
args
=
[
'
python
'
,
'
fmfnBO/runBO.py
'
,
'
-f
'
,
str
(
func
),
'
-d
'
,
str
(
d
),
'
-e
'
,
str
(
e
)],
stdout
=
subprocess
.
PIPE
,
universal_newlines
=
True
)
while
True
:
output
=
fmfn
.
stdout
.
readline
()
if
output
not
in
[
'
'
,
'
\n
'
,
''
]:
fmfn_files
=
output
print
(
output
.
strip
())
return_code
=
fmfn
.
poll
()
if
return_code
is
not
None
:
break
# clean up hs_files
hs_files
=
hs_files
.
strip
(
'
\n
'
)
# clean up fmfn_files
fmfn_files
=
[
line
.
strip
().
strip
(
"
(
"
).
strip
(
"
)
"
).
strip
(
"'"
)
for
line
in
fmfn_files
.
strip
(
"
\n
"
).
split
(
"
,
"
)]
# compare
compare_plots
(
hs_files
,
fmfn_files
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment