Implemented cost function for collaborative filtering algorithm