A Variational Analysis of Stochastic Gradient Algorithms