DerApproximator
From OpenOpt
- DerApproximator is a small yet important package for getting/checking derivatives via finite-difference approximation, extracted from OpenOpt framework to be standalone Python module. It is required by FuncDesigner (for obtaining derivatives of oofuns beyond standard set without routines to yield them directly) and some OpenOpt solvers (when there are some functions without user-supplied derivatives).
- Requirements for the package (as well as for OpenOpt and FuncDesigner) are NumPy and python-setuptools; OS - any where Python and numpy work (Linux, Windows, Mac OS X etc).
- If user provides start point of type Python list, it is automatically casted to NumPy array.
- Functions:
- Default diffInt is 1.5e-8 for get_d1, check_d1 and 1.5e-4 for get_d2. You can overwrite it by "diffInt" argument. Another one argument is stencil, default value 3 for DerApproximator, FuncDesigner and OpenOpt NSP is 3, for OpenOpt NLP it's 1:
- stencil = 1: (f(x+diffInt) - f(x)) / diffInt
- stencil = 2: (f(x+diffInt) - f(x-diffInt)) / (2*diffInt)
- stencil = 3: (-f(x+2*diffInt) + 8*f(x+diffInt) - 8*f(x-diffInt) + f(x-2*diffInt)) / (12*diffInt)
- If it turns out that f(x+diffInt) is NaN (not a number) or f(x-diffInt) is NaN or +/- inf, e.g. log or sqrt in zero, for than only one side will be involved into calculations. since v 0.36: if stencil > 1, then result is obtained as (-3*f(x) + 4*f(x+diffInt) - f(x+2*diffInt))/diffInt - it yields more exact result. BTW this situation is quite typical for lots of numerical optimization problems, and currently functions approx_fprime and check_grad from scipy.optimize are even more primitive - they have only one stencil and no handling of NaNs.
Made by Dmitrey |
See also:
- DerApproximator documentation
- Download and installation instructions at our Install webpage
- DerApproximator linux.softpedia.com entry
- FuncDesigner - for most cases it can provide more exact derivatives via Automatic differentiation