bundles / scipy latest / scipy / optimize / _differentiable_functions / ScalarFunction
class
scipy.optimize._differentiable_functions:ScalarFunction
Signature
class ScalarFunction ( fun , x0 , args , grad , hess , finite_diff_rel_step = None , finite_diff_bounds = (-inf, inf) , epsilon = None , workers = None ) Members
Summary
Scalar function and its derivatives.
Extended Summary
This class defines a scalar function F: R^n->R and methods for computing or approximating its first and second derivatives.
Parameters
fun: callableevaluates the scalar function. Must be of the form
fun(x, *args), wherexis the argument in the form of a 1-D array andargsis a tuple of any additional fixed parameters needed to completely specify the function. Should return a scalar.x0: array-likeProvides an initial set of variables for evaluating fun. Array of real elements of size (n,), where 'n' is the number of independent variables.
args: tuple, optionalAny additional fixed parameters needed to completely specify the scalar function.
grad: {callable, '2-point', '3-point', 'cs'}Method for computing the gradient vector. If it is a callable, it should be a function that returns the gradient vector:
grad(x, *args) -> array_like, shape (n,)where
xis an array with shape (n,) andargsis a tuple with the fixed parameters. Alternatively, the keywords {'2-point', '3-point', 'cs'} can be used to select a finite difference scheme for numerical estimation of the gradient with a relative step size. These finite difference schemes obey any specifiedbounds.hess: {callable, '2-point', '3-point', 'cs', HessianUpdateStrategy}Method for computing the Hessian matrix. If it is callable, it should return the Hessian matrix:
hess(x, *args) -> {LinearOperator, spmatrix, array}, (n, n)where x is a (n,) ndarray and
argsis a tuple with the fixed parameters. Alternatively, the keywords {'2-point', '3-point', 'cs'} select a finite difference scheme for numerical estimation. Or, objects implementing HessianUpdateStrategy interface can be used to approximate the Hessian. Whenever the gradient is estimated via finite-differences, the Hessian cannot be estimated with options {'2-point', '3-point', 'cs'} and needs to be estimated using one of the quasi-Newton strategies.finite_diff_rel_step: None or array_likeRelative step size to use. The absolute step size is computed as
h = finite_diff_rel_step * sign(x0) * max(1, abs(x0)), possibly adjusted to fit into the bounds. Formethod='3-point'the sign ofhis ignored. If None then finite_diff_rel_step is selected automatically,finite_diff_bounds: tuple of array_likeLower and upper bounds on independent variables. Defaults to no bounds, (-np.inf, np.inf). Each bound must match the size of
x0or be a scalar, in the latter case the bound will be the same for all variables. Use it to limit the range of function evaluation.epsilon: None or array_like, optionalAbsolute step size to use, possibly adjusted to fit into the bounds. For
method='3-point'the sign ofepsilonis ignored. By default relative steps are used, only ifepsilon is not Noneare absolute steps used.workers: map-like callable, optionalA map-like callable, such as
multiprocessing.Pool.mapfor evaluating any numerical differentiation in parallel. This evaluation is carried out asworkers(fun, iterable), orworkers(grad, iterable), depending on what is being numerically differentiated. Alternatively, ifworkersis an int the task is subdivided intoworkerssections and the function evaluated in parallel (usesmultiprocessing.Pool <multiprocessing>). Supply -1 to use all available CPU cores. It is recommended that a map-like be used instead of int, as repeated calls to approx_derivative will incur large overhead from setting up new processes.
Notes
This class implements a memoization logic. There are methods fun, grad, hess` and corresponding attributes f, g and H. The following things should be considered:
Use only public methods
fun,gradandhess.After one of the methods is called, the corresponding attribute will be set. However, a subsequent call with a different argument of any of the methods may overwrite the attribute.
Aliases
-
scipy.optimize._differentiable_functions.ScalarFunction