cost function computation implemented