code: public static <K> double estimatePenalty(double l2, Map<K, Double> weights) {
          double penalty = 0.0;
          if(l2 > 0.0) {
              double sumWeightsSquared = 0.0;
              for(double w : weights.values()) {
                  sumWeightsSquared += w*w;
              }
              penalty = l2*sumWeightsSquared/2.0;
          }
          return penalty;
      }
docs: Estimates the penalty by adding the L2 regularization.
  
  @param l2
  @param weights
  @param <K>
  @return