model whit cost function