discretize.tests.check_derivative(fctn, x0, num=7, plotIt=True, dx=None, expectedOrder=2, tolerance=0.85, eps=1e-10, ax=None)[source]

Basic derivative check

Compares error decay of 0th and 1st order Taylor approximation at point x0 for a randomized search direction.

  • fctn (callable) – function handle

  • x0 (numpy.ndarray) – point at which to check derivative

  • num (int) – number of times to reduce step length, h

  • plotIt (bool) – if you would like to plot

  • dx (numpy.ndarray) – step direction

  • expectedOrder (int) – The order that you expect the derivative to yield.

  • tolerance (float) – The tolerance on the expected order.

  • eps (float) – What is zero?

Return type



did you pass the test?!

from discretize import tests, utils
import numpy as np

def simplePass(x):
    return np.sin(x), utils.sdiag(np.cos(x))
tests.checkDerivative(simplePass, np.random.randn(5))

(Source code, png, pdf)