ENH: Added cost function interface.