added optional cost function documentation