Stochastic algorithms for distributed optimization and machine learning