Algorithms for machine learning and inference