fix gradient in cost regularization