MIT License

项目介绍

HIPS/autograd 是一个托管在 GitHub 上的开源项目,主要使用 Python 编写,采用 MIT License 许可证,目前获得 7.6k 个 Star、956 次 Fork。

仓库全名
HIPS/autograd
开源许可证
MIT License
Star 数
7.6k
Fork 数
956
未关闭 Issue
211

README 摘要

[publish-url]: https://github.com/HIPS/autograd/actions/workflows/publish.yml [checks-url]: https://github.com/HIPS/autograd/actions/workflows/check.yml [tests-url]: https://github.com/HIPS/autograd/actions/workflows/test.yml 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…

完整内容见 GitHub 原始 README 或本页 。

常见问题

autograd 用什么语言开发?

主要使用 Python 编写,采用 MIT License 许可证,目前有 7.6k 个 Star。

autograd 可以免费商用吗?

仓库采用 MIT License 许可证,可免费使用与修改,商业使用请遵守许可证条款(例如保留版权声明与许可声明)。

如何获取 autograd 的源码?

可以直接克隆仓库:git clone https://github.com/HIPS/autograd.git,默认分支为 master;安装与运行步骤见仓库 README。

autograd 最近还在维护吗?

仓库最近一次更新为 1 天前,当前有 211 个未关闭 Issue;Star 数为 7.6k,可作为社区活跃度的参考。

README

Autograd Checks status Tests status Publish 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
...     return (1.0 - np.exp((-2 * x))) / (1.0 + np.exp(-(2 * x)))
...
>>> grad_tanh = grad(tanh)       # Obtain its gradient function
>>> grad_tanh(1.0)               # Evaluate the gradient at x = 1.0
np.float64(0.419974341614026)
>>> (tanh(1.0001) - tanh(0.9999)) / 0.0002  # Compare to finite differences
np.float64(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, 700)
>>> 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
>>> plt.show()

See the tanh example file for the code.

Documentation

You can find a tutorial here.

End-to-end examples

How to install

Install Autograd using Pip:

pip install autograd

Some features require SciPy, which you can install separately or as an optional dependency along with Autograd:

pip install "autograd[scipy]"

Authors and maintainers

Autograd was written by Dougal Maclaurin, David Duvenaud, Matt Johnson, Jamie Townsend and many other contributors. The package is currently being maintained by Agriya Khetarpal, Fabian Joswig and Jamie Townsend. 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.

评论

暂无评论