Ridge regression with adaptive additive rectangles and other piecewise functional templates