Skip to main content

Solves automatic numerical differentiation problems in one or more variables.

Project description

Suite of tools to solve automatic numerical differentiation problems in one or more variables. All of these methods also produce error estimates on the result. A pdf file is also provided to explain the theory behind these tools.

To test if the toolbox is working paste the following in an interactive python session:

import numdifftools as nd
nd.test(coverage=True)

Derivative:

A flexible tool for the computation of derivatives of order 1 through 4 on any scalar function. Finite differences are used in an adaptive manner, coupled with a Romberg extrapolation methodology to provide a maximally accurate result. The user can configure many of the options, changing the order of the method or the extrapolation, even allowing the user to specify whether central, forward or backward differences are used.

Gradient

Computes the gradient vector of a scalar function of one or more variables at any location.

Jacobian

Computes the Jacobian matrix of a vector (or array) valued function of one or more variables.

Hessian

Computes the Hessian matrix of all 2nd partial derivatives of a scalar function of one or more variables.

Hessdiag

The diagonal elements of the Hessian matrix are the pure second order partial derivatives.

Examples

Compute 1’st and 2’nd derivative of exp(x), at x == 1:

>>> import numpy as np
>>> import numdifftools as nd
>>> fd = nd.Derivative(np.exp)              # 1'st derivative
>>> fdd = nd.Derivative(np.exp,derOrder=2)  # 2'nd derivative
>>> fd(1)
array([ 2.71828183])

Nonlinear least squares:

>>> xdata = np.reshape(np.arange(0,1,0.1),(-1,1))
>>> ydata = 1+2*np.exp(0.75*xdata)
>>> fun = lambda c: (c[0]+c[1]*np.exp(c[2]*xdata) - ydata)**2
>>> Jfun = Jacobian(fun)
>>> Jfun([1,2,0.75]) # should be numerically zero
array([[  0.00000000e+00,   0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00,  -1.30229526e-17],
       [  0.00000000e+00,  -2.12916532e-17,   6.35877095e-17],
       [  0.00000000e+00,   0.00000000e+00,   6.95367972e-19],
       [  0.00000000e+00,   0.00000000e+00,  -2.13524915e-17],
       [  0.00000000e+00,  -3.08563327e-16,   7.43577440e-16],
       [  0.00000000e+00,   1.16128292e-15,   1.71041646e-15],
       [  0.00000000e+00,   0.00000000e+00,  -5.51592310e-16],
       [  0.00000000e+00,  -4.51138245e-19,   1.90866225e-15],
       [ -2.40861944e-19,  -1.82530534e-15,  -4.02819694e-15]])

Compute gradient of sum(x**2):

>>> fun = lambda x: np.sum(x**2)
>>> dfun = Gradient(fun)
>>> dfun([1,2,3])
array([ 2.,  4.,  6.])

See also

scipy.misc.derivative

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

Numdifftools-0.3.5.zip (270.8 kB view details)

Uploaded Source

Built Distribution

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

Numdifftools-0.3.5.win32.exe (232.1 kB view details)

Uploaded Source

File details

Details for the file Numdifftools-0.3.5.zip.

File metadata

  • Download URL: Numdifftools-0.3.5.zip
  • Upload date:
  • Size: 270.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for Numdifftools-0.3.5.zip
Algorithm Hash digest
SHA256 d6939912dedf7255c4bf4e0e771ee6472db4c31423524062104a35e884512335
MD5 0a6ebc1332ecb6b0ef67b3db001ba9bd
BLAKE2b-256 25879dcf4e7904df09e66e0c4d748d8a1fea758f4b05b219404eff48a4eb9056

See more details on using hashes here.

File details

Details for the file Numdifftools-0.3.5.win32.exe.

File metadata

File hashes

Hashes for Numdifftools-0.3.5.win32.exe
Algorithm Hash digest
SHA256 6a426fbe9a5dee1a7c5d006db75d8efc33d5286fbb9aaa73c671b7413efc618f
MD5 0c5caeb704a69408a35b818bcd86e754
BLAKE2b-256 1574a362a5adb975f62dd7e7728a18ef4c418b29b168257908e7d338b743d222

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