Stochastic optimization by message passing