@@ -17,7 +17,8 @@ class Quadratic(BaseDatafit):
17
17
Attributes
18
18
----------
19
19
Xty : array, shape (n_features,)
20
- Pre-computed quantity used during the gradient evaluation. Equal to X.T @ y.
20
+ Pre-computed quantity used during the gradient evaluation.
21
+ Equal to ``X.T @ y``.
21
22
22
23
lipschitz : array, shape (n_features,)
23
24
The coordinatewise gradient Lipschitz constants. Equal to
@@ -50,7 +51,7 @@ def params_to_dict(self):
50
51
def initialize (self , X , y ):
51
52
self .Xty = X .T @ y
52
53
n_features = X .shape [1 ]
53
- self . global_lipschitz = norm ( X , ord = 2 ) ** 2 / len ( y )
54
+
54
55
self .lipschitz = np .zeros (n_features , dtype = X .dtype )
55
56
for j in range (n_features ):
56
57
self .lipschitz [j ] = (X [:, j ] ** 2 ).sum () / len (y )
@@ -59,9 +60,6 @@ def initialize_sparse(self, X_data, X_indptr, X_indices, y):
59
60
n_features = len (X_indptr ) - 1
60
61
self .Xty = np .zeros (n_features , dtype = X_data .dtype )
61
62
62
- self .global_lipschitz = spectral_norm (X_data , X_indptr , X_indices , len (y )) ** 2
63
- self .global_lipschitz /= len (y )
64
-
65
63
self .lipschitz = np .zeros (n_features , dtype = X_data .dtype )
66
64
for j in range (n_features ):
67
65
nrm2 = 0.
@@ -73,6 +71,13 @@ def initialize_sparse(self, X_data, X_indptr, X_indices, y):
73
71
self .lipschitz [j ] = nrm2 / len (y )
74
72
self .Xty [j ] = xty
75
73
74
+ def init_global_lipschitz (self , X , y ):
75
+ self .global_lipschitz = norm (X , ord = 2 ) ** 2 / len (y )
76
+
77
+ def init_global_lipschitz_sparse (self , X_data , X_indptr , X_indices , y ):
78
+ self .global_lipschitz = spectral_norm (
79
+ X_data , X_indptr , X_indices , len (y )) ** 2 / len (y )
80
+
76
81
def value (self , y , w , Xw ):
77
82
return np .sum ((y - Xw ) ** 2 ) / (2 * len (Xw ))
78
83
@@ -155,19 +160,22 @@ def raw_hessian(self, y, Xw):
155
160
156
161
def initialize (self , X , y ):
157
162
self .lipschitz = (X ** 2 ).sum (axis = 0 ) / (len (y ) * 4 )
158
- self .global_lipschitz = norm (X , ord = 2 ) ** 2 / (len (y ) * 4 )
159
163
160
164
def initialize_sparse (self , X_data , X_indptr , X_indices , y ):
161
165
n_features = len (X_indptr ) - 1
162
166
163
- self .global_lipschitz = spectral_norm (X_data , X_indptr , X_indices , len (y )) ** 2
164
- self .global_lipschitz /= 4 * len (y )
165
-
166
167
self .lipschitz = np .zeros (n_features , dtype = X_data .dtype )
167
168
for j in range (n_features ):
168
169
Xj = X_data [X_indptr [j ]:X_indptr [j + 1 ]]
169
170
self .lipschitz [j ] = (Xj ** 2 ).sum () / (len (y ) * 4 )
170
171
172
+ def init_global_lipschitz (self , X , y ):
173
+ self .global_lipschitz = norm (X , ord = 2 ) ** 2 / (4 * len (y ))
174
+
175
+ def init_global_lipschitz_sparse (self , X_data , X_indptr , X_indices , y ):
176
+ self .global_lipschitz = spectral_norm (
177
+ X_data , X_indptr , X_indices , len (y )) ** 2 / (4 * len (y ))
178
+
171
179
def value (self , y , w , Xw ):
172
180
return np .log (1. + np .exp (- y * Xw )).sum () / len (y )
173
181
@@ -235,23 +243,27 @@ def params_to_dict(self):
235
243
def initialize (self , yXT , y ):
236
244
n_features = yXT .shape [1 ]
237
245
self .lipschitz = np .zeros (n_features , dtype = yXT .dtype )
238
- self . global_lipschitz = norm ( yXT , ord = 2 ) ** 2
246
+
239
247
for j in range (n_features ):
240
248
self .lipschitz [j ] = norm (yXT [:, j ]) ** 2
241
249
242
250
def initialize_sparse (self , yXT_data , yXT_indptr , yXT_indices , y ):
243
251
n_features = len (yXT_indptr ) - 1
244
252
245
- self .global_lipschitz = spectral_norm (
246
- yXT_data , yXT_indptr , yXT_indices , max (yXT_indices )+ 1 ) ** 2
247
-
248
253
self .lipschitz = np .zeros (n_features , dtype = yXT_data .dtype )
249
254
for j in range (n_features ):
250
255
nrm2 = 0.
251
256
for idx in range (yXT_indptr [j ], yXT_indptr [j + 1 ]):
252
257
nrm2 += yXT_data [idx ] ** 2
253
258
self .lipschitz [j ] = nrm2
254
259
260
+ def init_global_lipschitz (self , yXT , y ):
261
+ self .global_lipschitz = norm (yXT , ord = 2 ) ** 2
262
+
263
+ def init_global_lipschitz_sparse (self , yXT_data , yXT_indptr , yXT_indices , y ):
264
+ self .global_lipschitz = spectral_norm (
265
+ yXT_data , yXT_indptr , yXT_indices , max (yXT_indices )+ 1 ) ** 2
266
+
255
267
def value (self , y , w , yXTw ):
256
268
return (yXTw ** 2 ).sum () / 2 - np .sum (w )
257
269
@@ -328,24 +340,26 @@ def params_to_dict(self):
328
340
def initialize (self , X , y ):
329
341
n_features = X .shape [1 ]
330
342
self .lipschitz = np .zeros (n_features , dtype = X .dtype )
331
- self .global_lipschitz = 0.
332
343
for j in range (n_features ):
333
344
self .lipschitz [j ] = (X [:, j ] ** 2 ).sum () / len (y )
334
- self .global_lipschitz += (X [:, j ] ** 2 ).sum () / len (y )
335
345
336
346
def initialize_sparse (self , X_data , X_indptr , X_indices , y ):
337
347
n_features = len (X_indptr ) - 1
338
348
339
- self .global_lipschitz = spectral_norm (X_data , X_indptr , X_indices , len (y )) ** 2
340
- self .global_lipschitz /= len (y )
341
-
342
349
self .lipschitz = np .zeros (n_features , dtype = X_data .dtype )
343
350
for j in range (n_features ):
344
351
nrm2 = 0.
345
352
for idx in range (X_indptr [j ], X_indptr [j + 1 ]):
346
353
nrm2 += X_data [idx ] ** 2
347
354
self .lipschitz [j ] = nrm2 / len (y )
348
355
356
+ def init_global_lipschitz (self , X , y ):
357
+ self .global_lipschitz = norm (X , ord = 2 ) ** 2 / len (y )
358
+
359
+ def init_global_lipschitz_sparse (self , X_data , X_indptr , X_indices , y ):
360
+ self .global_lipschitz = spectral_norm (
361
+ X_data , X_indptr , X_indices , len (y )) ** 2 / len (y )
362
+
349
363
def value (self , y , w , Xw ):
350
364
n_samples = len (y )
351
365
res = 0.
0 commit comments