Skip to content
Snippets Groups Projects
Commit 041b976b authored by Elvira Clement's avatar Elvira Clement
Browse files

Robustify SIAM xp 1

parent 276c41dc
No related branches found
No related tags found
No related merge requests found
...@@ -19,7 +19,8 @@ def process(setup, log=True): ...@@ -19,7 +19,8 @@ def process(setup, log=True):
mat_nb_zero_detected = screenings['mat_nb_zero_detected'] mat_nb_zero_detected = screenings['mat_nb_zero_detected']
nb_test = mat_nb_zero_detected.shape[0] nb_test = mat_nb_zero_detected.shape[0]
list_tests = screenings["list_test"] list_tests = screenings["list_test"]
list_legends = screenings["list_legends"]
# ---- log ---- # ---- log ----
if log: if log:
...@@ -48,6 +49,7 @@ def process(setup, log=True): ...@@ -48,6 +49,7 @@ def process(setup, log=True):
return { return {
"mat_pc_detected": np.mean(mat_pc_detected, axis=5), "mat_pc_detected": np.mean(mat_pc_detected, axis=5),
"list_tests": list_tests, "list_tests": list_tests,
"list_legends": list_legends,
} }
# { # {
......
...@@ -120,7 +120,8 @@ for i_dic in range(setup.nb_dic): ...@@ -120,7 +120,8 @@ for i_dic in range(setup.nb_dic):
np.savez( np.savez(
screening_filename, screening_filename,
mat_nb_zero_detected=mat_nb_zero_detected, mat_nb_zero_detected=mat_nb_zero_detected,
list_test = [test.get_name() for test in list_tests], list_test = [test.get_name() for test in list_tests],
list_legends = [test.get_legend_name() for test in list_tests],
version = __version__, version = __version__,
allow_pickle=True allow_pickle=True
) )
\ No newline at end of file
# -*- coding: utf-8 -*-
import argparse
from pathlib import Path
import numpy as np
# XP import
from experiments.SIAM.slopepb import SlopePb
from experiments.SIAM.setup import Setup
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('--noverbose', help='disable printing if true', action="store_true")
parser.add_argument('--save', help='save figure', action="store_true")
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
if args.noshow:
matplotlib.use('PS')
else:
matplotlib.use("TkAgg")
import matplotlib.pyplot as plt
from matplotlib.legend_handler import HandlerBase
import matplotlib.font_manager as font_manager
# -------------------------
# Font stuff
# -------------------------
fs = 20
# -------------------------
# Load Results
# -------------------------
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
# -------------------------
i_dic = 0
i_lbd = 0
fs=22
fs_ylabels = 20
list_colors = ["tab:blue", "tab:orange", "tab:green"]
list_legends = dic_process_oscar["list_legends"]
# list_legends = ["$p_q=q\\;\\forall q$", "all", "$p_q=1\\;\\forall q$"]
# "best $r_q \\;\\forall q$ "
if not args.noverbose:
print("printing xp_0_ball parameters with")
print(f"- {setup_oscar.list_dic[i_dic]} dictionary")
print(f"- lbd / lbd_max = {setup_oscar.list_ratio_lbd[i_lbd]}")
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,
)
ax.set_ylabel(
"% of zero entries detected",
fontsize=fs+2,
)
for tick in ax.xaxis.get_major_ticks():
tick.label.set_fontsize(20)
for tick in ax.yaxis.get_major_ticks():
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]
)
ax.legend(
fontsize=fs-2,
)
ax.set_xscale("log")
ax.set_xlim([1e-6, 1e0])
ax.set_ylim([-2, 102])
if args.save:
folderfig = "figs"
Path(folderfig).mkdir(parents=True, exist_ok=True)
filename = folderfig + f"/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
...@@ -20,6 +20,11 @@ parser.add_argument('--id', help='setup id', type=str, default="SIAM") ...@@ -20,6 +20,11 @@ parser.add_argument('--id', help='setup id', type=str, default="SIAM")
parser.add_argument('--i_seq', type=int, default=0) parser.add_argument('--i_seq', type=int, default=0)
args=parser.parse_args() args=parser.parse_args()
if args.id != "SIAM":
raise Exception("this file has been created to reproduce the SIAM figures. Use the SIAM id instead")
import matplotlib import matplotlib
if args.noshow: if args.noshow:
matplotlib.use('PS') matplotlib.use('PS')
...@@ -84,12 +89,14 @@ i_lbd = 1 ...@@ -84,12 +89,14 @@ i_lbd = 1
fs=22 fs=22
fs_ylabels = 20 fs_ylabels = 20
list_colors = ["tab:blue", "tab:orange", "tab:green"] list_colors = ["tab:blue", "tab:orange", "tab:green"]
list_legends = ["$p_q=q\\;\\forall q$", "all", "$p_q=1\\;\\forall q$"] list_legends = dic_process_oscar["list_legends"]
# list_legends = ["$p_q=q\\;\\forall q$", "all", "$p_q=1\\;\\forall q$"]
# "best $r_q \\;\\forall q$ " # "best $r_q \\;\\forall q$ "
print("printing xp_0_ball parameters with") if not args.noverbose:
print(f"- {setup_oscar.list_dic[i_dic]} dictionary") print("printing xp_0_ball parameters with")
print(f"- lbd / lbd_max = {setup_oscar.list_ratio_lbd[i_lbd]}") print(f"- {setup_oscar.list_dic[i_dic]} dictionary")
print(f"- lbd / lbd_max = {setup_oscar.list_ratio_lbd[i_lbd]}")
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)
......
...@@ -19,6 +19,9 @@ parser.add_argument('--save', help='save figure', action="store_true") ...@@ -19,6 +19,9 @@ parser.add_argument('--save', help='save figure', action="store_true")
parser.add_argument('--id', help='setup id', type=str, default="SIAM") parser.add_argument('--id', help='setup id', type=str, default="SIAM")
args=parser.parse_args() args=parser.parse_args()
if args.id != "SIAM":
raise Exception("this file has been created to reproduce the SIAM figures. Use the SIAM id instead")
import matplotlib import matplotlib
if args.noshow: if args.noshow:
matplotlib.use("ps") matplotlib.use("ps")
...@@ -52,6 +55,7 @@ list_tests_oscar = dic_process_oscar["list_tests"] ...@@ -52,6 +55,7 @@ list_tests_oscar = dic_process_oscar["list_tests"]
i_dic = 0 i_dic = 0
i_lbd = 1 i_lbd = 1
n_lbd = len(setup_oscar.list_ratio_lbd)
fs=22 fs=22
fs_ylabels = 20 fs_ylabels = 20
...@@ -104,7 +108,7 @@ font_ttt = font_manager.FontProperties( ...@@ -104,7 +108,7 @@ font_ttt = font_manager.FontProperties(
size=fs+6 size=fs+6
) )
f, ax = plt.subplots(1, 3, figsize=(18, 6), sharex=True, sharey=True) f, ax = plt.subplots(1, n_lbd, figsize=(18, 6), sharex=True, sharey=True)
for i_seq, _ in enumerate(setup_oscar.list_sequence): for i_seq, _ in enumerate(setup_oscar.list_sequence):
...@@ -120,7 +124,7 @@ for i_seq, _ in enumerate(setup_oscar.list_sequence): ...@@ -120,7 +124,7 @@ for i_seq, _ in enumerate(setup_oscar.list_sequence):
tick.label.set_fontsize(18) tick.label.set_fontsize(18)
for i_lbd in range(3): for i_lbd in range(n_lbd):
ax[i_seq].plot( ax[i_seq].plot(
xpparams.vec_offsets, xpparams.vec_offsets,
100 * mat_pc_detected_oscar[i_test, :, i_dic, i_seq, i_lbd], 100 * mat_pc_detected_oscar[i_test, :, i_dic, i_seq, i_lbd],
...@@ -144,7 +148,7 @@ ax[0].set_ylabel( ...@@ -144,7 +148,7 @@ ax[0].set_ylabel(
fontsize=fs_ylabels+6, fontsize=fs_ylabels+6,
) )
ax[0].legend([object, object, object], ['$\\lambda / \\lambda_{\\max}=' + str(x) + '$' for x in [.3, .5, .8]], ax[0].legend([object, object, object], ['$\\lambda / \\lambda_{\\max}=' + str(x) + '$' for x in setup_oscar.list_ratio_lbd],
handler_map={object: AnyObjectHandler()}, handler_map={object: AnyObjectHandler()},
prop=font_math prop=font_math
) )
......
...@@ -9,11 +9,14 @@ class AbstractGapScreening(ABC): ...@@ -9,11 +9,14 @@ class AbstractGapScreening(ABC):
def __init__(self): def __init__(self):
super(AbstractGapScreening, self).__init__() super(AbstractGapScreening, self).__init__()
self.name = "NONAME" self.name = "void"
self.legend_name = "void"
def get_name(self): def get_name(self):
return self.name return self.name
def get_legend_name(self):
return self.legend_name
@abstractmethod @abstractmethod
def apply_test(self, Atu_abs, gap, lbd, vec_gammas, coeff_dual_scaling=1., offset_radius=0, index=None) -> np.ndarray: def apply_test(self, Atu_abs, gap, lbd, vec_gammas, coeff_dual_scaling=1., offset_radius=0, index=None) -> np.ndarray:
......
This diff is collapsed.
...@@ -58,6 +58,10 @@ cdef class GapTestAll: ...@@ -58,6 +58,10 @@ cdef class GapTestAll:
def get_name(self): def get_name(self):
return self.name return self.name
@cython.boundscheck(False) # turn off bounds-checking for entire function
@cython.wraparound(False) # turn off negative index wrapping for entire function
def get_legend_name(self):
return "all"
@cython.boundscheck(False) # turn off bounds-checking for entire function @cython.boundscheck(False) # turn off bounds-checking for entire function
# @cython.wraparound(False) # turn off negative index wrapping for entire function # @cython.wraparound(False) # turn off negative index wrapping for entire function
......
This diff is collapsed.
...@@ -86,6 +86,10 @@ cdef class GapTestPequalOne: ...@@ -86,6 +86,10 @@ cdef class GapTestPequalOne:
def get_name(self): def get_name(self):
return self.name return self.name
@cython.boundscheck(False) # turn off bounds-checking for entire function
@cython.wraparound(False) # turn off negative index wrapping for entire function
def get_legend_name(self):
return "$p_q=1\\;\\forall q$"
@cython.boundscheck(False) # turn off bounds-checking for entire function @cython.boundscheck(False) # turn off bounds-checking for entire function
@cython.wraparound(False) # turn off negative index wrapping for entire function @cython.wraparound(False) # turn off negative index wrapping for entire function
......
...@@ -11,6 +11,7 @@ class GapTestPequalQ(AbstractGapScreening): ...@@ -11,6 +11,7 @@ class GapTestPequalQ(AbstractGapScreening):
super(GapTestPequalQ, self).__init__() super(GapTestPequalQ, self).__init__()
self.name = "Gap test p=q" self.name = "Gap test p=q"
self.legend_name = "$p_q=q\\;\\forall q$"
def apply_test(self, Atu_abs, gap, lbd, vec_gammas, coeff_dual_scaling=1., offset_radius=0, index=None) -> np.ndarray: def apply_test(self, Atu_abs, gap, lbd, vec_gammas, coeff_dual_scaling=1., offset_radius=0, index=None) -> np.ndarray:
""" GAP Sphere screening test detailed in Cédric's node """ GAP Sphere screening test detailed in Cédric's node
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment