approx_fprime(xk, f, epsilon=1.4901161193847656e-08, *args)
The function gradient is determined by the forward finite difference formula:
f(xk[i] + epsilon[i]) - f(xk[i]) f'[i] = --------------------------------- epsilon[i]
The main use of approx_fprime
is in scalar function optimizers like fmin_bfgs
, to determine numerically the Jacobian of a function.
The coordinate vector at which to determine the gradient of f
.
The function of which to determine the gradient (partial derivatives). Should take :None:None:`xk`
as first argument, other arguments to f
can be supplied in *args
. Should return a scalar, the value of the function at :None:None:`xk`
.
Increment to :None:None:`xk`
to use for determining the function gradient. If a scalar, uses the same finite difference delta for all partial derivatives. If an array, should contain one value per element of :None:None:`xk`
. Defaults to sqrt(np.finfo(float).eps)
, which is approximately 1.49e-08.
Any other arguments that are to be passed to f
.
Finite-difference approximation of the gradient of a scalar function.
check_grad
Check correctness of gradient function against approx_fprime.
>>> from scipy import optimize
... def func(x, c0, c1):
... "Coordinate vector `x` should be an array of size two."
... return c0 * x[0]**2 + c1*x[1]**2
>>> x = np.ones(2)See :
... c0, c1 = (1, 200)
... eps = np.sqrt(np.finfo(float).eps)
... optimize.approx_fprime(x, func, [eps, np.sqrt(200) * eps], c0, c1) array([ 2. , 400.00004198])
The following pages refer to to this document either explicitly or contain code examples using this.
scipy.optimize._optimize.check_grad
scipy.optimize._optimize.approx_fprime
Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.
Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)
SVG is more flexible but power hungry; and does not scale well to 50 + nodes.
All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them