ML: new regularized cost function and gradient solution