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

Modifications experiments

parent 572ba617
No related branches found
No related tags found
No related merge requests found
Pipeline #13224 failed
python viz_paper.py --id 1a --precision 8 --noshow --save
python viz_paper_it.py --id 1a --precision 8 --noshow --save
\ No newline at end of file
# -*- coding: utf-8 -*-
import argparse
import numpy as np
import matplotlib.pyplot as plt
from xps.SIAM.setup import Setup
from process_data import process
from get_algs_params import get_alg_params, get_nb_algs
from src.utils import gamma_sequence_generator
parser=argparse.ArgumentParser()
parser.add_argument('--id', help='setup id', type=str)
parser.add_argument('--precision', help='stop when gap reaches 1e-precision', default=8)
parser.add_argument('--exact', action="store_true")
parser.add_argument('--noshow', help='show plots', action="store_true")
parser.add_argument('--save', help='save figure', action="store_true")
args=parser.parse_args()
# -------------------------
# Load results
# -------------------------
folder = f'results/1e-{args.precision}'
folder += 'exact/' if args.exact else 'gersh/'
setup = Setup(args.id)
_, list_names = get_alg_params(setup, np.zeros(5), args.exact)
dic_process = process(folder, True, setup)
vec_tau = dic_process["vec_tau"]
results_rho = dic_process["results_rho"]
# -------------------------
# Plot results
# -------------------------
f, ax = plt.subplots(1, setup.nb_dic, figsize=(16, 4.),
sharex=True, sharey=True,
gridspec_kw = {'wspace':.05, 'hspace':.05}
)
list_algnames = ["PG", "PG$_s$", "PG$_p$"]
list_dicname = ["Gaussian", "Uniform", "toeplitz"]
i_lbd = 1
i_dic = 0
print("ploting it fig for")
print(f" - {list_dicname[i_dic]} dictionary")
print(f" - lbd / lbd_max = {setup.list_ratio_lbd[i_lbd]}")
for i_seq in range(setup.nb_sequence):
list_colors = ["tab:blue", "tab:orange", "tab:green"]
for i_alg in range(len(list_names)):
ax[i_seq].plot(
vec_tau,
100. * results_rho[i_alg, i_dic, i_seq, i_lbd],
linewidth=3.,
label=list_algnames[i_alg],
color=list_colors[i_alg],
linestyle='-.'
)
ax[i_seq].set_title(f"OSCAR-{i_seq+1}", fontsize=16)
ax[i_seq].set_xscale('log')
ax[i_seq].set_xlim([5e-15, 5e-5])
ax[i_seq].set_ylim([-2, 101])
ax[i_seq].grid()
if i_seq == 0 :
ax[i_seq].legend()
ax[i_seq].set_xlabel("$\\tau$ (Dual gap)", fontsize=14)
if i_seq == 0:
ax[i_seq].set_ylabel("$\\rho_s(\\tau)$", fontsize=14)
if args.save:
fig_name = f"figs/setup{args.id}_it"
plt.savefig(fig_name + ".pdf", bbox_inches='tight')
if not args.noshow:
plt.show()
import time
import numpy as np
from src.utils import get_lambda_max
def test_increasing_ball(list_tests, vec_offsets, slopepb, vecx):
nb_test = len(list_tests)
mat_out = np.zeros((nb_test, vec_offsets.size))
vecu, Atu, gap = slopepb.make_screening_quanties(
vecx
)
list_time = [0 for i in range(nb_test)]
# Boucle
for i_offset, offset in enumerate(vec_offsets):
for i_test, test in enumerate(list_tests):
# Test
t_start = time.time()
out = test.apply_test(
np.abs(Atu),
gap,
slopepb.lbd,
slopepb.vec_gammas,
offset_radius=offset
)
list_time[i_test] += time.time() - t_start
# save
mat_out[i_test, i_offset] = np.sum(out)
# out
return mat_out, list_time
\ No newline at end of file
import numpy as np
from src.slope import primal_func, dual_func
from src.utils import get_lambda_max
class SlopePb(object):
"""docstring for SlopePb"""
def __init__(self, matA, vecy, vec_gammas, ratio_lbd, lbdmax=None):
super(SlopePb, self).__init__()
self.matA = matA
self.vecy = vecy
self.vec_gammas = vec_gammas
self.ratio_lbd = ratio_lbd
if lbdmax is None:
self.lbdmax = get_lambda_max(vecy, matA, vec_gammas)
else:
self.lbdmax = lbdmax
self.lbd = ratio_lbd * self.lbdmax
def make_dual_scaling(self, vecr):
beta_dual = np.sort(np.abs(self.matA.T @ vecr))[::-1]
beta_dual = np.cumsum(beta_dual) / \
np.cumsum(self.lbd * self.vec_gammas)
return vecr / np.max(beta_dual)
def make_screening_quanties(self, vecx):
"""
"""
# residual error
vecu = self.vecy - self.matA @ vecx
# dual scaling
vecu = self.make_dual_scaling(vecu)
pval = primal_func(self.vecy, self.matA @ vecx, vecx,
self.lbd, self.vec_gammas
)
dval = dual_func(self.vecy,
np.linalg.norm(self.vecy, 2)**2, vecu
)
gap = np.abs(pval - dval)
Atu = self.matA.T @ vecu
return vecu, Atu, gap
def eval_gap(self, vecx):
"""
"""
# residual error
vecu = self.vecy - self.matA @ vecx
# dual scaling
vecu = self.make_dual_scaling(vecu)
pval = primal_func(self.vecy, self.matA @ vecx, vecx,
self.lbd, self.vec_gammas
)
dval = dual_func(self.vecy,
np.linalg.norm(self.vecy, 2)**2, vecu
)
return np.abs(pval - dval)
\ No newline at end of file
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