desc.optimize.Optimizer.optimize
- Optimizer.optimize(things, objective, constraints=(), ftol=None, xtol=None, gtol=None, ctol=None, x_scale='auto', verbose=1, maxiter=None, options=None, copy=False)Source
Optimize an objective function.
- Parameters:
things (Optimizable or tuple/list of Optimizable) – Things to optimize, eg Equilibrium.
objective (ObjectiveFunction) – Objective function to optimize.
constraints (tuple of Objective, optional) – List of objectives to be used as constraints during optimization.
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, defaults to 1e-2 (or 1e-6 for stochastic).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, defaults to 1e-6.gtol (float or None, optional) – Absolute tolerance for termination by the norm of the gradient. Optimizer terminates when
norm(g) < gtol, where If None, defaults to 1e-8.ctol (float or None, optional) – Stopping tolerance on infinity norm of the constraint violation. Optimization will stop when ctol and one of the other tolerances are satisfied. If None, defaults to 1e-4.
x_scale (array, list[dict |
'ess'],'ess'or'auto', optional) – Characteristic scale of each variable. Settingx_scaleis 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_scalesuch that a step of a given size along any of the scaled variables has a similar effect on the cost function. Default is'auto', which iteratively updates the scale using the inverse norms of the columns of the Jacobian or Hessian matrix. If set to'ess', the scale is set using Exponential Spectral Scaling, this scaling is set with two parameters,ess_alphaandess_orderwhich are passed throughoptions.ess_alphais the decay rate of the scaling, andess_orderis the norm order for multi-index modes, which can be1,2, ornp.inf. If not provided inoptions, the defaults are:ess_alpha=1.2,ess_order=np.inf'andess_min_value=1e-7(minimum allowed scale value). If an array, should be the same size as sum(thing.dim_x for thing in things). If a list, the list should have 1 element for each thing, and each element should either be'ess'to use exponential spectral scaling for that thing, or a dict with the same keys and dimensions as thing.params_dict to specify scales manually.verbose (integer, optional) –
0 : work silently.
1 : display a termination report.
2 : display progress during iterations
maxiter (int, optional) – Maximum number of iterations. Defaults to 100.
options (dict, optional) –
Dictionary of optional keyword arguments to override default solver settings. Options that are universal to all optimizers are:
"linear_constraint_options": Dictionary of keyword arguments to pass toLinearConstraintProjection."perturb_options": Dictionary of keyword arguments to pass toProximalProjectionas itsperturb_options."solve_options": Dictionary of keyword arguments to pass toProximalProjectionas itssolve_options."ess_alpha": float, optional Decay rate of the scaling. Default is 1.2."ess_order": int, optional Order of norm to use for multi-index mode numbers, which can be1,2, ornp.inf. Default isnp.inf."ess_min_value": float, optional Minimum allowed scale value. Default is 1e-7.
See the documentation page [Optimizers Supported](https://desc-docs.readthedocs.io/en/stable/optimizers.html) for more details on the options available to each specific optimizer.
copy (bool) – Whether to return the current things or a copy (leaving the original unchanged).
- Returns:
things (list,) – list of optimized things
res (OptimizeResult) – The optimization result represented as a
OptimizeResultobject. Important attributes are:xthe solution array,successa Boolean flag indicating if the optimizer exited successfully andmessagewhich describes the cause of the termination. See OptimizeResult for a description of other attributes. Additionally, stores the before and after values of the objectives and constraints in theObjective valueskey.