Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Grégoire Grzeczkowicz
sho
Commits
451de15a
Commit
451de15a
authored
Nov 02, 2020
by
Grégoire Grzeczkowicz
Browse files
Try solver
parent
dc809607
Changes
4
Hide whitespace changes
Inline
Side-by-side
.gitignore
View file @
451de15a
__pycache__
*.csv
*.swp
*.json
draw_ert.py
View file @
451de15a
...
...
@@ -2,6 +2,7 @@
from
os
import
system
,
remove
,
path
import
matplotlib.pyplot
as
plt
import
numpy
as
np
import
json
########################################################################
# Interface
...
...
@@ -18,11 +19,12 @@ if __name__=="__main__":
can
.
add_argument
(
"-v"
,
"--for-value"
,
metavar
=
"NB"
,
type
=
int
,
help
=
"Print ERT with probabilities to obtain this value"
)
can
.
add_argument
(
"-save"
,
"--save-proba"
,
action
=
'store_true'
,
default
=
False
,
help
=
"Disable graphical output and save proba"
)
arg
=
can
.
parse_known_args
()
the
=
arg
[
0
]
print
(
the
)
# Minimum checks.
assert
(
0
<
the
.
nb_run
)
...
...
@@ -55,9 +57,9 @@ if __name__=="__main__":
if
line
[
0
]
==
1
:
if
len
(
attempt
)
>
0
:
data
.
append
(
attempt
)
current_best
=
float
(
"inf"
)
current_best
=
0
attempt
=
{}
if
line
[
1
]
<
current_best
:
if
line
[
1
]
>
current_best
:
attempt
[
line
[
0
]]
=
line
[
1
]
current_best
=
line
[
1
]
...
...
@@ -68,7 +70,7 @@ if __name__=="__main__":
for
attempt
in
data
:
good
=
False
for
t
,
v
in
attempt
.
items
():
if
t
<
time
and
v
<
value
:
if
t
<
time
and
v
>
value
:
good
=
True
break
if
good
:
...
...
@@ -78,7 +80,10 @@ if __name__=="__main__":
probability
=
np
.
vectorize
(
probability
,
excluded
=
[
0
])
# Plot
if
the
.
for_value
is
not
None
:
if
the
.
save_proba
:
with
open
(
'proba.json'
,
'w'
)
as
outfile
:
json
.
dump
(
data
,
outfile
)
elif
the
.
for_value
is
not
None
:
temps
=
np
.
linspace
(
0
,
temps_max
,
100
)
P
=
probability
(
data
,
temps
,
the
.
for_value
)
plt
.
plot
(
temps
,
P
)
...
...
@@ -94,4 +99,4 @@ if __name__=="__main__":
cbar
=
fig
.
colorbar
(
cs
)
plt
.
show
()
remove
(
'run.csv'
)
#
remove('run.csv')
snp.py
View file @
451de15a
...
...
@@ -86,7 +86,7 @@ if __name__=="__main__":
nb_it
=
the
.
iters
),
make
.
iter
(
iters
.
save
,
filename
=
the
.
output_file
+
".csv"
,
fmt
=
"{it} ; {val}
; {sol}
\n
"
),
fmt
=
"{it} ; {val}
\n
"
),
make
.
iter
(
iters
.
log
,
fmt
=
"
\r
{it} {val}"
),
make
.
iter
(
iters
.
history
,
...
...
try_solver.py
0 → 100644
View file @
451de15a
from
os
import
system
import
json
import
numpy
as
np
from
scipy.integrate
import
dblquad
import
matplotlib.pyplot
as
plt
Nb_run
=
5
solvers
=
[
'-m num_greedy -n 45 -i 20 -r 0.08 -t 10000 -w 100 -a 0.01'
,
'-m bit_greedy -n 45 -i 20 -r 0.08 -t 10000 -w 100 -a 0.01'
]
datas
=
[]
for
solver
in
solvers
:
print
(
"python3 draw_ert.py --nb-run "
+
str
(
Nb_run
)
+
" --save-proba "
+
solver
)
system
(
"python3 draw_ert.py --nb-run "
+
str
(
Nb_run
)
+
" --save-proba "
+
solver
)
with
open
(
'proba.json'
)
as
json_file
:
data
=
json
.
load
(
json_file
)
datas
.
append
(
data
)
temps_max
=
0
value_max
=
0
value_min
=
np
.
inf
for
data
in
datas
:
for
run
in
data
:
m
=
max
([
int
(
k
)
for
k
,
v
in
run
.
items
()])
if
m
>
temps_max
:
temps_max
=
m
m
=
max
([
v
for
k
,
v
in
run
.
items
()])
if
m
>
value_max
:
value_max
=
m
m
=
min
([
v
for
k
,
v
in
run
.
items
()])
if
m
<
value_min
:
value_min
=
m
def
probability
(
data
,
time
,
value
):
num
=
0
for
attempt
in
data
:
good
=
False
for
t
,
v
in
attempt
.
items
():
if
int
(
t
)
<
time
and
v
>
value
:
good
=
True
break
if
good
:
num
+=
1
return
num
/
len
(
data
)
probability
=
np
.
vectorize
(
probability
,
excluded
=
[
0
])
m
=
0
v
=
0
for
i
in
range
(
len
(
solvers
)):
volume
=
dblquad
(
lambda
x
,
y
:
probability
(
datas
[
i
],
x
,
y
),
value_min
,
value_max
,
0
,
temps_max
)[
0
]
print
(
solvers
[
i
])
print
(
volume
)
if
volume
>
v
:
m
=
i
v
=
volume
print
(
"Best solveur:"
)
print
(
solvers
[
m
])
\ No newline at end of file
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