12
12
13
13
14
14
class SqrtQuadratic (BaseDatafit ):
15
- """Square root quadratic datafit.
15
+ """Unnormalized square root quadratic datafit.
16
16
17
17
The datafit reads::
18
- ||y - Xw||_2 / sqrt(n_samples)
18
+
19
+ ||y - Xw||_2
19
20
"""
20
21
21
22
def __init__ (self ):
@@ -29,7 +30,7 @@ def params_to_dict(self):
29
30
return dict ()
30
31
31
32
def value (self , y , w , Xw ):
32
- return np .linalg .norm (y - Xw ) / np . sqrt ( len ( y ))
33
+ return np .linalg .norm (y - Xw )
33
34
34
35
def raw_grad (self , y , Xw ):
35
36
"""Compute gradient of datafit w.r.t ``Xw``.
@@ -45,12 +46,12 @@ def raw_grad(self, y, Xw):
45
46
if norm_residuals < 1e-2 * norm (y ):
46
47
raise ValueError ("SmallResidualException" )
47
48
48
- return minus_residual / ( norm_residuals * np . sqrt ( len ( y )))
49
+ return minus_residual / norm_residuals
49
50
50
51
def raw_hessian (self , y , Xw ):
51
52
"""Diagonal matrix upper bounding the Hessian."""
52
53
n_samples = len (y )
53
- fill_value = 1 / ( np . sqrt ( n_samples ) * norm (y - Xw ) )
54
+ fill_value = 1 / norm (y - Xw )
54
55
return np .full (n_samples , fill_value )
55
56
56
57
@@ -59,7 +60,7 @@ class SqrtLasso(LinearModel, RegressorMixin):
59
60
60
61
The optimization objective for square root Lasso is::
61
62
62
- |y - X w||_2 / sqrt(n_samples) + alpha * ||w||_1
63
+ |y - X w||_2 + alpha * ||w||_1
63
64
64
65
Parameters
65
66
----------
@@ -205,7 +206,8 @@ def _chambolle_pock_sqrt(X, y, alpha, max_iter=1000, obj_freq=10, verbose=False)
205
206
"""Apply Chambolle-Pock algorithm to solve square-root Lasso.
206
207
207
208
The objective function is:
208
- min_w ||Xw - y||_2/sqrt(n_samples) + alpha * ||w||_1.
209
+
210
+ min_w ||Xw - y||_2 + alpha * ||w||_1.
209
211
"""
210
212
n_samples , n_features = X .shape
211
213
# dual variable is z, primal is w
@@ -221,12 +223,12 @@ def _chambolle_pock_sqrt(X, y, alpha, max_iter=1000, obj_freq=10, verbose=False)
221
223
sigma = 0.99 / L
222
224
223
225
for t in range (max_iter ):
224
- w = ST_vec (w - tau * X .T @ (2 * z - z_old ), alpha * np . sqrt ( n_samples ) * tau )
226
+ w = ST_vec (w - tau * X .T @ (2 * z - z_old ), alpha * tau )
225
227
z_old = z .copy ()
226
228
z [:] = proj_L2ball (z + sigma * (X @ w - y ))
227
229
228
230
if t % obj_freq == 0 :
229
- objs .append (norm (X @ w - y ) / np . sqrt ( n_samples ) + alpha * norm (w , ord = 1 ))
231
+ objs .append (norm (X @ w - y ) + alpha * norm (w , ord = 1 ))
230
232
if verbose :
231
233
print (f"Iter { t } , obj { objs [- 1 ]: .10f} " )
232
234
0 commit comments