public static < K > double estimatePenalty ( double l1 , Map < K , Double > weights ) { double penalty = 0.0 ; if ( l1 > 0.0 ) { double sumAbsWeights = 0.0 ; for ( double w : weights . values ( ) ) { sumAbsWeights += Math . abs ( w ) ; } penalty = l1 * sumAbsWeights ; } return penalty ; }
Estimates the penalty by adding the L1 regularization .