@@ -71,33 +71,61 @@ randomizedLASSO = function(X,
71
71
sign_soln = sign(result $ soln )
72
72
73
73
unpenalized = lam == 0
74
- active = ! unpenalized * (sign_soln != 0 )
75
- inactive = ! unpenzlied * (sign_soln == 0 )
74
+ active = ( ! unpenalized ) & (sign_soln != 0 )
75
+ inactive = ( ! unpenalized ) & (sign_soln == 0 )
76
76
77
77
unpenalized_set = which(unpenalized )
78
78
active_set = which(active )
79
79
inactive_set = which(inactive )
80
80
81
- coef_term = t(X ) %*% X [,c(unpenalized_set , # the coefficients
82
- active_set )]
81
+ # affine transform for optimization variables
82
+
83
+ E = c(unpenalized_set , active_set )
84
+ I = inactive_set
85
+ X_E = X [,E ]
86
+ X_I = X [,I ]
87
+ L_E = t(X ) %*% X [,E ]
88
+
89
+ coef_term = L_E
83
90
coef_term = coef_term %*% diag(c(rep(1 , sum(unpenalized )), sign_soln [active ])) # coefficients are non-negative
84
91
coef_term [active ,] = coef_term [active ,] + ridge_term * diag(rep(1 , sum(active ))) # ridge term
85
92
86
- subgrad_term = cbind(matrix (0 , sum(inactive ), sum(active ) + sum(unpenalized )),
87
- diag(rep(1 , sum(inactive ))))
88
- linear_term = rbind(coef_term ,
93
+ subgrad_term = matrix (0 , p , sum(inactive )) # for subgrad
94
+ for (i in 1 : sum(inactive )) {
95
+ subgrad_term [inactive_set [i ], i ] = 1
96
+ }
97
+
98
+ linear_term = cbind(coef_term ,
89
99
subgrad_term )
90
100
91
101
offset_term = rep(0 , p )
92
102
offset_term [active ] = lam [active ] * sign_soln [active ]
93
103
94
-
104
+ opt_transform = list (linear_term = linear_term ,
105
+ offset_term = offset_term )
106
+
107
+ # affine transform for internal (data) variables
108
+ # for now just use parametric in terms of
109
+ # (\bar{\beta}_E, X_{-E}^T(y-X_E\bar{\beta}_E)
110
+ #
111
+ # we have to reconstruct -X^TY from this pair
112
+ #
113
+
114
+ active_term = - L_E # for \bar{\beta}_E
115
+
116
+ inactive_term = - subgrad_term
117
+ linear_term = cbind(active_term ,
118
+ inactive_term )
119
+ offset_term = rep(0 , p )
120
+ internal_transform = list (linear_term = linear_term ,
121
+ offset_term = offset_term )
122
+
123
+ return (list (active_set = active_set ,
124
+ inactive_set = inactive_set ,
125
+ unpenalized_set = unpenalized_set ,
126
+ sign_soln = sign_soln ,
127
+ opt_transform = opt_transform ,
128
+ internal_transform = internal_transform
129
+ ))
95
130
96
- list (active_set = active_set ,
97
- inactive_set = inactive_set ,
98
- unpenalized_set = unpenalized_set ,
99
- sign_soln = sign_soln )
100
-
101
-
102
- return (result )
103
131
}
0 commit comments