Currently, this function is very inefficient, with multiple subsets from the data for each of the penalty values. This should be made faster.