A Stochastic Approximation Method for Optimization Problems