Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH - Add Pinball datafit #134

Merged
merged 31 commits into from
Dec 9, 2022
Merged
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
413ef54
remove sqrt n_samples
Badr-MOUFAD Nov 30, 2022
2ef5eb7
update unittest
Badr-MOUFAD Nov 30, 2022
5c0bedc
info comment statsmodels
Badr-MOUFAD Dec 1, 2022
ca6ece7
add prox subdiff to sqrt df
Badr-MOUFAD Dec 1, 2022
a6303e5
implement ``PDCD_WS``
Badr-MOUFAD Dec 1, 2022
e8fcee3
r sqrt_n from CB
Badr-MOUFAD Dec 1, 2022
339e98f
Merge branch 'r-sqrt-n' of https://github.com/Badr-MOUFAD/skglm into …
Badr-MOUFAD Dec 1, 2022
19a0ea9
bug w and subdiff
Badr-MOUFAD Dec 1, 2022
e01451d
unittest sqrt
Badr-MOUFAD Dec 1, 2022
dd36b88
add docs
Badr-MOUFAD Dec 1, 2022
523419b
fix docs SqrtQuadratic
Badr-MOUFAD Dec 1, 2022
71de179
Merge branch 'main' of https://github.com/scikit-learn-contrib/skglm …
Badr-MOUFAD Dec 2, 2022
63a547b
subdiff --> fixed_point
Badr-MOUFAD Dec 4, 2022
f78d17d
efficient prox conjugate && fix tests
Badr-MOUFAD Dec 5, 2022
d0ae3a4
remove go
Badr-MOUFAD Dec 5, 2022
ad36485
MM remarks
Badr-MOUFAD Dec 5, 2022
f60bd59
fix test && clean ups
Badr-MOUFAD Dec 5, 2022
5a5f1ba
MM round 2 remarks
Badr-MOUFAD Dec 5, 2022
4f27c56
CI Trigger
Badr-MOUFAD Dec 5, 2022
fe45faa
implement pinball
Badr-MOUFAD Dec 6, 2022
3ce886f
unittest
Badr-MOUFAD Dec 6, 2022
6928502
fix pinball value && ST step
Badr-MOUFAD Dec 6, 2022
1271288
more unittest
Badr-MOUFAD Dec 6, 2022
bd1984a
fix bug prox pinball
Badr-MOUFAD Dec 6, 2022
36100c7
Merge branch 'main' of https://github.com/scikit-learn-contrib/skglm …
Badr-MOUFAD Dec 8, 2022
1a03c60
MM remarks
Badr-MOUFAD Dec 8, 2022
4b3ea45
Update skglm/experimental/quantile_regression.py
mathurinm Dec 8, 2022
9cf2216
pinball expression
Badr-MOUFAD Dec 8, 2022
626b71d
Merge branch 'pinball-df' of https://github.com/Badr-MOUFAD/skglm int…
Badr-MOUFAD Dec 8, 2022
8e93720
sqrt --> pinball
Badr-MOUFAD Dec 8, 2022
0a247f0
quantile --> quantile_level
Badr-MOUFAD Dec 9, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
MM remarks
  • Loading branch information
Badr-MOUFAD committed Dec 5, 2022
commit ad364852ce5599770cab5c82b156edf46ffd862d
74 changes: 40 additions & 34 deletions skglm/experimental/pdcd_ws.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,33 +9,42 @@


class PDCD_WS:
Badr-MOUFAD marked this conversation as resolved.
Show resolved Hide resolved
"""Primal-Dual Coordinate Descent solver with working sets.
r"""Primal-Dual Coordinate Descent solver with working sets.

Solver inspired by [1] that uses working sets [2].
It solves::

\min_w F(Xw) + G(w) \Leftrightarrow \min_w \max_z <Xw, z> + G(w) - F^*(z)

