@@ -25,18 +25,21 @@ cdef:
2525@ cython.cdivision (True )
2626cpdef floating primal_grplasso(
2727 floating alpha, floating[:] R, int [::1 ] grp_ptr,
28- int [::1 ] grp_indices, floating[:] w):
28+ int [::1 ] grp_indices, floating[:] w, floating[:] weights ):
2929 cdef floating nrm = 0.
3030 cdef int j, k, g
3131 cdef int n_samples = R.shape[0 ]
3232 cdef int n_groups = grp_ptr.shape[0 ] - 1
3333 cdef floating p_obj = fnrm2(& n_samples, & R[0 ], & inc) ** 2 / (2 * n_samples)
34+
3435 for g in range (n_groups):
3536 nrm = 0.
37+
3638 for k in range (grp_ptr[g], grp_ptr[g + 1 ]):
3739 j = grp_indices[k]
3840 nrm += w[j] ** 2
39- p_obj += alpha * sqrt(nrm)
41+ p_obj += alpha * sqrt(nrm) * weights[g]
42+
4043 return p_obj
4144
4245
@@ -47,7 +50,7 @@ cpdef floating dnorm_grp(
4750 bint is_sparse, floating[::1 ] theta, int [::1 ] grp_ptr,
4851 int [::1 ] grp_indices, floating[::1 , :] X, floating[::1 ] X_data,
4952 int [::1 ] X_indices, int [::1 ] X_indptr, floating[::1 ] X_mean,
50- int ws_size, int [:] C, bint center):
53+ floating[:] weights, int ws_size, int [:] C, bint center):
5154 """ Dual norm in the group case, i.e. L2/infty ofter groups."""
5255 cdef floating Xj_theta, tmp
5356 cdef floating scal = 0.
@@ -63,6 +66,9 @@ cpdef floating dnorm_grp(
6366
6467 if ws_size == n_groups: # max over all groups
6568 for g in range (n_groups):
69+ if weights[g] == INFINITY:
70+ continue
71+
6672 tmp = 0
6773 for k in range (grp_ptr[g], grp_ptr[g + 1 ]):
6874 j = grp_indices[k]
@@ -79,10 +85,13 @@ cpdef floating dnorm_grp(
7985 & inc)
8086 tmp += Xj_theta ** 2
8187
82- scal = max (scal, sqrt(tmp))
88+ scal = max (scal, sqrt(tmp) / weights[g] )
8389
8490 else : # scaling only with features in C
8591 for g_idx in range (ws_size):
92+ if weights[g] == INFINITY:
93+ continue
94+
8695 g = C[g_idx]
8796 tmp = 0
8897 for k in range (grp_ptr[g], grp_ptr[g + 1 ]):
@@ -100,7 +109,7 @@ cpdef floating dnorm_grp(
100109 & inc)
101110 tmp += Xj_theta ** 2
102111
103- scal = max (scal, sqrt(tmp))
112+ scal = max (scal, sqrt(tmp) / weights[g] )
104113 return scal
105114
106115
@@ -110,9 +119,9 @@ cpdef floating dnorm_grp(
110119cdef void set_prios_grp(
111120 bint is_sparse, int pb, floating[::1 ] theta, floating[::1 , :] X,
112121 floating[::1 ] X_data, int [::1 ] X_indices, int [::1 ] X_indptr,
113- floating[:: 1 ] norms_X_grp, int [::1 ] grp_ptr , int [::1 ] grp_indices ,
114- floating[::1 ] prios, int [::1 ] screened, floating radius ,
115- int * n_screened):
122+ floating[:] weights, floating [::1 ] norms_X_grp , int [::1 ] grp_ptr ,
123+ int [:: 1 ] grp_indices, floating[::1 ] prios, int [::1 ] screened,
124+ floating radius, int * n_screened):
116125 cdef int i, j, k, g, startptr, endptr
117126 cdef floating nrm_Xgtheta, Xj_theta
118127 cdef int n_groups = grp_ptr.shape[0 ] - 1
@@ -134,7 +143,7 @@ cdef void set_prios_grp(
134143 else :
135144 Xj_theta = fdot(& n_samples, & theta[0 ], & inc, & X[0 , j], & inc)
136145 nrm_Xgtheta += Xj_theta ** 2
137- nrm_Xgtheta = sqrt(nrm_Xgtheta)
146+ nrm_Xgtheta = sqrt(nrm_Xgtheta) / weights[g]
138147
139148 prios[g] = (1. - nrm_Xgtheta) / norms_X_grp[g]
140149
@@ -150,8 +159,8 @@ cpdef celer_grp(
150159 int [::1 ] grp_ptr, floating[::1 ] X_data, int [::1 ] X_indices,
151160 int [::1 ] X_indptr, floating[::1 ] X_mean, floating[:] y, floating alpha,
152161 floating[:] w, floating[:] R, floating[::1 ] theta,
153- floating[::1 ] norms_X_grp, floating tol, int max_iter , int max_epochs ,
154- int gap_freq = 10 , floating tol_ratio_inner = 0.3 , int p0 = 100 ,
162+ floating[::1 ] norms_X_grp, floating tol, floating[:] weights , int max_iter ,
163+ int max_epochs, int gap_freq = 10 , floating tol_ratio_inner = 0.3 , int p0 = 100 ,
155164 bint prune = 1 , bint use_accel = 1 ,
156165 bint verbose = 0 ):
157166
@@ -225,7 +234,7 @@ cpdef celer_grp(
225234
226235 scal = dnorm_grp(
227236 is_sparse, theta, grp_ptr, grp_indices, X, X_data, X_indices,
228- X_indptr, X_mean, n_groups, dummy_C, center)
237+ X_indptr, X_mean, weights, n_groups, dummy_C, center)
229238
230239 if scal > 1. :
231240 tmp = 1. / scal
@@ -234,11 +243,10 @@ cpdef celer_grp(
234243 d_obj = dual(pb, n_samples, alpha, norm_y2, & theta[0 ], & y[0 ])
235244
236245 if t > 0 :
237- pass
238246 # also test dual point returned by inner solver after 1st iter:
239247 scal = dnorm_grp(
240248 is_sparse, theta_inner, grp_ptr, grp_indices, X, X_data,
241- X_indices, X_indptr, X_mean, n_groups, dummy_C, center)
249+ X_indices, X_indptr, X_mean, weights, n_groups, dummy_C, center)
242250 if scal > 1. :
243251 tmp = 1. / scal
244252 fscal(& n_samples, & tmp, & theta_inner[0 ], & inc)
@@ -254,7 +262,7 @@ cpdef celer_grp(
254262 highest_d_obj = d_obj
255263 # TODO implement a best_theta
256264
257- p_obj = primal_grplasso(alpha, R, grp_ptr, grp_indices, w)
265+ p_obj = primal_grplasso(alpha, R, grp_ptr, grp_indices, w, weights )
258266 gap = p_obj - highest_d_obj
259267 gaps[t] = gap
260268
@@ -272,8 +280,9 @@ cpdef celer_grp(
272280 # radius = sqrt(gap / 2.) / alpha
273281
274282 set_prios_grp(
275- is_sparse, pb, theta, X, X_data, X_indices, X_indptr, lc_groups,
276- grp_ptr, grp_indices, prios, screened, radius, & n_screened)
283+ is_sparse, pb, theta, X, X_data, X_indices, X_indptr,
284+ weights, lc_groups, grp_ptr, grp_indices, prios, screened,
285+ radius, & n_screened)
277286
278287 if prune:
279288 nnz = 0
@@ -327,7 +336,7 @@ cpdef celer_grp(
327336
328337 scal = dnorm_grp(
329338 is_sparse, theta_inner, grp_ptr, grp_indices, X, X_data,
330- X_indices, X_indptr, X_mean, ws_size, C, center)
339+ X_indices, X_indptr, X_mean, weights, ws_size, C, center)
331340
332341 if scal > 1. :
333342 tmp = 1. / scal
@@ -348,8 +357,8 @@ cpdef celer_grp(
348357 if epoch // gap_freq >= K:
349358 scal = dnorm_grp(
350359 is_sparse, thetacc, grp_ptr, grp_indices, X,
351- X_data, X_indices, X_indptr, X_mean, ws_size, C ,
352- center)
360+ X_data, X_indices, X_indptr, X_mean, weights ,
361+ ws_size, C, center)
353362
354363 if scal > 1. :
355364 tmp = 1. / scal
@@ -365,7 +374,8 @@ cpdef celer_grp(
365374
366375 if d_obj_in > highest_d_obj_in:
367376 highest_d_obj_in = d_obj_in
368- p_obj_in = primal_grplasso(alpha, R, grp_ptr, grp_indices, w)
377+
378+ p_obj_in = primal_grplasso(alpha, R, grp_ptr, grp_indices, w, weights)
369379 gap_in = p_obj_in - highest_d_obj_in
370380
371381 if verbose_in:
@@ -402,7 +412,7 @@ cpdef celer_grp(
402412 norm_wg += w[j] ** 2
403413 norm_wg = sqrt(norm_wg)
404414 bst_scal = max (0. ,
405- 1. - alpha / lc_groups[g] * n_samples / norm_wg)
415+ 1. - alpha * weights[g] / lc_groups[g] * n_samples / norm_wg)
406416
407417 for k in range (grp_ptr[g + 1 ] - grp_ptr[g]):
408418 j = grp_indices[grp_ptr[g] + k]
0 commit comments