• Stars
    star
    6,959
  • Rank 5,631 (Top 0.2 %)
  • Language
    Python
  • License
    MIT License
  • Created almost 10 years ago
  • Updated about 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Efficiently computes derivatives of NumPy code.

Note: Autograd is still being maintained but is no longer actively developed. The main developers (Dougal Maclaurin, David Duvenaud, Matt Johnson, and Jamie Townsend) are now working on JAX, with Dougal and Matt working on it full-time. JAX combines a new version of Autograd with extra features such as jit compilation.

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
0.41997434161402603
>>> (tanh(1.0001) - tanh(0.9999)) / 0.0002  # Compare to finite differences
0.41997434264973155

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
>>> plt.show()

See the tanh example file for the code.

Documentation

You can find a tutorial here.

End-to-end examples

How to install

Just run pip install autograd

Authors

Autograd was written by Dougal Maclaurin, David Duvenaud, Matt Johnson, Jamie Townsend and many other contributors. The package is currently still being maintained, but is no longer actively developed. 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.

More Repositories

1

Spearmint

Spearmint Bayesian optimization codebase
Python
1,544
star
2

neural-fingerprint

Convolutional nets which can take molecular graphs of arbitrary size as input.
TeX
494
star
3

hypergrad

Exploring differentiation with respect to hyperparameters
Python
296
star
4

Kayak

Kayak is a library for automatic differentiation with applications to deep neural networks.
Python
227
star
5

Probabilistic-Backpropagation

Implementation in C and Theano of the method Probabilistic Backpropagation for scalable Bayesian inference in deep neural networks.
C
191
star
6

molecule-autoencoder

A project to enable optimization of molecules by transforming them to and from a continuous representation.
Python
154
star
7

pgmult

Dependent multinomials made easy: stick-breaking with the Pรณlya-gamma augmentation
Python
60
star
8

hips-lib

Library of common tools for machine learning research.
Python
40
star
9

author-roulette

LaTeX package for randomizing author order based on a public seed.
TeX
39
star
10

firefly-monte-carlo

Implementation of an algorithm for Markov chain Monte Carlo with data subsampling
Python
31
star
11

maxwells-daemon

Fastidious accounting of entropy streams into and out of optimization and sampling algorithms.
TeX
31
star
12

DESI-MCMC

MCMC for the Dark Energy Spectroscopic Instrument
Jupyter Notebook
13
star
13

BayesianStructuredSparsity

Code for performing Bayesian regression with structured sparsity from a Gaussian field.
8
star
14

autopaint

Gradient-based variational autoencoders to generate class-conditional natural images.
Python
6
star
15

gpu_numpy

A Numpy wrapper that adds a gpufloat32 dtype to Numpy.
Python
6
star
16

trusty_scribe_viewer

Website for viewing a git repo as a lab notebook. Figures and text files can be included with markdown-like syntax.
Python
4
star
17

optofit

A python framework for fitting biophysical models to optically recorded neural signals.
Python
4
star
18

lpickle

Linefeed-delimited pickle for Unix-style piping of arbitrary Python data
Python
2
star
19

Matrical

A simple abstraction layer for matrix computations in Python, making it easy to switch between CPU and NVIDIA or Intel coprocessors.
2
star