Skip to main content

jacobi

https://img.shields.io/pypi/v/jacobi https://github.com/scikit-hep/jacobi/actions/workflows/ci.yml/badge.svg https://img.shields.io/badge/github-docs-success https://img.shields.io/badge/github-source-blue https://zenodo.org/badge/DOI/10.5281/zenodo.7415783.svg

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

Click here for full documentation.

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

  • Faster than numdifftools at equivalent precision, up to 25x when the derivative is trivial

  • 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(x):
    return np.sin(x) / x


x = np.linspace(-10, 10, 200)
fx = f(x)

# f(x) is a simple vectorized function, jacobian is diagonal
fdx, fdxe = jacobi(f, x, diagonal=True)
# fdxe is uncertainty estimate for derivative

plt.plot(x, fx, color="k", label="$f(x) = sin(x) / x$")
plt.plot(x, fdx, label="$f'(x)$ computed with jacobi")
scale = 14
plt.fill_between(
    x,
    fdx - fdxe * 10**scale,
    fdx + fdxe * 10**scale,
    label=f"$f'(x)$ error estimate$\\times \\, 10^{{{scale}}}$",
    facecolor="C0",
    alpha=0.5,
)
plt.legend()
https://scikit-hep.org/jacobi/_images/example.svg
from jacobi import propagate
import numpy as np
from scipy.special import gamma


# arbitrarily complex function that calls compiled libraries, numba-jitted code, etc.
def fn(x):
    r = np.empty(3)
    r[0] = 1.5 * np.exp(-x[0] ** 2)
    r[1] = gamma(x[1] ** 3.1)
    r[2] = np.polyval([1, 2, 3], x[0])
    return r  # x and r have different lengths


# fn 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(fn, x, xcov)  # y=f(x) and ycov = J xcov J^T

Comparison to numdifftools

Speed

For typical functions, Jacobi is up to 2-3x faster than numdifftools (measured with Python 3.15, numpy 2.5 and numdifftools 0.11.2). It converges rapidly if the derivative is trivial, which gives a speedup of up to 25x.

Smaller run-time is better (and ratio > 1).

https://scikit-hep.org/jacobi/_images/speed.svg

Precision

The machine precision is indicated by the dashed line. Jacobi is comparable in accuracy to numdifftools. The error estimate has the right order of magnitude but slightly underestimates the true deviation. This does not matter for most applications.

https://scikit-hep.org/jacobi/_images/precision.svg

Metadata

Release files for jacobi 0.10.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for jacobi 0.10.0
File Size Uploaded Provenance Actions
jacobi-0.10.0.tar.gz 69.6 kB With provenance Details for jacobi-0.10.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for jacobi 0.10.0
File Interpreter ABI Platform Actions
jacobi-0.10.0-py3-none-any.whl Python 3 none any Details for jacobi-0.10.0-py3-none-any.whl

Total release size: 81.4 kB

Release files / jacobi-0.10.0.tar.gz

Download URL jacobi-0.10.0.tar.gz
Size 69.6 kB
Tags Source
SHA-256 checksum
How to use checksums
42216798a031a7bc9a30e866ffaddc4c99e7391cbb2be9da5c7a164674ef28cd
BLAKE2b-256 checksum
How to use checksums
8a2e38a7ce2bc9653c450f7de229d8c12ced65abac25ef4cb3e83e09f2d88eec
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 1, 2026.

Transparency log

Release files / jacobi-0.10.0-py3-none-any.whl

Download URL jacobi-0.10.0-py3-none-any.whl
Size 11.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3d78902222a3ea40520a605c7e777365a39368a21ff45ac29d0e801692c8fcf1
BLAKE2b-256 checksum
How to use checksums
f1d12b3397214629046bee25cc31e812d15ab3d7c39512701bb3e745e9621735
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 1, 2026.

Transparency log

Security for jacobi 0.10.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for jacobi-0.10.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 1, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page