margin dot prod cost function