Automatic Differentiation of Algorithms for Machine Learning