Partially updates cost function