Skip to main content

Compute numerical derivatives.

Project description

https://img.shields.io/pypi/v/jacobi https://img.shields.io/badge/github-docs-success https://img.shields.io/badge/github-source-blue

Fast numerical derivatives for real analytic functions with arbitrary round-off error.

Features

  • Robustly compute the generalised Jacobi matrix for an arbitrary real analytic mapping ℝⁿ → ℝⁱ¹ × … × ℝⁱⁿ

  • Derivative is either computed to specified accuracy (to save computing time) or until maximum precision of function is reached

  • Algorithm based on John D’Errico’s DERIVEST: works even with functions that have large round-off error

  • Up to 1200x faster than numdifftools at equivalent precision

  • Returns error estimates for derivatives

  • Supports arbitrary auxiliary function arguments

  • Perform statistical error propagation based on numerically computed jacobian

  • Lightweight package, only depends on numpy

Planned features

  • Compute the Hessian matrix numerically with the same algorithm

  • Further generalize the calculation to support function arguments with shape (N, K), in that case compute the Jacobi matrix for each of the K vectors of length N

Examples

from matplotlib import pyplot as plt
import numpy as np
from jacobi import jacobi


# function of one variable with auxiliary argument; returns a vector
def f(dx, x0):
    x = x0 + dx
    return np.sin(x) / x


x = np.linspace(-10, 10, 1000)
fx = f(0, x)
fdx, fdex = jacobi(f, 0, x)

plt.plot(x, fx, label="f(x) = sin(x) / x")
plt.plot(x, fdx, ls="--", label="f'(x)")
plt.legend()
https://hdembinski.github.io/jacobi/_images/example.svg
from jacobi import propagate
import numpy as np

# arbitrarily complex function that calls in compiled libraries etc
def f(x):
    a = 1.5
    b = 3.1
    return a * np.exp(-x ** 2) + b

# f accepts a parameter vector x, which has an associated covariance matrix xcov
x = [1.0, 2.0]
xcov = [[1.1, 0.1], [0.1, 2.3]]
y, ycov = propagate(f, x, xcov)  # y=f(x) and ycov = J xcov J^T

Comparison to numdifftools

Speed

Jacobi makes better use of vectorised computation than numdifftools. Smaller run-time is better (and ratio > 1).

https://hdembinski.github.io/jacobi/_images/speed.svg

Precision

The machine precision is indicated by the dashed line.

https://hdembinski.github.io/jacobi/_images/precision.svg

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

jacobi-0.3.0.tar.gz (435.5 kB view hashes)

Uploaded Source

Built Distribution

jacobi-0.3.0-py3-none-any.whl (8.0 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page