where :math:`F` is the datafit term (:math:`F^*` it's Fenchel conjugate)
and :math:`G` is the penalty term.

The datafit is required to be convex and proximable. Also, the penalty
is also required to be convex, separable, and proximable.

The solver is inspired by [1] and uses working sets [2].
The working sets are built using a fixed point distance strategy
where each feature is assigned a score based how much it maps
to itself when performing a primal update::

\text{score}_j = \abs{w_j - prox_{G_j}(w_j - \tau_j <X_j, z>)}

where :maths:`\tau_j` is the primal step associated with the j-th feature.

Parameters
----------
max_iter : int, optional
The maximum number of iterations or equivalently the
the maximum number solved subproblems.
the maximum number of solved subproblems.

max_epochs : int, optional
Maximum number of CD epochs on each subproblem.
Maximum number of primal CD epochs on each subproblem.

p0 : int, optional
First working set size.

tol : float, optional
The tolerance for the optimization.

dual_init : array, shape (n_samples,) default None
The initialization of dual variables.
If None, they are initialized as the 0 vector ``np.zeros(n_samples)``.

return_p_objs : bool, default False
If True, returns the values of the objective in each iteration.
Otherwise returns an empty array.

verbose : bool or int, default False
Amount of verbosity. 0/False is silent.

Expand All @@ -47,46 +56,44 @@ class PDCD_WS:
https://epubs.siam.org/doi/10.1137/18M1168480,
code: https://github.com/Badr-MOUFAD/Fercoq-Bianchi-solver

.. [2] Mathurin Massias, Alexandre Gramfort, Joseph Salmon,
"From safe screening rules to working sets for faster Lasso-type solvers",
OPTML workshop at NIPS 2017, https://arxiv.org/abs/1703.07285v2
.. [2] Bertrand, Q. and Klopfenstein, Q. and Bannier, P.-A. and Gidel, G.
and Massias, M.
"Beyond L1: Faster and Better Sparse Models with skglm", 2022
https://arxiv.org/abs/2204.07826
"""

def __init__(self, max_iter=1000, max_epochs=1000, p0=100, tol=1e-6,
dual_init=None, return_p_objs=False, verbose=False):
def __init__(self, max_iter=1000, max_epochs=1000,
p0=100, tol=1e-6, verbose=False):
self.max_iter = max_iter
self.max_epochs = max_epochs
self.dual_init = dual_init
self.p0 = p0
self.tol = tol
self.verbose = verbose
self.return_p_objs = return_p_objs

def solve(self, X, y, datafit_, penalty_):
def solve(self, X, y, datafit_, penalty_, w_init=None, Xw_init=None):
datafit, penalty = PDCD_WS._validate_init(datafit_, penalty_)
n_samples, n_features = X.shape

# init steps
# Despite violating the conditions mentioned in [1]
# this choice of steps yield in practice a convergent algorithm
# with better speed of convergence
dual_step = 1 / norm(X, ord=2)
primal_steps = 1 / norm(X, axis=0, ord=2)

# primal vars
w = np.zeros(n_features)
Xw = np.zeros(n_samples)
w = np.zeros(n_features) if w_init is None else w_init
Xw = np.zeros(n_samples) if Xw_init is None else Xw_init

# dual vars
if self.dual_init is None:
z = np.zeros(n_samples)
z_bar = np.zeros(n_samples)
else:
z = self.dual_init.copy()
z_bar = self.dual_init.copy()
z = y.copy()
z_bar = y.copy()

p_objs = []
stop_crit = 0.
all_features = np.arange(n_features)

for iter in range(self.max_iter):
for iteration in range(self.max_iter):

# check convergence
opts_primal = _scores_primal(
Expand All @@ -103,13 +110,9 @@ def solve(self, X, y, datafit_, penalty_):
if self.verbose:
current_p_obj = datafit.value(y, w, Xw) + penalty.value(w)
print(
f"Iteration {iter+1}: {current_p_obj:.10f}, "
f"Iteration {iteration+1}: {current_p_obj:.10f}, "
f"stopping crit: {stop_crit:.2e}")

if self.return_p_objs:
current_p_obj = datafit.value(y, w, Xw) + penalty.value(w)
p_objs.append(current_p_obj)

if stop_crit <= self.tol:
break

Expand All @@ -126,6 +129,9 @@ def solve(self, X, y, datafit_, penalty_):
PDCD_WS._solve_subproblem(
y, X, w, Xw, z, z_bar, datafit, penalty,
primal_steps, dual_step, ws, self.max_epochs, tol_in=0.3*stop_crit)

current_p_obj = datafit.value(y, w, Xw) + penalty.value(w)
p_objs.append(current_p_obj)
else:
warnings.warn(
f"PDCD_WS did not converge for tol={self.tol:.3e} "
Expand Down