Not Logged In

ADiPy 0.6.1

ADiPy is a fast, pure-python automatic differentiation (AD) library. This
package provides the following functionality:

Arbitrary order univariate differentiation

First-order multivariate differentiation

Univariate Taylor polynomial function generator

Jacobian matrix generator

Compatible linear algebra routines

Installation

To install adipy, simply do one of the following in a terminal window
(administrative priviledges may be required):

Download the tarball, unzip, then run python setup.py install in the
unzipped directory.

Run easy_install [--upgrade] adipy

Run pip install [--upgrade] adipy

Where to Start

To start, we use the simple import:

from adipy import *

This imports the necessary constructors and elementary functions (sin, exp,
sqrt, etc.) as well as np which is the root NumPy module.

Now, we can construct AD objects using either ad(...) or adn(...). For
multivariate operations, it is recommended to construct them all at once using
the ad(...) function, but this is not required. The syntax is only a little
more complicated if they are initialized separately.

As can be seen in the examples, when an AD object is printed out, you see two
sets of numbers. The first is the nominal value, or the zero-th derivative.
The next set of values are the 1st through the Nth order derivatives, evaluated
at the nominal value.

Multivariate Examples

For multivariate sessions, things look a little bit different and can only
handle first derivatives (for the time being), but behave similarly:

This essentially just performed the **2 operator on each object individually,
so we can see the derivatives for each array index and how they are not
dependent on each other. Using standard indexing operations, we can access the
individual elements of an AD multivariate object:

print x[0]
# output is:
# ad(-1, array([ 1., 0., 0.]))

What if we want to use more than one AD object in calculations? Let’s see what
happens:

For the object y, we can’t yet use the d(...) function yet, because it is
technically a list at this point. However, we can convert it to a single,
multivariate AD object using the unite function, then we’ll have access
to the d(...) function. The jacobian function’s result is the same in
both cases:

This allows all the partial derivatives to be tracked, noted at the respective
unitary index at initialization. Conversely to singular construction, we can
break-out the individual elements, if desired:

x, y, z = ad([np.array([-1, 2.1, 0.25]))

And the results are the same.

Univariate Taylor Series Approximation

For univariate functions, we can use the taylorfunc function to generate
an callable function that allows approximation to some specifiable order:

The “at” keyword designates the point that the series is expanded about, which
will likely always be at the nominal value of the original independent AD
object (e.g., x.nom). Now, we can use fz whenever we need to
approximate x*sin(x**2), but know that the farther it is evaluated from
x.nom, the more error there will be in the approximation.

If Matplotlib is installed, we can see the difference in the order of the
approximating Taylor polynomials:

Notice that at x=1.5, all the approximations are perfectly accurate (as we
would expect) and error increases as the approximation moves farther from that
point, but less so with the increase in the order of the approximation.

Linear Algebra

Several linear algebra routines are available that are AD-compatible:

Decompositions

Cholesky (chol)

QR (qr)

LU (lu)

Linear System solvers

General solver, with support for multiple outputs (solve)

Least squares solver (lstsq)

Matrix inverse (inv)

Matrix Norms

Frobenius norm, or 2-norm (norm)

These require a separate import import adipy.linalg, then they can be
using something like adipy.linalg.solve(...).

See the source code for relevant documentation and examples. If you are
familiar with NumPy’s versions, you will find these easy to use.

Support

Please contact the author with any questions, comments, or good examples of
how you’ve used adipy!

License

This package is distributed under the BSD License. It is free for public and
commercial use and may be copied royalty free, provided the author is given
credit.