Fully vectorised implementation of cost function and gradient.
Regularized cost function.