Auto Differentiation Tools
Project description
cs107-FinalProject, Group 16
| Group members | |
|---|---|
| Connor Capitolo | connorcapitolo@g.harvard.edu |
| Kexin Huang | kexinhuang@hsph.harvard.edu |
| Haoxin Li | haoxin_li@hsph.harvard.edu |
| Chen Lucy Zhang | chz522@g.harvard.edu |
Installation (we assume you are familiar with virtual environments and Git)
# install virtualenv
pip install virtualenv
# create virtual environment
virtualenv apollo_ad_env
# activate virtual environment
source apollo_ad_env/bin/activate
# clone from GitHub
git clone https://github.com/West-Coast-Quaranteam/cs107-FinalProject.git
# get into the folder
cd cs107-FinalProject
# install requirements
pip install -r requirements.txt
# Test the package
# From directory apollo_ad/tests/ run the module test.py
pytest test_scalar.py
Examples
We show two examples here to use apollo_ad.
First, to calculate the derivative of y = cos(x) + x^2 at x = 2:
from apollo_ad.apollo_ad import *
x = Variable(2)
y = Variable.cos(x) + x ** 2
print(y) # Value: 3.5838531634528574 , Der: [3.09070257]
print(y.var) # 3.583853163452857
print(y.der) # [3.09070257]
assert y.var == np.cos(2) + 4
assert y.der == -np.sin(2) + 2 * 2
Second, to calculate the derivative of y = 2 * log(x) - sqrt(x) / 3 at x = 2:
from apollo_ad.apollo_ad import *
x = Variable(2)
y = 2 * Variable.log(x) - Variable.sqrt(x)/3
print(y) # Value: 0.9148898403288588 , Der: [0.88214887]
print(y.var) # 0.9148898403288588
print(y.der) # [0.88214887]
assert np.around(y.var, 4) == np.around(2 * np.log(2) - np.sqrt(2)/3, 4)
assert np.around(y.der, 4) == np.around(2 * 1/2 - 1/3 * 1/2 * 2**(-1/2), 4)
You can also run the above examples by:
python demo.py
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
apollo_ad-0.0.3.tar.gz
(7.2 kB
view details)
File details
Details for the file apollo_ad-0.0.3.tar.gz.
File metadata
- Download URL: apollo_ad-0.0.3.tar.gz
- Upload date:
- Size: 7.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
005d8510700fbe36f3cb65c55f88e0863ef6dbad1f90f5b95c066ddc8405e78f
|
|
| MD5 |
5902f5112df3bf4241a9dc90cdb69787
|
|
| BLAKE2b-256 |
216d5356b34747e8fb8ee9f07f34965343c6470f8c726fea21f9ca14181445a9
|