Skip to main content

Numerical Derivative Checker

This package contains a numericcal derivative checker that can be used to verify first or second order derivatives by comparing them to the central finite difference approximation.

The following combinations of input and output types are currently supported

Derivative order Output type
scalar vector
scalar first / second first
Input type vector first / second first
matrix first ---

Sampling types

In helper_functions.py, there are different sampling routines defined to randomize the function inputs. The following samplers are currently implemented:

  • ScalarSampler
  • VectorSampler
  • MatrixSampler
  • PosDefMatrixSampler

Each sampling routine has various parameters such as minimum/maximum values or dimensionality.

Examples

Scalar input and output: f(x) = x**2

from numerical_derivative_checker import check_derivative, ScalarSampler
check_derivative(sampler=ScalarSampler(n_samples=200),
                 fun=lambda x: np.sin(x),
                 grad=lambda x: np.cos(x),
                 hess=lambda x: -np.sin(x))

Vector input and scalar output: f(x) = x^T A x

from numerical_derivative_checker import check_derivative, VectorSampler
A = np.random.rand(5, 5)
check_derivative(sampler=VectorSampler(n=5),
                 fun=lambda x: x @ A @ x,
                 grad=lambda x: (A + A.T) @ x)

Pos. def. matrix input and scalar output: f(X) = log(det(X))

from numerical_derivative_checker import check_derivative, PosDefMatrixSampler
check_derivative(sampler=PosDefMatrixSampler(n=3),
                 fun=lambda x: np.linalg.det(x),
                 grad=lambda x: np.linalg.det(x) * np.linalg.inv(x),
                 tol=1e-3)

see examples.py for more examples.

Release files for numerical-derivative-checker 0.8

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

Source distribution (sdist)

Source distribution for numerical-derivative-checker 0.8
File Size Uploaded
numerical_derivative_checker-0.8.tar.gz 4.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for numerical-derivative-checker 0.8
File Interpreter ABI Platform
numerical_derivative_checker-0.8-py3-none-any.whl Python 3 none any Details

Total release size: 14.7 kB

Release files / numerical_derivative_checker-0.8.tar.gz

Download URL numerical_derivative_checker-0.8.tar.gz
Size 4.4 kB
Tags Source
SHA-256 checksum
How to use checksums
904099158d459ce1e455170aef2d85a03647eff4ae0d08b0b9720ff97bc713b9
BLAKE2b-256 checksum
How to use checksums
1a6b0a3dcc80c5f1284f694e25c2743a27751ee292e78c15d2066fea8808f443
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.7.9

Release files / numerical_derivative_checker-0.8-py3-none-any.whl

Download URL numerical_derivative_checker-0.8-py3-none-any.whl
Size 10.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9dabb7c5e8ea14eb4cdc925cbc83157268fb8120dabe597f13a9b37412daced7
BLAKE2b-256 checksum
How to use checksums
7369960332b2f70faac2b235885c756144b8a8ed51bac85d3f963c006d918c24
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.7.9

Release history Release notifications | RSS feed

This release

0.8 This release

2 release files

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