bundles / scipy 1.17.1 / scipy / optimize / _optimize / _prepare_scalar_function
function
scipy.optimize._optimize:_prepare_scalar_function
Signature
def _prepare_scalar_function ( fun , x0 , jac = None , args = () , bounds = None , epsilon = None , finite_diff_rel_step = None , hess = None , workers = None ) Summary
Creates a ScalarFunction object for use with scalar minimizers (BFGS/LBFGSB/SLSQP/TNC/CG/etc).
Parameters
fun: callableThe objective function to be minimized.
fun(x, *args) -> floatwhere
xis a 1-D array with shape (n,) andargsis a tuple of the fixed parameters needed to completely specify the function.x0: ndarray, shape (n,)Initial guess. Array of real elements of size (n,), where 'n' is the number of independent variables.
jac: {callable, '2-point', '3-point', 'cs', None}, optionalMethod for computing the gradient vector. If it is a callable, it should be a function that returns the gradient vector:
jac(x, *args) -> array_like, shape (n,)If one of
{'2-point', '3-point', 'cs'}is selected then the gradient is calculated with a relative step for finite differences. IfNone, then two-point finite differences with an absolute step is used.args: tuple, optionalExtra arguments passed to the objective function and its derivatives (
fun,jacfunctions).bounds: sequence, optionalBounds on variables. 'new-style' bounds are required.
eps: float or ndarrayIf
jac is Nonethe absolute step size used for numerical approximation of the jacobian via forward differences.finite_diff_rel_step: None or array_like, optionalIf
jac in ['2-point', '3-point', 'cs']the relative step size to use for numerical approximation of the jacobian. The absolute step size is computed ash = rel_step * sign(x0) * max(1, abs(x0)), possibly adjusted to fit into the bounds. Forjac='3-point'the sign ofhis ignored. If None (default) then step is selected automatically.hess: {callable, '2-point', '3-point', 'cs', None}Computes the Hessian matrix. If it is callable, it should return the Hessian matrix:
hess(x, *args) -> {LinearOperator, spmatrix, array}, (n, n)Alternatively, the keywords {'2-point', '3-point', 'cs'} select a finite difference scheme for numerical estimation. 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.
workers: int or 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.
Returns
sf: ScalarFunction
Aliases
-
scipy.optimize._cobyla_py._prepare_scalar_function