Add penalty terms to error function.