Registry / ai-ml / jacobi

jacobi

JSON →
library0.9.2pypypi✓ verified 21d ago

Jacobi is a lightweight Python library designed for fast and robust computation of generalized Jacobi matrices (numerical derivatives) for arbitrary real analytic mappings. It supports functions with large round-off errors and offers significant speed improvements over other numerical differentiation tools. The current version is 0.9.2, and it typically releases updates as needed.

pip install jacobi
INSTALL
IMPORT
SIG · JACOBI
J
jacobi
ai-mlpythonv0.9.2
Install
3.6s avg
Import
248ms
Disk
89MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.9.2 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.248s · 89.4MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 3.6s · import 0.248s · 86MB
89MB installed
● package 89MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

jacobi
from jacobi import jacobi
propagate
from jacobi import propagate
Used for statistical error propagation based on numerically computed Jacobians.

This quickstart demonstrates how to compute the generalized Jacobi matrix for a vector-valued function and a scalar-valued function with an auxiliary argument using `jacobi.jacobi`. It returns both the derivative and its error estimate.

import numpy as np from jacobi import jacobi def my_function(x): return np.array([np.sin(x[0]) * x[1], np.exp(x[0] + x[1])]) # Point at which to compute the Jacobian x0 = np.array([1.0, 2.0]) # Compute the Jacobian matrix and its error estimate jacobian_matrix, error_estimate = jacobi(my_function, x0) print(f"Function: f(x) = [sin(x[0]) * x[1], exp(x[0] + x[1])]") print(f"Point x0: {x0}") print(f"Computed Jacobian matrix:\n{jacobian_matrix}") print(f"Error estimate for Jacobian:\n{error_estimate}") # Example with a function returning a scalar and an auxiliary argument def scalar_func(param, x): return np.sin(x * param) aux_param = 0.5 x_scalar = np.array([np.pi / 2]) scalar_derivative, scalar_error = jacobi(scalar_func, aux_param, x_scalar) print(f"\nFunction: g(param, x) = sin(x * param) where param={aux_param}") print(f"Point x_scalar: {x_scalar}") print(f"Derivative w.r.t. param: {scalar_derivative}") print(f"Error estimate: {scalar_error}")
Debug
Known issues
gotchaThe `jacobi` function is designed for real analytic mappings. While robust, its accuracy can be affected by highly non-smooth or non-analytic functions. Ensure the function you are differentiating is suitable for numerical differentiation methods.
fix
Verify the mathematical properties of the function being differentiated. For highly non-smooth functions, other techniques like automatic differentiation (if applicable) or specialized numerical methods might be more appropriate.
affects: All versions
gotchaWhen differentiating a function that returns a 1D array where the Jacobian is known to be diagonal (e.g., an element-wise operation), passing `diagonal=True` to the `jacobi` function can significantly speed up computation. Omitting this for such cases will still yield correct results but might be less efficient.
fix
For functions `f(x)` where `f[i]` only depends on `x[i]`, pass `diagonal=True` as an argument to `jacobi(f, x, diagonal=True)` to optimize performance.
affects: All versions
gotchaThe `jacobi` library relies on `numpy` for its numerical operations. Performance can be influenced by how efficiently `numpy` handles the function being differentiated. Vectorized functions tend to perform better.
fix
Where possible, define the function to be differentiated using vectorized `numpy` operations to maximize performance.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'jacobi'
The 'jacobi' library has not been installed in the Python environment, or the environment where it was installed is not active.
fix
Install the library using pip: `pip install jacobi`
AttributeError: module 'jacobi' has no attribute 'jacobian'
This error typically occurs if a user tries to access a function directly from the top-level 'jacobi' module that is actually nested within a submodule, or if the function name is misspelled.
fix
The main function for computing the Jacobian is often directly available after import, but if not, ensure the correct function name and import path is used, e.g., `from jacobi import jacobian` or if it's within a specific submodule, `from jacobi.api import jacobian` (adjusting 'api' to the actual submodule if necessary, but 'jacobian' is typically top-level for this library).
TypeError: 'numpy.ndarray' object cannot be interpreted as an integer
This error often arises when a numerical function within 'jacobi' (or its underlying numpy operations) expects a scalar input (like `x0` or step size), but receives a NumPy array, or vice-versa, indicating a mismatch in expected input types for numerical operations.
fix
Ensure that function arguments are of the correct type and shape as expected by the `jacobi` function. For instance, if a scalar is expected for `x0`, pass `x0=1.0` instead of `x0=np.array([1.0])`.
Upgrade
Version history
0.9.2latest on PyPI · released Aug 16, 2023
Audit
Dependencies
numpyrequiredRequired for numerical operations and array manipulation.
Agent activity
7 hits · last 30 days
node
6
Resources
jacobi — pip install jacobi · libregistry