NumGrad
Simple gradient computation library for Python.
Getting Started
pip install numgrad
Inspired by tensorflow, numgrad supports automatic differentiation in tensorflow v2 style using original numpy and scipy functions.
>>> import numgrad as ng
>>> import numpy as np # Original numpy
>>>
>>> # Pure numpy function
>>> def tanh(x):
... y = np.exp(-2 * x)
... return (1 - y) / (1 + y)
...
>>> x = ng.Variable(1)
>>> with ng.Graph() as g:
... # numgrad patches numpy functions automatically here
... y = tanh(x)
...
>>> g.backward(y, [x])
(0.419974341614026,)
>>> (tanh(1.0001) - tanh(0.9999)) / 0.0002
0.41997434264973155
numgrad also supports jax style automatic differentiation.
>>> import numgrad as ng
>>> import numpy as np # Original numpy unlike `jax`
>>>
>>> power_derivatives = [lambda a: np.power(a, 5)]
>>> for _ in range(6):
... power_derivatives.append(ng.grad(power_derivatives[-1]))
...
>>> [f(2) for f in power_derivatives]
[32, 80.0, 160.0, 240.0, 240.0, 120.0, 0.0]
>>> [f(-1) for f in power_derivatives]
[-1, 5.0, -20.0, 60.0, -120.0, 120.0, -0.0]
Contribute
Be sure to run the following command before developing
$ git clone https://github.com/ctgk/numgrad.git
$ cd numgrad
$ pre-commit install
Release files for numgrad 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| numgrad-0.3.0.tar.gz | 21.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| numgrad-0.3.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 45.1 kB
Release files / numgrad-0.3.0.tar.gz
| Download URL | numgrad-0.3.0.tar.gz |
|---|---|
| Size | 21.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e5fb113bcc6b222b784a5f7ee0eff1ed5a6a07f84d5f05d9612226e8e8c427ac
|
|
BLAKE2b-256 checksum How to use checksums |
59abad865ad0d66d50eb5b9a1c9e1137adeb12699c64d7fea30dc5aaf8b64e92
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.11.9
|
Release files / numgrad-0.3.0-py3-none-any.whl
| Download URL | numgrad-0.3.0-py3-none-any.whl |
|---|---|
| Size | 24.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a80ce2769a02a429e7985ff04a772a969f0d99488e6107c58ff85bf9ea40492b
|
|
BLAKE2b-256 checksum How to use checksums |
3185b042e2238d861e2f3b958e2d3bfe54fa90eb314cf668a9e1411c7367ea65
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.11.9
|