{ } Raw JSON

bundles / scipy latest / scipy / optimize / _optimize / _prepare_scalar_function

function

scipy.optimize._optimize:_prepare_scalar_function

source: /scipy/optimize/_optimize.py :204

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 : callable

The objective function to be minimized.

fun(x, *args) -> float

where x is a 1-D array with shape (n,) and args is 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}, optional

Method 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. If None, then two-point finite differences with an absolute step is used.

args : tuple, optional

Extra arguments passed to the objective function and its derivatives (fun, jac functions).

bounds : sequence, optional

Bounds on variables. 'new-style' bounds are required.

eps : float or ndarray

If jac is None the absolute step size used for numerical approximation of the jacobian via forward differences.

finite_diff_rel_step : None or array_like, optional

If 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 as h = rel_step * sign(x0) * max(1, abs(x0)), possibly adjusted to fit into the bounds. For jac='3-point' the sign of h is 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, optional

A map-like callable, such as multiprocessing.Pool.map for evaluating any numerical differentiation in parallel. This evaluation is carried out as workers(fun, iterable), or workers(grad, iterable), depending on what is being numerically differentiated. Alternatively, if workers is an int the task is subdivided into workers sections and the function evaluated in parallel (uses multiprocessing.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