@@ -73,7 +73,7 @@ impl LassoInput<f64> {
7373 let n_cols = self . x . ncols ( ) ;
7474 let n_rows = self . x . nrows ( ) as f64 ;
7575 let mut features_matrix = self . x . clone ( ) ;
76- let mut response_vec = self . y . clone ( ) ;
76+ let mut residuals = self . y . clone ( ) ;
7777 let feature_means = DVector :: from_iterator (
7878 self . x . ncols ( ) ,
7979 ( 0 ..self . x . ncols ( ) ) . map ( |j| self . x . column ( j) . mean ( ) )
@@ -88,10 +88,9 @@ impl LassoInput<f64> {
8888 features_matrix[ ( i, j) ] -= mean;
8989 }
9090 }
91- response_vec = & self . y - DVector :: from_element ( self . x . nrows ( ) , self . y . mean ( ) ) ;
91+ residuals -= DVector :: from_element ( self . x . nrows ( ) , self . y . mean ( ) ) ;
9292 }
9393
94- let mut residual = response_vec;
9594 let mut coefficients = DVector :: < f64 > :: zeros ( n_cols) ;
9695
9796 for _ in 0 ..self . max_iter {
@@ -100,7 +99,7 @@ impl LassoInput<f64> {
10099
101100 let feature_vals_col_j = features_matrix. column ( j) ;
102101 let col_norm: f64 = feature_vals_col_j. dot ( & feature_vals_col_j) ;
103- let rho: f64 = ( residual . dot ( & feature_vals_col_j) + coefficients[ j] * col_norm) / n_rows;
102+ let rho: f64 = ( residuals . dot ( & feature_vals_col_j) + coefficients[ j] * col_norm) / n_rows;
104103
105104 let new_coefficient_j: f64 = if rho < -self . lambda {
106105 ( rho + self . lambda ) / ( col_norm / n_rows)
@@ -112,7 +111,7 @@ impl LassoInput<f64> {
112111
113112 let delta: f64 = new_coefficient_j - coefficients[ j] ;
114113 if delta. abs ( ) > 0.0 {
115- residual -= & feature_vals_col_j * delta;
114+ residuals -= & feature_vals_col_j * delta;
116115 }
117116 coefficients[ j] = new_coefficient_j;
118117 max_delta = max_delta. max ( delta. abs ( ) ) ;
0 commit comments