Network optimization for distributed machine learning over networks