The Stan Math Library: Reverse-Mode Automatic Differentiation in C++

As computational challenges in optimization and statistical inference grow ever harder, algorithms that utilize derivatives are becoming increasingly more important. The implementation of the derivatives that make these algorithms so powerful, however, is a substantial user burden and the practicality of these algorithms depends critically on tools like automatic differentiation that remove the implementation burden entirely. The Stan Math Library is a C++, reverse-mode automatic differentiation library designed to be usable, extensive and extensible, efficient, scalable, stable, portable, and redistributable in order to facilitate the construction and utilization of such algorithms. Usability is achieved through a simple direct interface and a cleanly abstracted functional interface. The extensive built-in library includes functions for matrix operations, linear algebra, differential equation solving, and most common probability functions. Extensibility derives from a straightforward object-oriented framework for expressions, allowing users to easily create custom functions. Efficiency is achieved through a combination of custom memory management, subexpression caching, traits-based metaprogramming, and expression templates. Partial derivatives for compound functions are evaluated lazily for improved scalability. Stability is achieved by taking care with arithmetic precision in algebraic expressions and providing stable, compound functions where possible. For portability, the library is standards-compliant C++ (03) and has been tested for all major compilers for Windows, Mac OS X, and Linux.

[1]  M. D. MacLaren The Art of Computer Programming—Volume 1: Fundamental Algorithms (Donald E. Knuth) , 1969 .

[2]  S. Duane,et al.  Hybrid Monte Carlo , 1987 .

[3]  B. Fornberg Generation of finite difference formulas on arbitrarily spaced grids , 1988 .

[4]  Nicholas J. Higham,et al.  INVERSE PROBLEMS NEWSLETTER , 1991 .

[5]  J. Magnus,et al.  Matrix Differential Calculus with Applications in Statistics and Econometrics , 1991 .

[6]  Bjarne Stroustrup,et al.  The Design and Evolution of C , 1994 .

[7]  A. Hindmarsh,et al.  CVODE, a stiff/nonstiff ODE solver in C , 1996 .

[8]  Herb Sutter Pimples—beauty marks you can depend on , 2000 .

[9]  Andreas Griewank,et al.  Evaluating derivatives - principles and techniques of algorithmic differentiation, Second Edition , 2000, Frontiers in applied mathematics.

[10]  David Gay,et al.  Language support for regions , 2001, PLDI '01.

[11]  William H. Press,et al.  Numerical recipes in C , 2002 .

[12]  Douglas Gregor,et al.  C++ Templates: The Complete Guide , 2002 .

[13]  M. David Semiautomatic Differentiation for Efficient Gradient Computations , 2004 .

[14]  Tamara G. Kolda,et al.  An overview of the Trilinos project , 2005, TOMS.

[15]  Carol S. Woodward,et al.  Enabling New Flexibility in the SUNDIALS Suite of Nonlinear and Differential/Algebraic Equation Solvers , 2020, ACM Trans. Math. Softw..

[16]  Kaare Brandt Petersen,et al.  The Matrix Cookbook , 2006 .

[17]  M. Giles An extended collection of matrix derivative results for forward and reverse mode algorithmic dieren tiation , 2008 .

[18]  John K Kruschke,et al.  Bayesian data analysis. , 2010, Wiley interdisciplinary reviews. Cognitive science.

[19]  Robert H. Halstead,et al.  Matrix Computations , 2011, Encyclopedia of Parallel Computing.

[20]  Radford M. Neal MCMC Using Hamiltonian Dynamics , 2011, 1206.1901.

[21]  Sandeep Koranne,et al.  Boost C++ Libraries , 2011 .

[22]  Laurent Hascoët,et al.  The Tapenade automatic differentiation tool: Principles, model, and specification , 2013, TOMS.

[23]  M. Betancourt,et al.  The Geometric Foundations of Hamiltonian Monte Carlo , 2014, 1410.5110.

[24]  Robin J. Hogan,et al.  Fast Reverse-Mode Automatic Differentiation using Expression Templates in C++ , 2014, ACM Trans. Math. Softw..