desc.optimize.lsqtr
- class desc.optimize.lsqtr(fun, x0, jac, bounds=(-inf, inf), args=(), x_scale='jac', ftol=1e-06, xtol=1e-06, gtol=1e-06, verbose=1, maxiter=None, callback=None, options=None)Source
Solve a least squares problem using a (quasi)-Newton trust region method.
- Parameters:
fun (callable) – objective to be minimized. Should have a signature like fun(x,*args)-> 1d array
x0 (array-like) – initial guess
jac (callable:) – function to compute Jacobian matrix of fun
bounds (tuple of array-like) – Lower and upper bounds on independent variables. Defaults to no bounds. Each array must match the size of x0 or be a scalar, in the latter case a bound will be the same for all variables. Use np.inf with an appropriate sign to disable bounds on all or some variables.
args (tuple) – additional arguments passed to fun, grad, and jac
x_scale (array_like or
'jac'
, optional) – Characteristic scale of each variable. Settingx_scale
is equivalent to reformulating the problem in scaled variablesxs = x / x_scale
. An alternative view is that the size of a trust region along jth dimension is proportional tox_scale[j]
. Improved convergence may be achieved by settingx_scale
such that a step of a given size along any of the scaled variables has a similar effect on the cost function. If set to'jac'
, the scale is iteratively updated using the inverse norms of the columns of the Jacobian matrix.ftol (float or None, optional) – Tolerance for termination by the change of the cost function. The optimization process is stopped when
dF < ftol * F
, and there was an adequate agreement between a local quadratic model and the true model in the last step. If None, the termination by this condition is disabled.xtol (float or None, optional) – Tolerance for termination by the change of the independent variables. Optimization is stopped when
norm(dx) < xtol * (xtol + norm(x))
. If None, the termination by this condition is disabled.gtol (float or None, optional) – Absolute tolerance for termination by the norm of the gradient. Optimizer terminates when
max(abs(g)) < gtol
. If None, the termination by this condition is disabled.verbose ({0, 1, 2}, optional) –
0 : work silently.
1 (default) : display a termination report.
2 : display progress during iterations
maxiter (int, optional) – maximum number of iterations. Defaults to size(x)*100
callback (callable, optional) –
Called after each iteration. Should be a callable with the signature:
callback(xk, *args) -> bool
where
xk
is the current parameter vector, andargs
are the same arguments passed to fun and jac. If callback returns True the algorithm execution is terminated.options (dict, optional) –
dictionary of optional keyword arguments to override default solver settings.
"max_nfev"
: (int > 0) Maximum number of function evaluations (each iteration may take more than one function evaluation). Default is5*maxiter+1
"max_dx"
: (float > 0) Maximum allowed change in the norm of x from its starting point. Default np.inf."initial_trust_radius"
: ("scipy"
,"conngould"
,"mix"
or float > 0) Initial trust region radius."scipy"
uses the scaled norm of x0, which is the default behavior inscipy.optimize.least_squares
."conngould"
uses the norm of the Cauchy point, as recommended in ch17 of [1]."mix"
uses the geometric mean of the previous two options. A float can also be passed to specify the trust radius directly. Default is"scipy"
."initial_trust_ratio"
: (float > 0) A extra scaling factor that is applied after one of the previous heuristics to determine the initial trust radius. Default 1."max_trust_radius"
: (float > 0) Maximum allowable trust region radius. Defaultnp.inf
."min_trust_radius"
: (float >= 0) Minimum allowable trust region radius. Optimization is terminated if the trust region falls below this value. Defaultnp.finfo(x0.dtype).eps
."tr_increase_threshold"
: (0 < float < 1) Increase the trust region radius when the ratio of actual to predicted reduction exceeds this threshold. Default 0.75."tr_decrease_threshold"
: (0 < float < 1) Decrease the trust region radius when the ratio of actual to predicted reduction is less than this threshold. Default 0.25."tr_increase_ratio"
: (float > 1) Factor to increase the trust region radius by when the ratio of actual to predicted reduction exceeds threshold. Default 2."tr_decrease_ratio"
: (0 < float < 1) Factor to decrease the trust region radius by when the ratio of actual to predicted reduction falls below threshold. Default 0.25."tr_method"
:"svd"
,"cho"
) Method to use for solving the trust region subproblem."cho"
uses a sequence of cholesky factorizations (generally 2-3), while"svd"
uses one singular value decomposition."cho"
is generally faster for large systems, especially on GPU, but may be less accurate for badly scaled systems. Default"svd"
- Returns:
res (OptimizeResult) – The optimization result represented as a
OptimizeResult
object. Important attributes are:x
the solution array,success
a Boolean flag indicating if the optimizer exited successfully andmessage
which describes the cause of the termination. SeeOptimizeResult
for a description of other attributes.
References