This Python module approximates derivatives using finite difference methods.
This package is essential for obtaining derivatives of oofuns beyond the standard set without routines to yield them directly, which is required by FuncDesigner. Additionally, some OpenOpt solvers require DerApproximator when there are functions without user-supplied derivatives. The requirements for DerApproximator, as well as for OpenOpt and FuncDesigner are NumPy and python-setuptools.
DerApproximator currently provides only two functions: get_d1 and check_d1. Users need to provide two required arguments for these functions, which are the function involved and the point where the derivatives are to be obtained or checked. If the user provides a Python list as a starting point, it is automatically casted to a NumPy array.
The get_d1 function returns the first derivatives of a func f: R^n -> R^m. An example of how to use this function is provided in the documentation. Another function, check_d1, checks a user-provided routine for obtaining first derivatives of a function. Examples are also provided in the documentation.
The default diffInt value is 1.5e-8, which users can overwrite by using the "diffInt" argument for get_d1 and check_d1. Another argument, stencil, has a default value of 2 for DerApproximator, FuncDesigner, and OpenOpt NSP. This means that (f(x+diffInt)-f(x-diffInt)) / (2*diffInt) is used. For OpenOpt NLP, the default value is 1, which means (f(x+diffInt)-f(x)) / diffInt.
If it turns out that f(x+diffInt) is NaN (not a number) or f(x-diffInt) is NaN, then only one side will be involved in the calculations. This is a typical situation for many numerical optimization problems. Furthermore, functions like approx_fprime and check_grad from scipy.optimize are even more primitive since they have only one stencil and no handling of NaNs.
Version 0.15: N/A