Skip to main content

Module finite_differences

Module finite_differences 

Source
Expand description

Forward-difference gradients and gradient checking (SciPy’s optimize.approx_fprime and optimize.check_grad).

See the book entry Brute force, isotonic regression and gradient checks.

Functions§

approx_fprime
The forward-difference gradient (f(x + hεᵢ) − f(x))/h of f at x (SciPy’s approx_fprime), with step epsilon (SciPy’s default is √ε ≈ 1.49·10⁻⁸); the step actually used is the representable (xᵢ + h) − xᵢ. Its error is about h|f''|/2 + 2ε|f|/h, smallest near the default.
check_grad
The Euclidean norm of the difference between an analytic gradient grad(x) and the forward-difference gradient of f (SciPy’s check_grad): about √ε times the size of the second derivatives when grad is right, of the order of the gradient itself when it is wrong.