allow custom cost functions for the algorithm