Added logging to plot the costs, plus adaptation of lambda to the number of samples