Compute theta gradients with regularization.