ScipyMinimize
- class pmrf.optimize.ScipyMinimize(method: str | None = None, tol: float | None = None, options: dict = <factory>, show_progress: bool = True, use_grad: bool | None = None, nonfinite: Literal['backoff', 'raise']='backoff')
Bases:
AbstractBoundedMinimizerA wrapper around SciPy’s
scipy.optimize.minimize().Whether it honours bounds depends on method: L-BFGS-B, TNC, SLSQP, trust-constr, Powell, Nelder-Mead, COBYLA and COBYQA do, and search box space; any other method, such as BFGS or CG, moves through raw space. The default, None, is L-BFGS-B, which SciPy picks when it is given bounds. When bounds are supplied to trust-constr, SciPy searches fixed affine coordinates centered at the box start and receives feasible bounds; metrics.box_origin and metrics.box_scale map its coordinates back to box space.
A trial point whose loss, or any requested gradient entry, is nonfinite, such as a circuit that becomes singular at extreme parameter values, is handed to SciPy as
+inf(with a zero gradient), so its line search or simplex backs off from it. Not every method backtracks: L-BFGS-B stops at its last finite iterate instead. A fit that backed off and ended no better than its start raisesFloatingPointErrorrather than returning that start as a success, as does a nonfinite final value. L-BFGS-B also raises when it ends no better than its best loss before its last backed-off trial, since it never recovers from one. A nonfinite value at the start point, or a nonfinite attempted parameter vector, raises with the method and evaluation number. With nonfinite=’raise’, every nonfinite evaluation raises, which helps find where an objective breaks. Finite nonconvergence keeps SciPy’s usual result.- run(fn: Callable[[PyTree, Any], Any], y0: PyTree, args: Any = None, bounds: tuple[PyTree, PyTree] | None = None, max_iter: int = 1024, **kwargs) MinimizeResult
Execute the minimization algorithm.
- Parameters:
fn (callable) – The objective function to minimize.
y0 (PyTree) – The initial parameter guess.
args (Any) – Args to pass to fn.
bounds (tuple[PyTree, PyTree], optional) – The lower and upper edges of the box to search, shaped like y0, or None if the minimiser does not honour bounds. Edges may be infinite.
max_iter (int = 1024) – The maximum number of iterations to take.
**kwargs – Runtime arguments forward to the solver backend.
- Returns:
An instance of
pmrf.optimize.MinimizeResult.- Return type:
results
- property honours_bounds: bool
Whether method keeps its iterates inside bounds. None is L-BFGS-B.
- method: str | None = None
- nonfinite: Literal['backoff', 'raise'] = 'backoff'
'backoff'hands SciPy+infso it steps back, and'raise'raisesFloatingPointErroron that evaluation.- Type:
What a nonfinite loss or gradient after the start point does
- options: dict
- show_progress: bool = True
- tol: float | None = None
- use_grad: bool | None = None