Dualitic is a Python package for forward mode automatic differentiation using dual numbers.
- Seamlessly wrap NumPy and SciPy functions to enable automatic differentiation of any code. No need to rewrite models.
- Define dual variables that can be treated like normal NumPy arrays which track derivatives.
- Multivariate dual variables allow computing multiple derivatives at once.
- Dual arrays can be used with neural networks, optimization, and more.
- Lightweight and easy to use.
To install, clone the repository and pip install.
git clone https://github.com/jaimeliew1/Dualitic.git
cd dualitic
pip install .
(Pypi installation comming soon)
Import Dualitic and create a dual number by defining its real and dual part:
import dualitic as dl
x = dl.DualNumber(3.0, [1.0])
print(x)
# DualNumber([3.], [[1.]])
print(x.real)
# [3.]
print(x.dual)
# [[1.]]
The .real
attribute holds the primal value and .dual
holds the derivatives.
Pass dual variables into NumPy/SciPy functions as normal:
import numpy as np
y = np.sin(x)
print(y.real)
# [0.14112001]
print(y.dual)
# [[-0.9899925]]
The derivative is computed automatically through the dual number propagation!
See the documentation for more examples and API details. Dualitic enables derivative computation with only minor changes to existing code!
Dualitic can theoretically function with all Numpy and Scipy continuous functions, however not all methods have been implemented. See the function list for a comprehensive overview of implemented Numpy and Scipy functions, as well as functions which are not yet implemented.