Package: ad
OverviewTheadpackage allows you toeasilyandtransparentlyperformfirst and second-order automatic differentiation. Advanced math
involving trigonometric, logarithmic, hyperbolic, etc. functions can also
be evaluated directly using theadmathsub-module.All base numeric types are supported(int,float,complex,
etc.). This package is designed so that the underlying numeric types will
interact with each otheras they normally dowhen performing any
calculations. Thus, this package acts more like a “wrapper” that simply helps
keep track of derivatives whilemaintaining the original functionalityof
the numeric calculations.From the Wikipedia entry onAutomatic differentiation(AD):“AD exploits the fact that every computer program, no matter how
complicated, executes a sequence of elementary arithmetic operations
(addition, subtraction, multiplication, division, etc.) and elementary
functions (exp, log, sin, cos, etc.). By applying the chain rule
repeatedly to these operations, derivatives of arbitrary order can be
computed automatically, and accurate to working precision.”See thepackage documentationfor details and examples.Main FeaturesTransparent calculations with derivatives: no or little
modification of existing codeis needed, including when using
theNumpymodule.Almost all mathematical operationsare supported, including
functions from the standardmathmodule (sin, cos, exp, erf,
etc.) andcmathmodule (phase, polar, etc.) with additional convenience
trigonometric, hyperbolic, and logarithmic functions (csc, acoth, ln, etc.).
Comparison operators follow thesame rules as the underlying numeric
types.Real and complexarithmetic handled seamlessly. Treat objects as you
normally would using themathandcmathfunctions, but with their newadmathcounterparts.Automatic gradient and hessian function generatorfor optimization
studies usingscipy.optimizeroutines withgh(your_func_here).Compatible Linear Algebra Routinesin thead.linalgsubmodule,
similar to those found in NumPy’slinalgsubmodule, that are not
dependent on LAPACK. There are currently:Decompositionschol: Cholesky Decompositionlu: LU Decompositionqr: QR DecompositionSolving equations and inverting matricessolve: General solver for linear systems of equationslstsq: Least-squares solver for linear systems of equationsinv: Solve for the (multiplicative) inverse of a matrixInstallationYou have several easy, convenient options to install theadpackage
(administrative privileges may be required):Download the package files below, unzip to any directory, and runpython setup.py installfrom the command-line.Simply copy the unzippedad-XYZdirectory to any other location
that python can find it and rename itad.Ifsetuptoolsis installed, runeasy_install--upgradeadfrom the command-line.Ifpipis installed, runpip install--upgradeadfrom the
command-line.Download thebleeding-edgeversion onGitHubContactPlease sendfeature requests, bug reports, or feedbacktoAbraham Lee.AcknowledgementsThe author expresses his thanks to :Eric O. LEBIGOT (EOL), author of theuncertaintiespackage, for providing
code insight and inspirationStephen Marks, professor at Pomona College, for useful feedback concerning
the interface with optimization routines inscipy.optimize.Wendell Smith, for updating testing functionality and numerous other useful
function updatesJonathan Terhorst, for catching a bug that made derivatives of logarithmic
functions (base != e) give the wrong answers.GitHub userfhgdfor catching a mis-calculation inadmath.atan2