The loss and cost functions