scijit.optimize.OptimizeResult

class scijit.optimize.OptimizeResult

Bases: _Mapping

The result minimize, root and the other solvers return.

Attributes:
xndarray

The solution.

funfloat or ndarray

The objective, or the residual vector, at x.

successbool

Whether the solver met its termination condition.

messagestr

What the solver reported.

Notes

The field set is the solver’s, not a fixed one. Each routine, and on minimize and root each method, returns the fields scipy’s own result carries for that call and no others. A field the solver did not compute is ABSENT: reading it raises AttributeError from Python and is a numba.TypingError when the call compiles, and hasattr is False.

keys lists what a given result holds. Attribute access, res['x'], res.get('nfev'), in, values and items all read the same object, from Python and from inside @njit.

The CONTAINER differs from scipy’s, which is a dict subclass: isinstance(res, scipy.optimize.OptimizeResult) is False, integer indexing reads a value here and raises KeyError there, and unpacking yields this result’s VALUES where scipy’s yields its field NAMES.

Examples

>>> import numpy as np
>>> from numba import njit
>>> from scijit.optimize import minimize
>>> @njit
... def rosen(x):
...     return 100.0 * (x[1] - x[0] ** 2) ** 2 + (1.0 - x[0]) ** 2
>>> res = minimize(rosen, np.array([0.5, 0.5]), method='Nelder-Mead')
>>> sorted(res.keys())
['final_simplex', 'fun', 'message', 'nfev', 'nit', 'status', 'success', 'x']
>>> hasattr(res, 'hess_inv')
False
__init__(*args, **kwargs)

Methods

__init__(*args, **kwargs)

get(key[, default])

items()

keys()

values()