Software:Adept (C++ library)

From HandWiki
Adept C++ Library
AdeptLogo.png
Developer(s)Robin Hogan
Stable release
2.1 / 5 February 2021 (3 years ago) (2021-02-05)
Written inC++
Operating systemCross-platform
TypeLibrary
LicenseApache 2.0 (open source)
Websitewww.met.reading.ac.uk/clouds/adept/

Adept is a combined automatic differentiation and array software library for the C++ programming language. The automatic differentiation capability facilitates the development of applications involving mathematical optimization. Adept is notable for having applied the template metaprogramming technique of expression templates to speed-up the differentiation of mathematical statements.[1][2] Along with the efficient way that it stores the differential information, this makes it significantly faster than most other C++ tools that provide similar functionality (e.g. ADOL-C, CppAD and FADBAD),[1][3][4][5][6] although comparable performance has been reported for Stan and in some cases Sacado.[3] Differentiation may be in forward mode, reverse mode (for use with a Quasi-Newton minimization scheme), or the full Jacobian matrix may be computed (for use with the Levenberg-Marquardt or Gauss-Newton minimization schemes).

Applications of Adept have included financial modeling,[6][7] computational fluid dynamics,[8] physical chemistry,[9] parameter estimation[10] and meteorology.[11] Adept is free software distributed under the Apache License.

Example

Adept implements automatic differentiation using an operator overloading approach, in which scalars to be differentiated are written as adouble, indicating an "active" version of the normal double, and vectors to be differentiated are written as aVector. The following simple example uses these types to differentiate a 3-norm calculation on a small vector:

#include <iostream>
#include <adept_arrays.h>

int main(int argc, const char** argv) {
  using namespace adept;
  Stack stack;                           // Object to store differential statements
  aVector x(3);                          // Independent variables: active vector with 3 elements
  x << 1.0, 2.0, 3.0;                    // Fill vector x
  stack.new_recording();                 // Clear any existing differential statements
  adouble J = cbrt(sum(abs(x * x * x))); // Compute dependent variable: 3-norm in this case
  J.set_gradient(1.0);                   // Seed the dependent variable
  stack.reverse();                       // Reverse-mode differentiation
  std::cout << "dJ/dx = "
            << x.get_gradient() << "\n"; // Print the vector of partial derivatives dJ/dx

  return 0;
}

When compiled and executed, this program reports the derivative as:

dJ/dx = {0.0917202, 0.366881, 0.825482}

See also

References

  1. 1.0 1.1 Hogan, Robin J. (2014). "Fast reverse-mode automatic differentiation using expression templates in C++". ACM Trans. Math. Softw. 40 (4): 26:1–26:16. doi:10.1145/2560359. http://www.met.reading.ac.uk/%7Eswrhgnrj/publications/adept.pdf. 
  2. Griewank, Andreas (2014). "On automatic differentiation and algorithmic linearization". Pesquisa Operacional 34 (3): 621–645. doi:10.1590/0101-7438.2014.034.03.0621. http://pdfs.semanticscholar.org/90e8/7e99cf6416ef29fe9ddf993ef8f88ccd7003.pdf. 
  3. 3.0 3.1 Carpenter, Bob (2015). "The Stan Math Library: Reverse-Mode Automatic Differentiation in C++". arXiv:1509.07164 [cs.MS].
  4. "Sensitivities in Quantitative Finance: Libor Swaption Portfolio Pricer (Monte-Carlo)". 2016-12-02. https://www.xcelerit.com/computing-benchmarks/software/aad/. Retrieved 2017-10-21. 
  5. Rieck, Matthias. Discrete controls and constraints in optimal control problems (PDF) (PhD Thesis). Technical University of Munich. Retrieved 2017-10-21.
  6. 6.0 6.1 Zhao, Ze. Stochastic volatility models with applications in finance (Thesis). University of Iowa. Archived from the original on July 18, 2017. Retrieved 2017-10-27.
  7. Pagès, Gilles; Pironneau, Olivier; Sall, Guillaume (2016). "Vibrato and automatic differentiation for high order derivatives and sensitivities of financial options". arXiv:1606.06143 [q-fin.CP].
  8. Albring, T.; Sagebaum, M.; Gauger, N. R. (2016). "A Consistent and Robust Discrete Adjoint Solver for the SU2 Framework—Validation and Application". in Dillmann, A.; Heller, G.; Krämer, E. et al.. 132. Springer, Cham. doi:10.1007/978-3-319-27279-5_7. 
  9. Niemeyer, Kyle E.; Curtis, Nicholas J.; Sung, Chih-Jen (2017). "pyJac: Analytical Jacobian generator for chemical kinetics". Comput. Phys. Commun. 215: 188–203. doi:10.1016/j.cpc.2017.02.004. Bibcode2017CoPhC.215..188N. 
  10. Albert, Carlo; Ulzega, Simone; Stoop, Ruedi (2016). "Boosting Bayesian parameter inference of nonlinear stochastic differential equation models by Hamiltonian scale separation". Phys. Rev. E 93 (43313): 043313. doi:10.1103/PhysRevE.93.043313. PMID 27176434. Bibcode2016PhRvE..93d3313A. 
  11. Mason, S.; Chiu, J.-C.; Hogan, R. J.; Moisseev, D.; Kneifel, S. (2018). "Retrievals of riming and snow particle density from vertically-pointing Doppler radars". J. Geophys. Res. 123. doi:10.1029/2018JD028603. http://centaur.reading.ac.uk/80877/1/manuscript.pdf. 

External links