ML: new regularized cost function solution (as for exercise 2)