bundles / scipy latest / scipy / optimize / _chandrupatla / _chandrupatla_minimize
function
scipy.optimize._chandrupatla:_chandrupatla_minimize
source: build-install/usr/lib/python3.14/site-packages/scipy/optimize/_chandrupatla.py:287
Signature
def _chandrupatla_minimize(func, x1, x2, x3, *, args = (), kwargs = None, xatol = None, xrtol = None, fatol = None, frtol = None, maxiter = 100, callback = None, preserve_shape = False)Summary
Find the minimizer of an elementwise function.
Extended Summary
For each element of the output of func, _chandrupatla_minimize seeks the scalar minimizer that minimizes the element. This function allows for x1, x2, x3, and the elements of args to be arrays of any broadcastable shapes.
Parameters
func: callableThe function whose minimizer is desired. The signature must be
func(x: ndarray, *args) -> ndarray where each element of ``x`` is a finite real and ``args`` is a tuple, which may contain an arbitrary number of arrays that are broadcastable with `x`. ``func`` must be an elementwise function: each element ``func(x)[i]`` must equal ``func(x[i])`` for all indices ``i``. `_chandrupatla` seeks an array ``x`` such that ``func(x)`` is an array of minima.
x1, x2, x3: array_likeThe abscissae of a standard scalar minimization bracket. A bracket is valid if
x1 < x2 < x3andfunc(x1) > func(x2) <= func(x3). Must be broadcastable with one another andargs.args: tuple, optionalAdditional positional arguments to be passed to
func. Must be arrays broadcastable withx1,x2, andx3. If the callable to be differentiated requires arguments that are not broadcastable withx, wrap that callable withfuncsuch thatfuncaccepts onlyxand broadcastable arrays.kwargs: dict of str:array_like, optionalAdditional keyword arguments to be passed to
f. Seeargs.xatol, xrtol, fatol, frtol: float, optionalAbsolute and relative tolerances on the minimizer and function value. See Notes for details.
maxiter: int, optionalThe maximum number of iterations of the algorithm to perform.
callback: callable, optionalAn optional user-supplied function to be called before the first iteration and after each iteration. Called as
callback(res), whereresis a_RichResultsimilar to that returned by _chandrupatla_minimize (but containing the current iterate's values of all variables). Ifcallbackraises aStopIteration, the algorithm will terminate immediately and _chandrupatla_minimize will return a result.preserve_shape: bool, default: FalseWhether calls to
funcmust preserve the broadcasted shape of the arguments to _chandrupatla_minimize. See find_minimum documentation.
Returns
res: _RichResultAn instance of scipy._lib._util._RichResult with the following attributes. (The descriptions are written as though the values will be scalars; however, if
funcreturns an array, the outputs will be arrays of the same shape.)success
Truewhen the algorithm terminated successfully (status0).status
An integer representing the exit status of the algorithm.
0: The algorithm converged to the specified tolerances.-1: The algorithm encountered an invalid bracket.-2: The maximum number of iterations was reached.-3: A non-finite value was encountered.-4: Iteration was terminated bycallback.1: The algorithm is proceeding normally (incallbackonly).x
The minimizer of the function, if the algorithm terminated successfully.
fun
The value of
funcevaluated atx.nfev
The number of points at which
funcwas evaluated.nit
The number of iterations of the algorithm that were performed.
xl,xm,xr
The final three-point bracket.
fl,fm,fr
The function value at the bracket points.
Notes
Implemented based on Chandrupatla's original paper [1].
If x1 < x2 < x3 are the points of the bracket and f1 > f2 <= f3 are the values of func at those points, then the algorithm is considered to have converged when x3 - x1 <= abs(x2)*xrtol + xatol or (f1 - 2*f2 + f3)/2 <= abs(f2)*frtol + fatol. Note that first of these differs from the termination conditions described in [1]. The default values of xrtol is the square root of the precision of the appropriate dtype, and xatol = fatol = frtol is the smallest normal number of the appropriate dtype.
Examples
from scipy.optimize._chandrupatla import _chandrupatla_minimize def f(x, args=1): return (x - args)**2 res = _chandrupatla_minimize(f, -5, 0, 5)✓
res.x
✗np.float64(1.0)
c = [1, 1.5, 2] res = _chandrupatla_minimize(f, -5, 0, 5, args=(c,)) res.x✓
array([1. , 1.5, 2. ])
See also
Aliases
scipy.optimize._chandrupatla._chandrupatla_minimize