Automatic differentiation with dual numbers
Project description
HyperJet — Algorithmic Differentiation with Hyper-Dual numbers for Python and C++
A header-only library for algorithmic differentiation with hyper-dual numbers. Written in C++17 with an extensive Python interface.
Installation
pip install hyperjet
Quickstart
Import the module:
import hyperjet as hj
Create a set of variables e.g. x=3
and y=6
:
x, y = hj.variables([3, 6])
x
and y
are hyper-dual numbers. This is indicated by the postfix hj
:
x
>>> 3hj
Get the value as a simple float
:
x.f
>>> 3
The hyper-dual number stores the derivatives as a numpy array.
Get the first order derivatives (Gradient) of a hyper-dual number:
x.g # = [dx/dx, dx/dy]
>>> array([1., 0.])
Get the second order derivatives (Hessian matrix):
x.hm() # = [[d^2 x/ dx**2 , d^2 x/(dx*dy)],
# [d^2 x/(dx*dy), d^2 x/ dy**2 ]]
>>> array([[0., 0.],
[0., 0.]])
For a simple variable these derivatives are trivial.
Now do some computations:
f = (x * y) / (x - y)
f
>>> -6hj
The result is again a hyper-dual number.
Get the first order derivatives of f
with respect to x
and y
:
f.g # = [df/dx, df/dy]
>>> array([-4., 1.])
Get the second order derivatives of f
:
f.hm() # = [[d^2 f/ dx**2 , d^2 f/(dx*dy)],
# [d^2 f/(dx*dy), d^2 f/ dy**2 ]]
>>> array([[-2.66666667, 1.33333333],
[ 1.33333333, -0.66666667]])
You can use numpy to perform vector and matrix operations.
Compute the nomalized cross product of two vectors u = [1, 2, 2]
and v = [4, 1, -1]
with hyper-dual numbers:
import numpy as np
variables = hj.DDScalar.variables([1, 2, 2,
4, 1, -1])
u = np.array(variables[:3]) # = [1hj, 2hj, 2hj]
v = np.array(variables[3:]) # = [4hj, 1hj, -1hj]
normal = np.cross(u, v)
normal /= np.linalg.norm(normal)
normal
>>> array([-0.331042hj, 0.744845hj, -0.579324hj], dtype=object)
The result is a three-dimensional numpy array containing hyper-dual numbers.
Get the value and derivatives of the x-component:
normal[0].f
>>> -0.3310423554409472
normal[0].g
>>> array([ 0.00453483, -0.01020336, 0.00793595, 0.07255723, -0.16325376, 0.12697515])
normal[0].hm()
>>> array([[ 0.00434846, -0.01091775, 0.00647611, -0.0029818 , -0.01143025, -0.02335746],
[-0.01091775, 0.02711578, -0.01655522, 0.00444165, 0.03081974, 0.04858632],
[ 0.00647611, -0.01655522, 0.0093492 , -0.00295074, -0.02510461, -0.03690759],
[-0.0029818 , 0.00444165, -0.00295074, -0.02956956, 0.03025289, -0.01546811],
[-0.01143025, 0.03081974, -0.02510461, 0.03025289, 0.01355789, -0.02868433],
[-0.02335746, 0.04858632, -0.03690759, -0.01546811, -0.02868433, 0.03641839]])
Reference
If you use HyperJet, please refer to the official GitHub repository:
@misc{HyperJet,
author = "Thomas Oberbichler",
title = "HyperJet",
howpublished = "\url{http://github.com/oberbichler/HyperJet}",
}
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Hashes for hyperjet-1.4.3-pp37-pypy37_pp73-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a078a53058bc09be8ab48e9fba91f36510fce510977b494d2efa4e90d49efd27 |
|
MD5 | 4b1aec003b6480f5b1a0004d04aae4d8 |
|
BLAKE2b-256 | b5eb847b40c622eafad426adb177dbda7ae8ea8728fa625254088633abb67e0f |
Hashes for hyperjet-1.4.3-pp37-pypy37_pp73-manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b776edb6fc32fca902be158c11c569946f3ca50e0b95eb1ba9b80d944b553370 |
|
MD5 | e166c9dd96db90b2e96e19309fc0b754 |
|
BLAKE2b-256 | 9bff99033e2159347c9e22878ff4d639bdfd7a1422a6954f0b6a7cfd512f2aaf |
Hashes for hyperjet-1.4.3-pp37-pypy37_pp73-manylinux_2_12_i686.manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 23cedc8509b4a01b66bee28d47ea863d34225353ad87cdb588f69842e001294d |
|
MD5 | 3e5012438f6ad6a8542352360997a8e7 |
|
BLAKE2b-256 | 8bb16cf25e7347a940c3ead896db810ef9ab61dfcf837cf5ea1189676d5691f0 |
Hashes for hyperjet-1.4.3-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 94c390aee62830653820476815a09dcd6741b63cef435bdf03997a6c2b1dc231 |
|
MD5 | d2d776cc32ea9b9331838893a2171556 |
|
BLAKE2b-256 | d98fe10093f236b2797dddf3a519b90d279194207b7cfeba777b57182d5f7349 |
Hashes for hyperjet-1.4.3-cp39-cp39-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 25732a755776ed326557a4de6fa9f53b20e5bd472112193bdf69f0ecec7fde49 |
|
MD5 | e4657c3cedb0776b9141ed2fc35477a7 |
|
BLAKE2b-256 | 4d34f39b05698c4783918db8029741cb10ad8855b97353870a4e1699f8f46a83 |
Hashes for hyperjet-1.4.3-cp39-cp39-manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6b46e92022d2da61cdeae09011d54c080f14f176b9426c894b2d837e7ab78128 |
|
MD5 | 595c8d8a4df317299601c6340a5c0b72 |
|
BLAKE2b-256 | 385dfe3539b2f0f8902e02c37492f368347cbe4a270b1ba7173878e032027f3b |
Hashes for hyperjet-1.4.3-cp39-cp39-manylinux_2_12_i686.manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1c2f8b20ddaec03815b7e238799830638547b364374d51fa99f1025a38c66f5c |
|
MD5 | 7c0f1cc9a2f4f56b630a4b6d163a8b89 |
|
BLAKE2b-256 | f37d6bb76860fe9de846d7b984e682b75f7aea9608bcaefabb8c5ec881673f39 |
Hashes for hyperjet-1.4.3-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 49f63867adec7682267b3475f7ee92a427da03926cf82caaaa0aa2b7fe9a5e1d |
|
MD5 | 50b1458d5992ded1b8c396f0e6f314c5 |
|
BLAKE2b-256 | 2631903e308ad48ce9858ee885cd6b4eef79858ca7cbf667d37546f0c4b55d29 |
Hashes for hyperjet-1.4.3-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a2b72898f6c9fc6e515ba9e1c2a465d631585c5feaa49ee62261711d1b949e66 |
|
MD5 | 0c5e525a701029db9b717fb3fe4a8de6 |
|
BLAKE2b-256 | 72dc51885b9de1da388c090ee5ba2f14ddc60877269e35418c5450572739fcee |
Hashes for hyperjet-1.4.3-cp38-cp38-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7380bfae485b6c3ee1deb8a956ebb07928b6d4f966e9f1240a3120b2422b6ef5 |
|
MD5 | ddd985b947c841d1bb3afd5a1a868af0 |
|
BLAKE2b-256 | 2485a68c9300fc40b1b41d011b4bb43b6436ba794f9c91e2dcfd647f32c9a119 |
Hashes for hyperjet-1.4.3-cp38-cp38-manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5b25449ae9cc7035b0d59d4027eb2f4bf8fd823fe72b69a5da1f4930b15539aa |
|
MD5 | 995f79fcf322d06c5ed317f665e8e641 |
|
BLAKE2b-256 | e8093d0fececd1f61eb9afbd1fceef883079a34e75b8593f8adbe7ddcdf42654 |
Hashes for hyperjet-1.4.3-cp38-cp38-manylinux_2_12_i686.manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6a98dda8f481b6dac657c587dd46fa4f8213777fc46a1728bd1e82b2fbbac0b2 |
|
MD5 | aafa8818bab92243f6eceb0087dd2783 |
|
BLAKE2b-256 | aa4229ed8c5faa143988ad27f331fcef1a7eb8280d3ac0abdf42d7e9dd3f8252 |
Hashes for hyperjet-1.4.3-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1c11df90ea808161e6f30e382983efef16323e98b3450174d626d51a802daef4 |
|
MD5 | 908270a5680d4b439f712f920548dbe3 |
|
BLAKE2b-256 | a346386e7b276c4c5b7ab37c341a462549c7c1d2067373ad49e49a84b16a2467 |
Hashes for hyperjet-1.4.3-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d6fc49be5f55db42bda419bab7203fd2686ffd2641be7f7a3a3a120baca1d59e |
|
MD5 | 9812eef94373d4364fa40493765fcde1 |
|
BLAKE2b-256 | 3835a50350f9f99b6e22cd5f9e31a8fd6932f592bcc7574fa0443248009d6db4 |
Hashes for hyperjet-1.4.3-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e4e859bfa2dabef9175f1551de5279a7e842886118c4b858820fe50597742f61 |
|
MD5 | 1211f4f5420c25d9cf09fc7cc76b48e6 |
|
BLAKE2b-256 | 69f53ab6c657a4b57c12cbc3730b6593952b67216e95307b088103422bf60ff4 |
Hashes for hyperjet-1.4.3-cp37-cp37m-manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a568692950ddf86dca58ec17a3fe3076ea31dc79aae1097d46a3471ee680cdb1 |
|
MD5 | 90346c7bc5040276c798b25836b8256d |
|
BLAKE2b-256 | bcdcc056e1ce183ee9f86ff1ba5f0214f780b4a8da98096e2286039fb91deba4 |
Hashes for hyperjet-1.4.3-cp37-cp37m-manylinux_2_12_i686.manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bf34008753ed16d1d6ecb724b774de7ca5cc4689474f37a885e4947c1353ffb0 |
|
MD5 | 43e2d1ad5805711402076adb9a019739 |
|
BLAKE2b-256 | 37246a7baeb7ecf4527a4103e3d1244ccced34cd97894907fcf26813b0d5af26 |
Hashes for hyperjet-1.4.3-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d40ae71be58ee904fb1555ac9a6340bf4e3f2905f4bc62d03474f54899df62f6 |
|
MD5 | d9dfd573352b5dd0443c70c3c9221523 |
|
BLAKE2b-256 | 6f249698713d06a450baa0f8d4ebba6bc0031572fc6bf7f3c42665f1fde15f37 |
Hashes for hyperjet-1.4.3-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ca181e3e58de9d9a5e1f81f2eb9d5782407a3adb6b3d40700671116959629c81 |
|
MD5 | bafb03fbfa956d62914b4956cca60238 |
|
BLAKE2b-256 | fa75133d38c522ac4295e4099d0f727a8031b5ba7aab7250022b6cdb382c5b02 |
Hashes for hyperjet-1.4.3-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 715dba2e573f500f3d4f5b1c4eb09e6f99b12334ef228fa80682879820d48954 |
|
MD5 | b0c7f62ccff0e2efa12e44983d1971a5 |
|
BLAKE2b-256 | 3685effd8896f5c9717de3c30ebbd48fd8180ff86fdc30df140bc3088b0f3c66 |
Hashes for hyperjet-1.4.3-cp36-cp36m-manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ce0d0f0de8f4c9e0e05a07fc0065f6e0b9aee8812b015fc6c526c426054e0a73 |
|
MD5 | c07d6ee8d9dd1a3c5c57f96dbe04956e |
|
BLAKE2b-256 | f8c1df951b799768cd4d18c4d0c97879150379dfe6e406cdf70ebd672f0cd353 |
Hashes for hyperjet-1.4.3-cp36-cp36m-manylinux_2_12_i686.manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9f9b8177857659198fabffff7d26748cecb8a23ca97c90e940c0b992d57cd600 |
|
MD5 | 9b416c4c78cffc05aaa860d646af5feb |
|
BLAKE2b-256 | 569bed135db1d05e01069c9c042fc2598fcb216b4b85843f7a18b01700024e72 |
Hashes for hyperjet-1.4.3-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9f49365c30a68247556e0eb3640995e7b2bb690ba670bdfd0cfa2ba346fc071c |
|
MD5 | 75445dccb06091a1154e0fe05fdfca7b |
|
BLAKE2b-256 | efe17f1736ba1f28ab6cd7f4cadde2c99a29c1cfc631d20538bc90f6e645246a |