Optimize¶
Multistart optimization with support for various optimizers.
-
class
pypesto.optimize.
DlibOptimizer
(method: str, options: Dict = None)¶ Bases:
pypesto.optimize.optimizer.Optimizer
Use the Dlib toolbox for optimization.
-
__init__
(method: str, options: Dict = None)¶ Default constructor.
-
get_default_options
()¶ Create default options specific for the optimizer.
-
is_least_squares
()¶
-
minimize
(problem, x0, id, allow_failed_starts, history_options=None)¶
-
-
class
pypesto.optimize.
IpoptOptimizer
(options: Dict = None)¶ Bases:
pypesto.optimize.optimizer.Optimizer
Use IpOpt (https://pypi.org/project/ipopt/) for optimization.
-
__init__
(options: Dict = None)¶ - Parameters
options – Options are directly passed on to ipopt.minimize_ipopt.
-
is_least_squares
()¶
-
minimize
(problem, x0, id, allow_failed_starts, history_options=None)¶
-
-
class
pypesto.optimize.
OptimizeOptions
(startpoint_resample: bool = False, allow_failed_starts: bool = True)¶ Bases:
dict
Options for the multistart optimization.
- Parameters
startpoint_resample – Flag indicating whether initial points are supposed to be resampled if function evaluation fails at the initial point
allow_failed_starts (bool, optional) – Flag indicating whether we tolerate that exceptions are thrown during the minimization process.
-
__init__
(startpoint_resample: bool = False, allow_failed_starts: bool = True)¶ Initialize self. See help(type(self)) for accurate signature.
-
static
assert_instance
(maybe_options: Union[OptimizeOptions, Dict]) → pypesto.optimize.options.OptimizeOptions¶ Returns a valid options object.
- Parameters
maybe_options (OptimizeOptions or dict) –
-
class
pypesto.optimize.
Optimizer
¶ Bases:
abc.ABC
This is the optimizer base class, not functional on its own.
An optimizer takes a problem, and possibly a start point, and then performs an optimization. It returns an OptimizerResult.
-
__init__
()¶ Default constructor.
-
get_default_options
()¶ Create default options specific for the optimizer.
-
abstract
is_least_squares
()¶
-
abstract
minimize
(problem, x0, id, allow_failed_starts, history_options=None)¶
-
-
class
pypesto.optimize.
OptimizerResult
(id: str = None, x: numpy.ndarray = None, fval: float = None, grad: numpy.ndarray = None, hess: numpy.ndarray = None, res: numpy.ndarray = None, sres: numpy.ndarray = None, n_fval: int = None, n_grad: int = None, n_hess: int = None, n_res: int = None, n_sres: int = None, x0: numpy.ndarray = None, fval0: float = None, history: pypesto.objective.history.History = None, exitflag: int = None, time: float = None, message: str = None)¶ Bases:
dict
The result of an optimizer run. Used as a standardized return value to map from the individual result objects returned by the employed optimizers to the format understood by pypesto.
Can be used like a dict.
-
id
¶ Id of the optimizer run. Usually the start index.
-
x
¶ The best found parameters.
-
fval
¶ The best found function value, fun(x).
-
grad
¶ The gradient at x.
-
hess
¶ The Hessian at x.
-
res
¶ The residuals at x.
-
sres
¶ The residual sensitivities at x.
-
n_fval
¶ Number of function evaluations.
-
n_grad
¶ Number of gradient evaluations.
-
n_hess
¶ Number of Hessian evaluations.
-
n_res
¶ Number of residuals evaluations.
-
n_sres
¶ Number of residual sensitivity evaluations.
-
x0
¶ The starting parameters.
-
fval0
¶ The starting function value, fun(x0).
-
history
¶ Objective history.
-
exitflag
¶ The exitflag of the optimizer.
-
time
¶ Execution time.
-
message
¶ Textual comment on the optimization result.
- Type
str
Notes
Any field not supported by the optimizer is filled with None.
-
__init__
(id: str = None, x: numpy.ndarray = None, fval: float = None, grad: numpy.ndarray = None, hess: numpy.ndarray = None, res: numpy.ndarray = None, sres: numpy.ndarray = None, n_fval: int = None, n_grad: int = None, n_hess: int = None, n_res: int = None, n_sres: int = None, x0: numpy.ndarray = None, fval0: float = None, history: pypesto.objective.history.History = None, exitflag: int = None, time: float = None, message: str = None)¶ Initialize self. See help(type(self)) for accurate signature.
-
update_to_full
(problem: pypesto.problem.Problem) → None¶ Updates values to full vectors/matrices
- Parameters
problem – problem which contains info about how to convert to full vectors or matrices
-
-
class
pypesto.optimize.
PyswarmOptimizer
(options: Dict = None)¶ Bases:
pypesto.optimize.optimizer.Optimizer
Global optimization using pyswarm.
-
__init__
(options: Dict = None)¶ Default constructor.
-
is_least_squares
()¶
-
minimize
(problem, x0, id, allow_failed_starts, history_options=None)¶
-
-
class
pypesto.optimize.
ScipyOptimizer
(method: str = 'L-BFGS-B', tol: float = 1e-09, options: Dict = None)¶ Bases:
pypesto.optimize.optimizer.Optimizer
Use the SciPy optimizers.
-
__init__
(method: str = 'L-BFGS-B', tol: float = 1e-09, options: Dict = None)¶ Default constructor.
-
get_default_options
()¶ Create default options specific for the optimizer.
-
is_least_squares
()¶
-
minimize
(problem, x0, id, allow_failed_starts, history_options=None)¶
-
-
pypesto.optimize.
minimize
(problem: pypesto.problem.Problem, optimizer: pypesto.optimize.optimizer.Optimizer = None, n_starts: int = 100, ids: Iterable[str] = None, startpoint_method: Union[Callable, bool] = None, result: pypesto.result.Result = None, engine: pypesto.engine.base.Engine = None, options: pypesto.optimize.options.OptimizeOptions = None, history_options: pypesto.objective.history.HistoryOptions = None) → pypesto.result.Result¶ This is the main function to call to do multistart optimization.
- Parameters
problem – The problem to be solved.
optimizer – The optimizer to be used n_starts times.
n_starts – Number of starts of the optimizer.
ids – Ids assigned to the startpoints.
startpoint_method – Method for how to choose start points. False means the optimizer does not require start points, e.g. ‘pso’ method in ‘GlobalOptimizer’
result – A result object to append the optimization results to. For example, one might append more runs to a previous optimization. If None, a new object is created.
engine – Parallelization engine. Defaults to sequential execution on a SingleCoreEngine.
options – Various options applied to the multistart optimization.
history_options – Optimizer history options.
- Returns
Result object containing the results of all multistarts in result.optimize_result.
- Return type
result