Skip to main content

Simple numerical derivative checker with randomized input sampling.

Project description

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.

Project details


Release history Release notifications | RSS feed

This version

0.8

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

numerical_derivative_checker-0.8.tar.gz (4.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

numerical_derivative_checker-0.8-py3-none-any.whl (10.3 kB view details)

Uploaded Python 3

File details

Details for the file numerical_derivative_checker-0.8.tar.gz.

File metadata

  • Download URL: numerical_derivative_checker-0.8.tar.gz
  • Upload date:
  • Size: 4.4 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for numerical_derivative_checker-0.8.tar.gz
Algorithm Hash digest
SHA256 904099158d459ce1e455170aef2d85a03647eff4ae0d08b0b9720ff97bc713b9
MD5 3eae6d602488ce6ae190e3dcf0f180e9
BLAKE2b-256 1a6b0a3dcc80c5f1284f694e25c2743a27751ee292e78c15d2066fea8808f443

See more details on using hashes here.

File details

Details for the file numerical_derivative_checker-0.8-py3-none-any.whl.

File metadata

  • Download URL: numerical_derivative_checker-0.8-py3-none-any.whl
  • Upload date:
  • Size: 10.3 kB
  • Tags: Python 3
  • Uploaded using 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

File hashes

Hashes for numerical_derivative_checker-0.8-py3-none-any.whl
Algorithm Hash digest
SHA256 9dabb7c5e8ea14eb4cdc925cbc83157268fb8120dabe597f13a9b37412daced7
MD5 348f618c252ea42d57383f0fbb47add9
BLAKE2b-256 7369960332b2f70faac2b235885c756144b8a8ed51bac85d3f963c006d918c24

See more details on using hashes here.

Supported by

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