nifty.re.optimize module#
- class OptimizeResults(x: Any, success: bool | Array, status: int | Array, fun: Any, jac: Any, hess: Array | None = None, hess_inv: Array | None = None, nfev: None | int | Array = None, njev: None | int | Array = None, nhev: None | int | Array = None, nit: None | int | Array = None, trust_radius: None | float | Array = None, jac_magnitude: None | float | Array = None, good_approximation: None | bool | Array = None)[source]#
Bases:
NamedTupleObject holding optimization results inspired by JAX and scipy.
- Variables:
x (ndarray) – The solution of the optimization.
success (bool) – Whether or not the optimizer exited successfully.
status (int) – Termination status of the optimizer. Its value depends on the underlying solver. NOTE, in contrast to scipy there is no message for details since strings are not statically memory bound.
hess (fun, jac,) – Values of objective function, its Jacobian and its Hessian (if available). The Hessians may be approximations, see the documentation of the function in question.
hess_inv (object) – Inverse of the objective function’s Hessian; may be an approximation. Not available for all solvers.
nhev (nfev, njev,) – Number of evaluations of the objective functions and of its Jacobian and Hessian.
nit (int) – Number of iterations performed by the optimizer.
- fun: Any#
Alias for field number 3
- good_approximation: None | bool | Array#
Alias for field number 13
- hess: Array | None#
Alias for field number 5
- hess_inv: Array | None#
Alias for field number 6
- jac: Any#
Alias for field number 4
- jac_magnitude: None | float | Array#
Alias for field number 12
- nfev: None | int | Array#
Alias for field number 7
- nhev: None | int | Array#
Alias for field number 9
- nit: None | int | Array#
Alias for field number 10
- njev: None | int | Array#
Alias for field number 8
- status: int | Array#
Alias for field number 2
- success: bool | Array#
Alias for field number 1
- trust_radius: None | float | Array#
Alias for field number 11
- x: Any#
Alias for field number 0
- minimize(fun: Callable[[...], float] | None, x0, args: Tuple = (), *, method: str, tol: float | None = None, options: Mapping[str, Any] | None = None) OptimizeResults[source]#
Minimize fun.
- newton_cg(fun=None, x0=None, *args, **kwargs)[source]#
Minimize a scalar-valued function using the Newton-CG algorithm.
- optax_wrapper(fun=None, x0=None, *, optimizer=None, maxiter=None, miniter=None, jac: Callable | None = None, fun_and_grad=None, hessp=None, name=None, xtol=1e-05)[source]#
Minimize an objective function using an Optax optimizer.
This function wraps an
optaxoptimizer to be used in anoptimize_kloptimization in NIFTy.- Parameters:
fun (Callable) – Objective function to minimize. Must accept parameters
xand return a scalar value.x0 (array-like or pytree) – Initial parameters. Must be a JAX-compatible pytree.
optimizer (optax optimizer) – Optax optimizer instance (e.g.
optax.sdg(...),optax.lbfgs(...)). Must provideinitandupdatemethods.maxiter (int, optional) – Maximum number of iterations. Defaults to 200.
miniter (int, optional) – Minimum number of iterations before convergence is checked. Defaults to 0.
jac (Callable, optional) – Function returning the gradient of
fun.fun_and_grad (Callable, optional) – Function returning both value and gradient.
hessp (Callable, optional) – Hessian-vector product function. Included for API compatibility, but not used.
name (str, optional) – Optional label used for formatted iteration logging.
xtol (float, optional) – Convergence tolerance on the gradient norm. Internally scaled by the size of
x0.
- Returns:
An optimization result object containing:
- Return type: