Online and Stochastic Gradient Methods for Non-decomposable Loss Functions