Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Elvira Clement
slope-screening
Commits
bcbebe3d
Commit
bcbebe3d
authored
Apr 23, 2022
by
Elvira Clement
Browse files
Update xp1
parent
9df53a47
Changes
4
Hide whitespace changes
Inline
Side-by-side
experiments/SIAM/xp_1_balls/xp_a_accuracy_sol.py
View file @
bcbebe3d
# -*- coding: utf-8 -*-
import
time
,
argparse
,
sys
from
pathlib
import
Path
import
numpy
as
np
...
...
@@ -14,8 +13,7 @@ from src.utils import get_lambda_max, gamma_sequence_generator
from
src.dictionaries
import
generate_dic
# Screening
from
src.screening.singletest
import
GapSphereSingleTest
from
src.screening.gap_ptest
import
GAP_Ptest
from
src.screening.gap_test_all
import
GapTestAll
# XP import
from
experiments.SIAM.slopepb
import
SlopePb
...
...
@@ -26,7 +24,7 @@ parser=argparse.ArgumentParser()
parser
.
add_argument
(
'--erase'
,
help
=
'erase existing results'
,
action
=
"store_true"
)
parser
.
add_argument
(
'--continue'
,
help
=
'save figure'
,
action
=
"store_true"
,
dest
=
"cont"
)
parser
.
add_argument
(
'--id'
,
help
=
'setup id'
,
type
=
str
,
default
=
"1a"
)
default
=
1
)
args
=
parser
.
parse_args
()
...
...
@@ -35,10 +33,7 @@ args=parser.parse_args()
# -------------------------
setup
=
Setup
(
args
.
id
)
folder
=
"results/"
Path
(
folder
).
mkdir
(
parents
=
True
,
exist_ok
=
True
)
out_file_name
=
folder
+
f
"/xp_setup
{
args
.
id
}
.npz"
out_file_name
=
f
"results/xp_setup
{
args
.
id
}
.npz"
mat_seed
=
np
.
random
.
randint
(
0
,
2
**
32
-
1
,
...
...
@@ -131,19 +126,21 @@ for i_dic in range(setup.nb_dic):
params
.
max_it
=
1e7
params
.
gap_stopping
=
xpparams
.
stopping_gap
params
.
time_stopping
=
np
.
inf
params
.
screening1
=
Gap
SphereSingleTest
(
)
params
.
screening2
=
GAP_Ptest
(
vec_gammas
)
params
.
screening_it_div
=
2.
params
.
screening1
=
Gap
TestAll
(
vec_gammas
)
params
.
eval_gap
=
True
params
.
eval_gap_it
=
setup
.
eval_gap_it
params
.
accelerated
=
True
params
.
verbose
=
False
out_slope
=
slope_gp
(
vecy
,
matA
,
ratio
*
lbd_max
,
vec_gammas
,
params
)
gap
=
slopePb
.
eval_gap
(
out_slope
[
"sol"
],
out_slope
[
"dualsol"
])
dv
=
vecy
-
matA
@
out_slope
[
"sol"
]
dv
=
slopePb
.
make_dual_scaling
(
dv
)
gap
=
slopePb
.
eval_gap
(
out_slope
[
"sol"
],
dv
)
if
gap
<=
gap_old
:
mat_pvopt
[
i_dic
,
i_seq
,
i_ratio
,
rep
,
:]
=
out_slope
[
"sol"
]
mat_dvopt
[
i_dic
,
i_seq
,
i_ratio
,
rep
,
:]
=
out_slope
[
"dualsol"
]
mat_dvopt
[
i_dic
,
i_seq
,
i_ratio
,
rep
,
:]
=
dv
# Save
np
.
savez
(
out_file_name
,
...
...
experiments/SIAM/xp_1_balls/xp_b_screening.py
View file @
bcbebe3d
# -*- coding: utf-8 -*-
import
argparse
from
pathlib
import
Path
import
numpy
as
np
...
...
@@ -10,10 +9,9 @@ from src.dictionaries import generate_dic
from
src.utils
import
get_lambda_max
,
gamma_sequence_generator
# Screening
from
src.screening.gap_rqtest
import
GAP_RQtest
from
src.screening.kappa_test
import
Kappa_test
from
src.screening.singletest
import
GapSphereSingleTest
from
src.screening.gap_ptest
import
GAP_Ptest
from
src.screening.gap_test_p_1
import
GapTestPequalOne
from
src.screening.gap_test_p_q
import
GapTestPequalQ
from
src.screening.gap_test_all
import
GapTestAll
# XP import
from
experiments.SIAM.slopepb
import
SlopePb
...
...
@@ -103,14 +101,12 @@ for i_dic in range(setup.nb_dic):
# ---- 3c. Testing sphere ----
list_tests
=
[
# GAP_RQtest(vec_gammas, 1 + np.arange(setup.n)),
Kappa_test
(
vec_gammas
,
np
.
arange
(
setup
.
n
,
dtype
=
float
)),
GapSphereSingleTest
(),
GAP_Ptest
(
vec_gammas
),
GapTestPequalOne
(
vec_gammas
,
np
.
arange
(
setup
.
n
,
dtype
=
np
.
double
)),
GapTestPequalQ
(),
GapTestAll
(
vec_gammas
),
]
assert
(
len
(
list_tests
)
==
NB_TEST
)
for
i_offset
,
offset
in
enumerate
(
xpparams
.
vec_offsets
):
for
i_test
,
test
in
enumerate
(
list_tests
):
out
=
test
.
apply_test
(
np
.
abs
(
Atu
),
gap
,
ratio
*
lbd_max
,
vec_gammas
,
offset_radius
=
offset
)
...
...
experiments/SIAM/xp_1_balls/xp_c_viz_fig1.py
View file @
bcbebe3d
# -*- coding: utf-8 -*-
from
decimal
import
Decimal
import
json
,
argparse
from
pathlib
import
Path
import
argparse
import
numpy
as
np
# XP import
from
experiments.SIAM.slopepb
import
SlopePb
from
experiments.SIAM.setup
import
Setup
from
experiments.SIAM.xp_1_balls
import
xpparams
from
experiments.SIAM.xp_1_balls.process_data
import
process
import
xpparams
from
process_data
import
process
parser
=
argparse
.
ArgumentParser
()
parser
.
add_argument
(
'--noshow'
,
help
=
'do not display figures'
,
action
=
"store_true"
)
parser
.
add_argument
(
'--save'
,
help
=
'save figure'
,
action
=
"store_true"
)
# parser.add_argument('--id', help='setup id', type=str, default=1)
parser
.
add_argument
(
'--id'
,
help
=
'setup id'
,
type
=
str
,
default
=
"SIAM"
)
parser
.
add_argument
(
'--i_seq'
,
type
=
int
,
default
=
0
)
args
=
parser
.
parse_args
()
import
matplotlib
...
...
@@ -52,7 +52,7 @@ font_text = font_manager.FontProperties(
font_ttt
=
font_manager
.
FontProperties
(
# fname='../fonts/ectt1000.ttf',
fname
=
'../fonts/cmuntt.ttf'
,
fname
=
'../fonts/
computer-modern/
cmuntt.ttf'
,
weight
=
'bold'
,
style
=
'normal'
,
size
=
fs
...
...
@@ -63,14 +63,15 @@ font_ttt = font_manager.FontProperties(
# Load Results
# -------------------------
# OSCAR
setup_oscar
=
Setup
(
"1a"
)
setup_oscar
=
Setup
(
args
.
id
)
dic_process_oscar
=
process
(
setup_oscar
)
mat_pc_detected_oscar
=
dic_process_oscar
[
"mat_pc_detected"
]
list_tests_oscar
=
dic_process_oscar
[
"list_tests"
]
# -------------------------
# Plot Results
# -------------------------
...
...
@@ -81,63 +82,58 @@ i_lbd = 1
fs
=
22
fs_ylabels
=
20
list_colors
=
[
"tab:blue"
,
"tab:orange"
,
"tab:green"
]
list_legends
=
[
"$
r
_q=q
\\
;
\\
forall q$"
,
"
best performance
"
,
"$
r
_q=1
\\
;
\\
forall q$"
]
list_legends
=
[
"$
p
_q=q
\\
;
\\
forall q$"
,
"
all
"
,
"$
p
_q=1
\\
;
\\
forall q$"
]
# "best $r_q \\;\\forall q$ "
print
(
"printing xp_0_ball parameters with"
)
print
(
" - OSCAR sequence"
)
print
(
f
"-
{
setup_oscar
.
list_dic
[
i_dic
]
}
dictionary"
)
print
(
f
"- lbd / lbd_max =
{
setup_oscar
.
list_ratio_lbd
[
i_lbd
]
}
"
)
for
i_seq
in
range
(
2
):
f
,
ax
=
plt
.
subplots
(
1
,
1
,
figsize
=
(.
7
*
16
,
.
6
*
9
),
sharex
=
True
,
sharey
=
True
)
f
,
ax
=
plt
.
subplots
(
1
,
1
,
figsize
=
(.
7
*
16
,
.
6
*
9
),
sharex
=
True
,
sharey
=
True
)
# ax.set_title(f"OSCAR-{i_seq+1}", fontsize=fs+2)
ax
.
set_xlabel
(
r
"$R$"
,
fontsize
=
fs
+
2
,
fontproperties
=
font_math
,
)
ax
.
set_ylabel
(
"% of zero entries detected"
,
fontsize
=
fs
+
2
,
fontproperties
=
font_text
# ax.set_title(f"OSCAR-{i_seq+1}", fontsize=fs+2)
ax
.
set_xlabel
(
r
"$R$"
,
fontsize
=
fs
+
2
,
fontproperties
=
font_math
,
)
ax
.
set_ylabel
(
"% of zero entries detected"
,
fontsize
=
fs
+
2
,
fontproperties
=
font_text
)
for
tick
in
ax
.
xaxis
.
get_major_ticks
():
tick
.
label
.
set_fontproperties
(
font_math
)
tick
.
label
.
set_fontsize
(
20
)
for
tick
in
ax
.
yaxis
.
get_major_ticks
():
tick
.
label
.
set_fontproperties
(
font_math
)
tick
.
label
.
set_fontsize
(
20
)
for
i_test
in
[
2
,
0
,
1
]:
ax
.
plot
(
xpparams
.
vec_offsets
,
100
*
mat_pc_detected_oscar
[
i_test
,
:,
i_dic
,
args
.
i_seq
,
i_lbd
],
label
=
list_legends
[
i_test
],
linewidth
=
4.
,
alpha
=
.
9
,
color
=
list_colors
[
i_test
]
)
for
tick
in
ax
.
xaxis
.
get_major_ticks
():
tick
.
label
.
set_fontproperties
(
font_math
)
tick
.
label
.
set_fontsize
(
20
)
for
tick
in
ax
.
yaxis
.
get_major_ticks
():
tick
.
label
.
set_fontproperties
(
font_math
)
tick
.
label
.
set_fontsize
(
20
)
for
i_test
in
[
2
,
0
,
1
]:
ax
.
plot
(
xpparams
.
vec_offsets
,
100
*
mat_pc_detected_oscar
[
i_test
,
:,
i_dic
,
i_seq
,
i_lbd
],
label
=
list_legends
[
i_test
],
linewidth
=
4.
,
alpha
=
.
9
,
color
=
list_colors
[
i_test
]
)
if
i_seq
==
0
:
ax
.
legend
(
fontsize
=
fs
-
2
,
prop
=
font_math
)
ax
.
set_xscale
(
"log"
)
ax
.
set_xlim
([
1e-6
,
1e0
])
ax
.
set_ylim
([
-
2
,
102
])
if
args
.
save
:
Path
(
"figs/"
).
mkdir
(
parents
=
True
,
exist_ok
=
True
)
filename
=
f
"figs/xp_illustration_screening
{
i_seq
}
.eps"
plt
.
savefig
(
filename
,
bbox_inches
=
'tight'
)
ax
.
legend
(
fontsize
=
fs
-
2
,
prop
=
font_math
)
ax
.
set_xscale
(
"log"
)
ax
.
set_xlim
([
1e-6
,
1e0
])
ax
.
set_ylim
([
-
2
,
102
])
if
args
.
save
:
filename
=
f
"figs/xp_illustration_screening
{
args
.
i_seq
}
.eps"
plt
.
savefig
(
filename
,
bbox_inches
=
'tight'
)
if
not
args
.
noshow
:
plt
.
show
()
\ No newline at end of file
experiments/SIAM/xp_1_balls/xp_c_viz_fig2.py
View file @
bcbebe3d
# -*- coding: utf-8 -*-
from
decimal
import
Decimal
import
json
,
argparse
from
pathlib
import
Path
import
argparse
import
numpy
as
np
# XP import
from
experiments.SIAM.slopepb
import
SlopePb
from
experiments.SIAM.setup
import
Setup
from
experiments.SIAM.xp_1_balls
import
xpparams
from
experiments.SIAM.xp_1_balls.process_data
import
process
import
xpparams
from
process_data
import
process
parser
=
argparse
.
ArgumentParser
()
parser
.
add_argument
(
'--noshow'
,
help
=
'do not display figures'
,
action
=
"store_true"
)
parser
.
add_argument
(
'--save'
,
help
=
'save figure'
,
action
=
"store_true"
)
#
parser.add_argument('--id', help='setup id', type=str, default=
1
)
parser
.
add_argument
(
'--id'
,
help
=
'setup id'
,
type
=
str
,
default
=
"SIAM"
)
args
=
parser
.
parse_args
()
import
matplotlib
...
...
@@ -26,14 +25,15 @@ else:
import
matplotlib.pyplot
as
plt
from
matplotlib.legend_handler
import
HandlerBase
import
matplotlib.font_manager
as
font_manager
# print(matplotlib.get_backend())
# matplotlib.rc('pdf', fonttype=42)
# -------------------------
# Load Results
# -------------------------
# OSCAR
setup_oscar
=
Setup
(
"1a"
)
setup_oscar
=
Setup
(
args
.
id
)
dic_process_oscar
=
process
(
setup_oscar
)
mat_pc_detected_oscar
=
dic_process_oscar
[
"mat_pc_detected"
]
...
...
@@ -153,7 +153,7 @@ f.tight_layout()
for
i_seq
in
range
(
3
):
ax
[
i_seq
].
set_xlabel
(
"$R$"
,
fontproperties
=
font_math
,
fontsize
=
fs_ylabels
+
6
)
ax
[
i_seq
].
set_xlabel
(
"$R
_0
$"
,
fontproperties
=
font_math
,
fontsize
=
fs_ylabels
+
6
)
# ax[1, i_seq].xaxis.set_major_locator(plt.MaxNLocator(6))
...
...
@@ -165,7 +165,11 @@ for i_seq in range(3):
tick
.
label
.
set_fontproperties
(
font_math
)
tick
.
label
.
set_fontsize
(
22
)
# plt.show()
# exit()
if
args
.
save
:
filename
=
f
"figs/xp0_
{
setup_oscar
.
list_dic
[
i_dic
]
}
.eps"
# plt.rcParams['pdf.fonttype'] = 42
plt
.
savefig
(
filename
,
bbox_inches
=
'tight'
)
\ No newline at end of file
plt
.
savefig
(
filename
,
bbox_inches
=
'tight'
)
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