# b45ch1/algopy

Switch branches/tags
Nothing to show
Fetching contributors…
Cannot retrieve contributors at this time
162 lines (116 sloc) 5.77 KB

# AlgoPy, a library for Automatic Differentation (AD) in Python

Description:

AlgoPy allows you to differentiate functions implemented as computer programs by using Algorithmic Differentiation (AD) techniques in the forward and reverse mode.

The forward mode propagates univariate Taylor polynomials of arbitrary order. Hence it is also possible to use AlgoPy to evaluate higher-order derivative tensors.

Speciality of AlgoPy is the possibility to differentiate functions that contain matrix functions as +,-,*,/, dot, solve, qr, eigh, cholesky.

Rationale:

Many programs for scientific computing make use of numerical linear algebra. The defacto standard for array manipulations in Python is NumPy. AlgoPy allows you to write code that can either be evaluated by NumPy, or with AlgoPy with little or no modifications to your code.

Note that this does not mean that any code you wrote can be differentiated with AlgoPy, but rather that you can write code that can be evaluated with or without AlgoPy.

Documentation:

Available at http://packages.python.org/algopy/

For more documentation have a look at:
1. the talks in the ./documentation folder
2. the examples in the ./documentation/examples folder
3. sphinx documenation ./documentation/sphinx and run make
Example:

Compute directional derivatives of the function f(J):

```import numpy
from algopy import UTPM, qr, solve, dot, eigh

def f(x):
N,M = x.shape
Q,R = qr(x)
Id = numpy.eye(M)
Rinv = solve(R,Id)
C = dot(Rinv,Rinv.T)
l,U = eigh(C)
return l[0]

x = UTPM.init_jacobian(numpy.random.random((50,10)))
y = f(x)
J = UTPM.extract_jacobian(y)

print 'Jacobian dy/dx =', J
```

Installation:

see http://packages.python.org/algopy/

Features:

Univariate Taylor Propagation:

• Univariate Taylor Propagation on Matrices (UTPM) Implementation in: algopy.utpm
• Exact Interpolation of Higher Order Derivative Tensors: (Hessians, etc.)

Reverse Mode:

ALGOPY also features functionality for convenient differentiation of a given algorithm. For that, the sequence of operation is recorded by tracing the evaluation of the algorithm. Implementation in: ./algopy/tracer.py

Testing:

Uses numpy testing facilities. Simply run:

```\$ python -c "import algopy; algopy.test()"
```

Alternatives:

If you are looking for a robust tool for AD in Python you should try:

However, their support for differentiation of Numerical Linear Algebra (NLA) functions is only very limited.

Email:

sebastian.walter@gmail.com

How to cite AlgoPy:

```@article{Walter2011,
title = "Algorithmic differentiation in Python with AlgoPy",
journal = "Journal of Computational Science",
volume = "",
number = "0",
pages = " - ",
year = "2011",
note = "",
issn = "1877-7503",
doi = "10.1016/j.jocs.2011.10.007",
url = "http://www.sciencedirect.com/science/article/pii/S1877750311001013",
author = "Sebastian F. Walter and Lutz Lehmann",
keywords = "Automatic differentiation",
keywords = "Cholesky decomposition",
keywords = "Hierarchical approach",
keywords = "Higher-order derivatives",
keywords = "Numerical linear algebra",
keywords = "NumPy",
keywords = "Taylor arithmetic"
}
```

Licence:

BSD style using http://www.opensource.org/licenses/bsd-license.php template as it was on 2009-01-24 with the following substutions:

• <YEAR> = 2008-2009
• <OWNER> = Sebastian F. Walter, sebastian.walter@gmail.com
• <ORGANIZATION> = contributors' organizations
• In addition, "Neither the name of the contributors' organizations" was changed to "Neither the names of the contributors' organizations"