Skip to content
Efficiently computes derivatives of numpy code.
Branch: master
Clone or download
j-towns Merge pull request #478 from CamDavidsonPilon/master
adding survival function & log survival function for normal dist
Latest commit 96a03f4 Feb 22, 2019
Type Name Latest commit message Commit time
Failed to load latest commit information.
conda_recipe BLD: conda recipe for support Nov 5, 2015
docs Merge pull request #347 from ericmjl/tutorial-syntax-patch Feb 24, 2018
examples Use print() function in both Python 2 and Python 3 Nov 26, 2018
tests adding log survival function for normal dist Feb 21, 2019
.travis.yml add all .h and .pyx files to (in case we make some later) Oct 23, 2015 Update README, add j-towns to primary author list Jun 14, 2018
license.txt Added MIT license Feb 19, 2015
setup.cfg Getting ready for PyPI Apr 10, 2015

Autograd Test status asv

Autograd can automatically differentiate native Python and Numpy code. It can handle a large subset of Python's features, including loops, ifs, recursion and closures, and it can even take derivatives of derivatives of derivatives. It supports reverse-mode differentiation (a.k.a. backpropagation), which means it can efficiently take gradients of scalar-valued functions with respect to array-valued arguments, as well as forward-mode differentiation, and the two can be composed arbitrarily. The main intended application of Autograd is gradient-based optimization. For more information, check out the tutorial and the examples directory.

Example use:

>>> import autograd.numpy as np  # Thinly-wrapped numpy
>>> from autograd import grad    # The only autograd function you may ever need
>>> def tanh(x):                 # Define a function
...     y = np.exp(-2.0 * x)
...     return (1.0 - y) / (1.0 + y)
>>> grad_tanh = grad(tanh)       # Obtain its gradient function
>>> grad_tanh(1.0)               # Evaluate the gradient at x = 1.0
>>> (tanh(1.0001) - tanh(0.9999)) / 0.0002  # Compare to finite differences

We can continue to differentiate as many times as we like, and use numpy's vectorization of scalar-valued functions across many different input values:

>>> from autograd import elementwise_grad as egrad  # for functions that vectorize over inputs
>>> import matplotlib.pyplot as plt
>>> x = np.linspace(-7, 7, 200)
>>> plt.plot(x, tanh(x),
...          x, egrad(tanh)(x),                                     # first  derivative
...          x, egrad(egrad(tanh))(x),                              # second derivative
...          x, egrad(egrad(egrad(tanh)))(x),                       # third  derivative
...          x, egrad(egrad(egrad(egrad(tanh))))(x),                # fourth derivative
...          x, egrad(egrad(egrad(egrad(egrad(tanh)))))(x),         # fifth  derivative
...          x, egrad(egrad(egrad(egrad(egrad(egrad(tanh))))))(x))  # sixth  derivative

See the tanh example file for the code.


You can find a tutorial here.

End-to-end examples

How to install

Just run pip install autograd


Autograd was written by Dougal Maclaurin, David Duvenaud, Matt Johnson, Jamie Townsend and many other contributors, and we're actively developing it. Please feel free to submit any bugs or feature requests. We'd also love to hear about your experiences with autograd in general. Drop us an email!

We want to thank Jasper Snoek and the rest of the HIPS group (led by Prof. Ryan P. Adams) for helpful contributions and advice; Barak Pearlmutter for foundational work on automatic differentiation and for guidance on our implementation; and Analog Devices Inc. (Lyric Labs) and Samsung Advanced Institute of Technology for their generous support.

You can’t perform that action at this time.