optimization_methods⚓︎
Optimizers: EnOpt, GenOpt, LineSearch, TrustRegion and SmcOpt, all built on OptimizerBase.
BoundTransformHandler
⚓︎
Transform states between the original parameter domain and the unit cube.
Notes
All bounds must be finite whenever bounds are supplied.
__init__(bounds=None, transform=False)
⚓︎
Initialize the BoundTransformHandler.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bounds
|
sequence of (lower, upper) pairs
|
Lower and upper bounds for each state variable. |
None
|
transform
|
bool
|
If True, transform the optimization problem to the unit cube [0, 1]^n. |
False
|
hess_from_unit_cube(hess)
⚓︎
Transform a Hessian from unit-cube coordinates.
hess_to_unit_cube(hess)
⚓︎
Transform a Hessian to unit-cube coordinates.
jac_from_unit_cube(jac)
⚓︎
Transform a gradient from unit-cube coordinates.
jac_to_unit_cube(jac)
⚓︎
Transform a gradient to unit-cube coordinates.
project_gradient(x, g, tol=1e-08)
⚓︎
Project a gradient to respect active bound constraints.
project_to_bounds(x)
⚓︎
Project a vector onto the feasible domain.
state_to_unit_cube(x)
⚓︎
Transform original coordinates to unit-cube coordinates.
unit_cube_to_state(u)
⚓︎
Transform unit-cube coordinates to original coordinates.
EnOpt
⚓︎
Bases: OptimizerBase
Ensemble-based optimization (EnOpt).
obj_func_values
⚓︎
Legacy alias for fk.
__init__(x0, fun, jac=None, hess=None, args=(), bounds=None, callback=None, **options)
⚓︎
Initialize an EnOpt optimizer instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x0
|
ndarray
|
Initial control/state vector. |
required |
fun
|
callable
|
Objective function. |
required |
jac
|
callable
|
Ensemble gradient function. |
None
|
hess
|
callable
|
Ensemble Hessian function. |
None
|
args
|
tuple
|
The first tuple element is interpreted as the initial covariance. |
()
|
bounds
|
sequence
|
Lower and upper bounds for each state variable. |
None
|
callback
|
callable
|
Callback invoked after successful updates. |
None
|
**options
|
EnOpt configuration, plus everything :class: |
{}
|
log_columns()
⚓︎
The row of the iteration log: iteration, backtracking attempts, objective, step size, first covariance entry.
update_step()
⚓︎
Perform one EnOpt step with backtracking and optional resampling.
GenOpt
⚓︎
Bases: OptimizerBase
Generalized ensemble optimization with an adapting mutation distribution.
EnOpt draws its ensemble from a Gaussian whose covariance is fixed apart from an
optional Hessian-driven update. GenOpt draws from the marginals of
:class:~popt.ensembles.ensemble_generalized.GeneralizedEnsemble -- Beta,
logistic, truncated Gaussian -- and moves the distribution itself along with the
controls: theta (the marginal's shape) follows its own gradient, and the
correlation matrix follows corr_adapt.
So each accepted step updates three things rather than one: the controls from
jac, theta from jac_mut, and corr from corr_adapt -- which is
either a :class:CMA instance, called with the ensemble the mutation gradient
was built from, or any callable returning a matrix to descend along.
Examples:
ensemble = GeneralizedEnsemble(options, simulator, objective)
cma = CMA(ne=ensemble.num_samples, dim=x0.size, corr_update=True)
result = GenOpt.minimize(
x0, ensemble.function,
jac=ensemble.gradient, jac_mut=ensemble.mutation_gradient,
args=(ensemble.get_theta(), ensemble.get_corr()),
corr_adapt=cma, bounds=bounds,
)
__init__(x0, fun, jac=None, jac_mut=None, corr_adapt=None, args=(), bounds=None, callback=None, **options)
⚓︎
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x0
|
ndarray
|
Initial control vector. |
required |
fun
|
callable
|
Objective function. |
required |
jac
|
callable
|
Ensemble gradient, called as |
None
|
jac_mut
|
callable
|
Mutation gradient, called as |
None
|
corr_adapt
|
CMA or callable
|
Correlation-matrix adaptation. A :class: |
None
|
args
|
tuple
|
|
()
|
bounds
|
sequence
|
(min, max) per control. |
None
|
callback
|
callable
|
Invoked after each accepted step. |
None
|
**options
|
GenOpt configuration, plus everything :class:
|
{}
|
log_columns()
⚓︎
Iteration, backtracking attempts, objective, step size, and the correlation's spread.
update_step()
⚓︎
One GenOpt step: controls by backtracking, then theta and the correlation.
LineSearch
⚓︎
Bases: OptimizerBase
Line-search optimizer compatible with OptimizerBase.
The class supports gradient descent, BFGS, and Newton-CG search directions, together with either Wolfe or backtracking line search. It can operate with bounds, optional state transformations, logging, result persistence, and restart checkpoints.
__init__(x0, fun, method='GD', jac=None, hess=None, args=(), bounds=None, callback=None, **options)
⚓︎
Initialize a line-search optimizer instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x0
|
ndarray
|
Initial parameter vector. |
required |
fun
|
callable
|
Objective function. |
required |
method
|
(GD, BFGS, Newton - CG)
|
Search-direction method. |
'GD'
|
jac
|
callable
|
Gradient function. |
None
|
hess
|
callable
|
Hessian function, required by |
None
|
args
|
tuple
|
Extra positional arguments passed to the wrapped callables. |
()
|
bounds
|
sequence
|
Lower and upper bounds for each state variable. |
None
|
callback
|
callable
|
Callback invoked after successful updates. |
None
|
**options
|
Line-search configuration, plus everything :class: |
{}
|
log_columns()
⚓︎
The row of the iteration log: iteration, objective, gradient infinity norm, step length taken.
update_step()
⚓︎
Perform one optimization step.
The method computes a search direction, performs a line search, and commits the new iterate on success. When enabled, it can recompute the gradient and retry if the line search fails.
OptimizerBase
⚓︎
Bases: OptimizerRestartMixin, ABC
The iteration every optimizer shares; a subclass supplies the step.
A subclass implements :meth:update_step, committing an improving point
with :meth:_commit_step and returning a :class:StepReport, and names
what its log row shows in :meth:log_columns. Everything else -- the
starting evaluation, the callback, recording and saving the result, the
log row, the function, state and projected-gradient convergence checks,
restart checkpoints and the EPF outer loop -- happens here.
NAME = 'Optimizer'
⚓︎
Shown in the start-of-run banner.
__init__(x0, fun, jac=None, hess=None, args=(), bounds=None, callback=None, **options)
⚓︎
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x0
|
ndarray
|
Initial parameter vector. |
required |
fun
|
callable
|
Objective function. |
required |
jac
|
callable
|
Gradient function. |
None
|
hess
|
callable
|
Hessian function. |
None
|
args
|
tuple
|
Extra positional arguments passed to callables: |
()
|
bounds
|
sequence
|
Lower and upper bounds for each state variable. |
None
|
callback
|
callable
|
Called with the optimizer after every accepted step. |
None
|
**options
|
Optimizer configuration such as tolerances, logging, restart, and
persistence options.
- maxiter: Maximum number of iterations (default: 100)
- ftol: Relative function tolerance for convergence (default: 1e-5)
- xtol: Relative change in state for convergence (default: 1e-8)
- gtol: Projected-gradient infinity-norm tolerance for convergence (default: 1e-5)
- fun0, jac0, hess0: Initial objective, gradient and Hessian values to reuse instead of evaluating them
- logit: Enable logging (default: True)
- logger_name: Log file name (default: 'OPTIM.log')
- restart: Enable restart from file (default: False)
- restartsave: Save restart file after each iteration (default: False)
- restart_file: Path for restart file (default: '{optimizer_name}_restart.pkl')
- epf: Dictionary of EPF options (default: None)
- r: Initial penalty factor
- r_factor: Penalty factor update multiplier (default: 2)
- tol_factor: Function tolerance update multiplier (default: 0.9)
- conv_crit: EPF convergence criterion, compared against the mean
penalty with the penalty factor divided out (default: 1e-5). The
objective must write |
{}
|
check_convergence()
⚓︎
Optimizer-specific criteria; by default the projected gradient against gtol.
Runs after the function and state checks. An optimizer with more
criteria extends this; one without a gradient gets False.
check_epf_convergence()
⚓︎
Evaluate convergence of the outer EPF iteration.
The loop stops once the constraints are satisfied, measured as the mean of
self.epf['penalty'] with the penalty factor r divided back out. The
objective is responsible for writing penalty into the epf dict it is
handed; without it there is nothing to converge on and this raises.
Returns:
| Type | Description |
|---|---|
bool
|
|
check_function_convergence()
⚓︎
Check convergence based on relative change in objective value.
check_state_convergence()
⚓︎
Check convergence based on the norm of the state update.
log_columns()
⚓︎
One row of the iteration log. Optimizers override to show their own quantities.
minimize(x0, fun, *args, **kwargs)
⚓︎
Construct the optimizer with these arguments, run it, and return its result.
The arguments are the constructor's, in the constructor's order; see the class for what each optimizer takes.
run_optimization()
⚓︎
Run this optimizer to completion.
Named for the job rather than the mechanism; the counterpart in pipt is
AssimilationScheme.run_assimilation.
The loop handles restart restoration, the starting evaluation, optional
EPF outer iterations, repeated calls to update_step(), and the
shared convergence checks. When enabled, restart files are updated
after successful iterations and after EPF penalty updates.
update_step()
⚓︎
Take one step from the current iterate.
Find a better point and make it current with :meth:_commit_step,
which also keeps the previous iterate for the convergence checks; then
return StepReport(True). The loop runs the callback, records and
saves the result, logs a row and checks convergence -- none of that
is the step's job. Return StepReport(False, why) when no
acceptable step exists: the run stops and why is its message.
OptimizerRestartMixin
⚓︎
Bases: RestartMixin
Checkpoint/restart behaviour for optimizers.
The implementation is shared with PIPT via
:class:ensemble.checkpoint.RestartMixin; this subclass exists so the
optimizer-facing name stays stable.
SmcOpt
⚓︎
Bases: OptimizerBase
Sequential Monte-Carlo optimizer with resampling and backtracking.
obj_func_values
⚓︎
Legacy alias for fk.
__init__(x0, fun, sens=None, args=(), bounds=None, callback=None, **options)
⚓︎
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x0
|
ndarray
|
Initial state |
required |
fun
|
callable
|
objective function |
required |
sens
|
callable
|
Ensemble sensitivity function |
None
|
args
|
tuple
|
Initial covariance tuple where |
()
|
bounds
|
list
|
(min, max) pairs for each element in x. None is used to specify no bound. |
None
|
callback
|
callable
|
Callback invoked after successful updates. |
None
|
options
|
dict
|
SmcOpt configuration, plus everything :class:
|
{}
|
log_columns()
⚓︎
The row of the iteration log: iteration, backtracking attempts, objective, best objective seen, step size.
update_step()
⚓︎
Perform one SMC update step with backtracking and optional resampling.
StepReport
⚓︎
What one call to :meth:OptimizerBase.update_step produced.
accepted says the optimizer committed a new iterate (through
:meth:OptimizerBase._commit_step); the loop then does the bookkeeping
every optimizer used to repeat. message is why it stopped when it did
not, and becomes the result's message.
TrustRegion
⚓︎
Bases: OptimizerBase
Trust-region Optimizer.
The class supports exact Hessian trust-region subproblems (iterative or
CG-Steihaug) and optional BFGS Hessian approximation via hess='BFGS'.
__init__(x0, fun, jac, hess, method='iterative', args=(), bounds=None, callback=None, **options)
⚓︎
Initialize a trust-region optimizer instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x0
|
ndarray
|
Initial parameter vector. |
required |
fun
|
callable
|
Objective function. |
required |
jac
|
callable
|
Gradient function. |
required |
hess
|
callable or {BFGS}
|
Hessian function, or |
required |
method
|
(iterative, CG - Steihaug)
|
Trust-region subproblem solver. |
'iterative'
|
args
|
tuple
|
Extra positional arguments passed to the wrapped callables. |
()
|
bounds
|
sequence
|
Lower and upper bounds for each state variable. |
None
|
callback
|
callable
|
Callback invoked after successful updates. |
None
|
**options
|
Trust-region configuration, plus everything :class: |
{}
|
check_convergence()
⚓︎
The projected gradient, the trust-region radius, and any custom criterion.
log_columns()
⚓︎
The row of the iteration log: iteration, objective, trust radius, reduction ratio, whether the step hit the boundary.
update_step()
⚓︎
Perform one trust-region step with optional radius reductions.