+
    /iPj                         R t ^ RIHt ^RIHt ^ RIt. ROt ! R R]4      t	R t
RR ltRR lt]tRR	 ltRR
 ltR tR tR tRR ltRR ltRR ltRR ltRR ltR# )z
Functions
---------
.. autosummary::
   :toctree: generated/

    line_search_armijo
    line_search_wolfe1
    line_search_wolfe2
    scalar_search_wolfe1
    scalar_search_wolfe2

)warn)DCSRCHNLineSearchWarningc                       ] tR t^tRtR# )r    N)__name__
__module____qualname____firstlineno____static_attributes__r       X/var/www/html/photoedit/myenv/lib/python3.14/site-packages/scipy/optimize/_linesearch.pyr   r      s    r   c                 N    ^ T u;8  d   Tu;8  d   ^8  g   M \        R4      hR# )    z.'c1' and 'c2' do not satisfy'0 < c1 < c2 < 1'.N)
ValueError)c1c2s   &&r   _check_c1_c2r      s(    ORO!O . / 	/ r   c                   a aaaaaaa Vf   S! S.SO5!  pV.o^ .o^ .oVV VVV3R lpVVVVVV3R lp\         P                  ! VS4      p\        WWVVWWVR7
      w  pppVS^ ,          S^ ,          VVS^ ,          3# )a  
As `scalar_search_wolfe1` but do a line search to direction `pk`

Parameters
----------
f : callable
    Function `f(x)`
fprime : callable
    Gradient of `f`
xk : array_like
    Current point
pk : array_like
    Search direction
gfk : array_like, optional
    Gradient of `f` at point `xk`
old_fval : float, optional
    Value of `f` at point `xk`
old_old_fval : float, optional
    Value of `f` at point preceding `xk`

The rest of the parameters are the same as for `scalar_search_wolfe1`.

Returns
-------
stp, f_count, g_count, fval, old_fval
    As in `line_search_wolfe1`
gval : array
    Gradient of `f` at the final point

Notes
-----
Parameters `c1` and `c2` must satisfy ``0 < c1 < c2 < 1``.

c                 ^   < S^ ;;,          ^,          uu&   S! SV S,          ,           .SO5!  # r   r   )sargsffcpkxks   &r   philine_search_wolfe1.<locals>.phiR   s(    
1
ad"T""r   c                    < S! SV S,          ,           .SO5!  S^ &   S^ ;;,          ^,          uu&   \         P                  ! S^ ,          S4      # r   npdot)r   r   fprimegcgvalr   r   s   &r   derphi"line_search_wolfe1.<locals>.derphiV   s@    ad*T*Q
1
vvd1gr""r   )r   r   amaxaminxtol)r!   r"   scalar_search_wolfe1)r   r#   r   r   gfkold_fvalold_old_fvalr   r   r   r(   r)   r*   r   r&   derphi0stpfvalr   r$   r%   s   ffff&&&f&&&&&     @@@r   line_search_wolfe1r2   %   s    L {R$5D
B
B# ## #
 ffS"oG.tT;Cx 1r!udHd1g55r   c
           	         \        WV4       Vf	   V ! R4      pVf	   V! R4      pVe2   V^ 8w  d+   \        RRW#,
          ,          V,          4      p
V
^ 8  d   Rp
MRp
^dp\        WWVWV4      pV! WWKR7      w  rr/WV3# )a  
Scalar function search for alpha that satisfies strong Wolfe conditions

alpha > 0 is assumed to be a descent direction.

Parameters
----------
phi : callable phi(alpha)
    Function at point `alpha`
derphi : callable phi'(alpha)
    Objective function derivative. Returns a scalar.
phi0 : float, optional
    Value of phi at 0
old_phi0 : float, optional
    Value of phi at previous point
derphi0 : float, optional
    Value derphi at 0
c1 : float, optional
    Parameter for Armijo condition rule.
c2 : float, optional
    Parameter for curvature condition rule.
amax, amin : float, optional
    Maximum and minimum step size
xtol : float, optional
    Relative tolerance for an acceptable step.

Returns
-------
alpha : float
    Step size, or None if no suitable step was found
phi : float
    Value of `phi` at the new point `alpha`
phi0 : float
    Value of `phi` at `alpha=0`

Notes
-----
Uses routine DCSRCH from MINPACK.

Parameters `c1` and `c2` must satisfy ``0 < c1 < c2 < 1`` as described in [1]_.

References
----------

.. [1] Nocedal, J., & Wright, S. J. (2006). Numerical optimization.
   In Springer Series in Operations Research and Financial Engineering.
   (Springer Series in Operations Research and Financial Engineering).
   Springer Nature.

              ?)phi0r/   maxiter)\( @)r   minr   )r   r&   r6   old_phi0r/   r   r   r(   r)   r*   alpha1r7   dcsrchr0   phi1tasks   &&&&&&&&&&      r   r+   r+   d   s    j |2w*1S&$/27:;A:FGCT:F"7Ct d?r   c                f  a aaaaaaaaaa ^ .o^ .oR.oR.oVV VVV3R lpVoVVVVVVV3R loVf   S! S.SO5!  p\         P                  ! VS4      pSe   VVVVVV3R lpMRp\        VSWVWWWR7
      w  ppppVf   \        R\        ^R7       M	S^ ,          pVS^ ,          S^ ,          VVV3# )a  Find alpha that satisfies strong Wolfe conditions.

Parameters
----------
f : callable f(x,*args)
    Objective function.
myfprime : callable f'(x,*args)
    Objective function gradient.
xk : ndarray
    Starting point.
pk : ndarray
    Search direction. The search direction must be a descent direction
    for the algorithm to converge.
gfk : ndarray, optional
    Gradient value for x=xk (xk being the current parameter
    estimate). Will be recomputed if omitted.
old_fval : float, optional
    Function value for x=xk. Will be recomputed if omitted.
old_old_fval : float, optional
    Function value for the point preceding x=xk.
args : tuple, optional
    Additional arguments passed to objective function.
c1 : float, optional
    Parameter for Armijo condition rule.
c2 : float, optional
    Parameter for curvature condition rule.
amax : float, optional
    Maximum step size
extra_condition : callable, optional
    A callable of the form ``extra_condition(alpha, x, f, g)``
    returning a boolean. Arguments are the proposed step ``alpha``
    and the corresponding ``x``, ``f`` and ``g`` values. The line search
    accepts the value of ``alpha`` only if this
    callable returns ``True``. If the callable returns ``False``
    for the step length, the algorithm will continue with
    new iterates. The callable is only called for iterates
    satisfying the strong Wolfe conditions.
maxiter : int, optional
    Maximum number of iterations to perform.

Returns
-------
alpha : float or None
    Alpha for which ``x_new = x0 + alpha * pk``,
    or None if the line search algorithm did not converge.
fc : int
    Number of function evaluations made.
gc : int
    Number of gradient evaluations made.
new_fval : float or None
    New function value ``f(x_new)=f(x0+alpha*pk)``,
    or None if the line search algorithm did not converge.
old_fval : float
    Old function value ``f(x0)``.
new_slope : float or None
    The local slope along the search direction at the
    new value ``<myfprime(x_new), pk>``,
    or None if the line search algorithm did not converge.


Notes
-----
Uses the line search algorithm to enforce strong Wolfe
conditions. See Wright and Nocedal, 'Numerical Optimization',
1999, pp. 59-61.

The search direction `pk` must be a descent direction (e.g.
``-myfprime(xk)``) to find a step length that satisfies the strong Wolfe
conditions. If the search direction is not a descent direction (e.g.
``myfprime(xk)``), then `alpha`, `new_fval`, and `new_slope` will be None.

Examples
--------
>>> import numpy as np
>>> from scipy.optimize import line_search

An objective function and its gradient are defined.

>>> def obj_func(x):
...     return (x[0])**2+(x[1])**2
>>> def obj_grad(x):
...     return [2*x[0], 2*x[1]]

We can find alpha that satisfies strong Wolfe conditions.

>>> start_point = np.array([1.8, 1.7])
>>> search_gradient = np.array([-1.0, -1.0])
>>> line_search(obj_func, obj_grad, start_point, search_gradient)
(1.0, 2, 1, 1.1300000000000001, 6.13, [1.6, 1.4])

Nc                 ^   < S^ ;;,          ^,          uu&   S! SV S,          ,           .SO5!  # r   r   )alphar   r   r   r   r   s   &r   r   line_search_wolfe2.<locals>.phi  s(    
1
ebj(4((r   c                    < S^ ;;,          ^,          uu&   S! SV S,          ,           .SO5!  S^ &   V S^ &   \         P                  ! S^ ,          S4      # r   r    )rA   r   r#   r$   r%   
gval_alphar   r   s   &r   r&   "line_search_wolfe2.<locals>.derphi#  sI    
1
ebj040Q
1vvd1gr""r   c                 r   < S^ ,          V 8w  d	   S! V 4       SV S,          ,           pS! WVS^ ,          4      # r   r   )	rA   r   xr&   extra_conditionr%   rD   r   r   s	   && r   extra_condition2,line_search_wolfe2.<locals>.extra_condition20  s6    !}%uURZA"5S$q'::r   )r7   *The line search algorithm did not converge
stacklevel)r!   r"   scalar_search_wolfe2r   r   )r   myfprimer   r   r,   r-   r.   r   r   r   r(   rH   r7   r   r/   rI   
alpha_starphi_starderphi_starr&   r   r#   r$   r%   rD   s   f&ff&&&f&&&f&      @@@@@@r   line_search_wolfe2rS      s    | B
B6DJ) ) F# # {R$ffS"oG"	; 	;  2Fb3//J(K 91	. 1gr!ubeXxDDr   c
                l   \        WV4       Vf	   V ! R4      pVf	   V! R4      p^ p
Ve)   V^ 8w  d"   \        RR
W#,
          ,          V,          4      pMRpV^ 8  d   RpVe   \        W4      pV ! V4      pTpTpVf   R p\        V	4       EF	  pV^ 8X  g   Ve9   W8  d3   RpTpTpRpV^ 8X  d   RpMRRV 2,           p\        V\        ^R7        MV^ 8  pWW[,          V,          ,           8  g   W8  d    V'       d   \        WVWWW$WVV4      w  ppp MV! V4      p\        V4      V) V,          8:  d   V! W4      '       d	   TpTpTp MeV^ 8  d   \        WVVVWW$WVV4      w  ppp MF^V,          pVe   \        VV4      pTp
TpTpV ! V4      pTpEK  	  TpTpRp\        R	\        ^R7       VVVV3# )a  Find alpha that satisfies strong Wolfe conditions.

alpha > 0 is assumed to be a descent direction.

Parameters
----------
phi : callable phi(alpha)
    Objective scalar function.
derphi : callable phi'(alpha)
    Objective function derivative. Returns a scalar.
phi0 : float, optional
    Value of phi at 0.
old_phi0 : float, optional
    Value of phi at previous point.
derphi0 : float, optional
    Value of derphi at 0
c1 : float, optional
    Parameter for Armijo condition rule.
c2 : float, optional
    Parameter for curvature condition rule.
amax : float, optional
    Maximum step size.
extra_condition : callable, optional
    A callable of the form ``extra_condition(alpha, phi_value)``
    returning a boolean. The line search accepts the value
    of ``alpha`` only if this callable returns ``True``.
    If the callable returns ``False`` for the step length,
    the algorithm will continue with new iterates.
    The callable is only called for iterates satisfying
    the strong Wolfe conditions.
maxiter : int, optional
    Maximum number of iterations to perform.

Returns
-------
alpha_star : float or None
    Best alpha, or None if the line search algorithm did not converge.
phi_star : float
    phi at alpha_star.
phi0 : float
    phi at 0.
derphi_star : float or None
    derphi at alpha_star, or None if the line search algorithm
    did not converge.

Notes
-----
Uses the line search algorithm to enforce strong Wolfe
conditions. See Wright and Nocedal, 'Numerical Optimization',
1999, pp. 59-61.

Nr4   r5   c                     R # )Tr   )rA   r   s   &&r   rH   -scalar_search_wolfe2.<locals>.extra_condition  s    r   z7Rounding errors prevent the line search from convergingz4The line search algorithm could not find a solution zless than or equal to amax: rL   rK   r8   )r   r9   ranger   r   _zoomabs)r   r&   r6   r:   r/   r   r   r(   rH   r7   alpha0r;   phi_a1phi_a0	derphi_a0irP   rQ   rR   msgnot_first_iteration	derphi_a1alpha2s   &&&&&&&&&&             r   rN   rN   I  s   p |2w*F1S&$/27:;zV"[F FI	 7^Q;4+ JHDK{OL4TF;< 'A6!eBK'111#6ff$"R_F .J+ 6N		Nrc'k)v..#
!'Nff$i"R_F .J+ V&FV	c j 
91	. x{22r   c                d   \         P                  ! RRRR7      ;_uu_ 4         TpW0,
          pWP,
          p	W,          ^,          W,
          ,          p
\         P                  ! R4      pV	^,          VR&   V^,          ) VR&   V	^,          ) VR&   V^,          VR&   \         P                  ! V\         P                  ! WA,
          Wx,          ,
          Wa,
          Wy,          ,
          .4      P                  4       4      w  rW,          pW,          pW,          ^V,          V,          ,
          pW) \         P                  ! V4      ,           ^V,          ,          ,           p RRR4       \         P                  ! X4      '       g   R# T#   \         d     RRR4       R# i ; i  + '       g   i     LJ; i)	z
Finds the minimizer for a cubic polynomial that goes through the
points (a,fa), (b,fb), and (c,fc) with derivative at a of fpa.

If no minimizer can be found, return None.

raisedivideoverinvalidN)   ri   )r   r   )r      )rj   r   )rj   rj   )	r!   errstateemptyr"   asarrayflattensqrtArithmeticErrorisfinite)afafpabfbcr   Cdbdcdenomd1ABradicalxmins   &&&&&&&         r   	_cubicminr     sQ    
G'7	C	C	ABBWNbg.E&!BQwBtHaxBtHaxBtHQwBtHVVB

BGaf,<,.Gaf,<,> !??FwyJFQJAJAea!eai'GRWWW--!a%88D! 
D& ;;tK	  	% 
D	C"	# 
D	Cs)   FD8FFFFFF/	c                   \         P                  ! RRRR7      ;_uu_ 4         TpTpW0R,          ,
          pWE,
          Wg,          ,
          Ww,          ,          pWRV,          ,          ,
          p	 RRR4       \         P                  ! X	4      '       g   R# T	#   \         d     RRR4       R# i ; i  + '       g   i     LJ; i)zz
Finds the minimizer for a quadratic polynomial that goes through
the points (a,fa), (b,fb) with derivative at a of fpa.

rd   re   r5          @N)r!   rk   rp   rq   )
rr   rs   rt   ru   rv   Drx   ry   r~   r   s
   &&&&&     r   _quadminr     s     
G'7	C	C	AAWB!&RW-AC!G}$D 
D ;;tK	  	 
D	C	 
D	Cs)   B2ABB/#B2.B//B22C	c           	        ^
p^ pRpRpTp^ p W,
          pV^ 8  d   YppMYppV^ 8  d   VV,          p\        WWAVVV4      pV^ 8X  g!   Xe   VVX,
          8  g   VVV,           8  dG   VV,          p\        WWAV4      pVe   VVV,
          8  g   VVV,           8  d   V RV,          ,           pV! V4      pVWyV,          V,          ,           8  g   VV8  d
   TpTpTpTpM]V! V4      p\        V4      V
) V,          8:  d   V! VV4      '       d   TpTpTpM@VW,
          ,          ^ 8  d
   TpTpT pTpMTpT pTp TpTpV^,          pW8  g   EKE  RpRpRp VVV3# )zZoom stage of approximate linesearch satisfying strong Wolfe conditions.

Part of the optimization algorithm in `scalar_search_wolfe2`.

Notes
-----
Implements Algorithm 3.6 (zoom) in Wright and Nocedal,
'Numerical Optimization', 1999, pp. 61.

g?皙?N      ?)r   r   rY   )a_loa_hiphi_lophi_hi	derphi_lor   r&   r6   r/   r   r   rH   r7   r^   delta1delta2phi_reca_recdalpharr   ru   cchka_jqchkphi_aj	derphi_aja_starval_starvalprime_stars   &&&&&&&&&&&&                 r   rX   rX     s    G	AFFGE
 A:qAqqA EF?DD)6!7,CFq4xS1t8^F?D4&ACqv34<SZ' STsF7N**&0@GEDFsI9~"W,f1M1M! )$+&!+  DF!I	QKFH M8]**r   c                   a aaaa \         P                  ! S4      o^ .oVV VVV3R lpVf
   V! R4      p	MTp	\         P                  ! VS4      p
\        WWVR7      w  rVS^ ,          V3# )a  Minimize over alpha, the function ``f(xk+alpha pk)``.

Parameters
----------
f : callable
    Function to be minimized.
xk : array_like
    Current point.
pk : array_like
    Search direction.
gfk : array_like
    Gradient of `f` at point `xk`.
old_fval : float
    Value of `f` at point `xk`.
args : tuple, optional
    Optional arguments.
c1 : float, optional
    Value to control stopping criterion.
alpha0 : scalar, optional
    Value of `alpha` at start of the optimization.

Returns
-------
alpha
f_count
f_val_at_alpha

Notes
-----
Uses the interpolation algorithm (Armijo backtracking) as suggested by
Wright and Nocedal in 'Numerical Optimization', 1999, pp. 56-57

c                 ^   < S^ ;;,          ^,          uu&   S! SV S,          ,           .SO5!  # r   r   )r;   r   r   r   r   r   s   &r   r   line_search_armijo.<locals>.phi  s(    
1
fRi'$''r   r4   )r   rZ   )r!   
atleast_1dr"   scalar_search_armijo)r   r   r   r,   r-   r   r   rZ   r   r6   r/   rA   r=   r   s   fff&&f&&     @r   line_search_armijor   o  sn    D 
r	B
B( ( 2wffS"oG&s'.46KE"Q%r   c                X    \        WW#WEVVR7      pV^ ,          V^,          ^ V^,          3# )z0
Compatibility wrapper for `line_search_armijo`
)r   r   rZ   )r   )	r   r   r   r,   r-   r   r   rZ   rs	   &&&&&&&& r   line_search_BFGSr     s4     	1"82"(	*AQ41q!A$r   c                
   V ! V4      pWaW4,          V,          ,           8:  d   WF3# V) V^,          ,          R,          Wa,
          W$,          ,
          ,          pV ! V4      pWW7,          V,          ,           8:  d   Wx3# Wu8  Ed~   V^,          V^,          ,          Wt,
          ,          p	V^,          W,
          W',          ,
          ,          V^,          Wa,
          W$,          ,
          ,          ,
          p
W,          p
V^,          ) W,
          W',          ,
          ,          V^,          Wa,
          W$,          ,
          ,          ,           pW,          pV) \         P                  ! \        V^,          ^V
,          V,          ,
          4      4      ,           RV
,          ,          pV ! V4      pWW<,          V,          ,           8:  d   W3# W|,
          VR,          8  g   ^W,          ,
          R8  d
   VR,          pTpTpTpTpEK  RV3# )a  Minimize over alpha, the function ``phi(alpha)``.

Uses the interpolation algorithm (Armijo backtracking) as suggested by
Wright and Nocedal in 'Numerical Optimization', 1999, pp. 56-57

alpha > 0 is assumed to be a descent direction.

Returns
-------
alpha
phi1

r   g      @gQ?N)r!   ro   rY   )r   r6   r/   r   rZ   r)   r\   r;   r[   factorrr   ru   rb   phi_a2s   &&&&&&        r   r   r     s    [F	')))~ Z&!)#c)V]W=M-MNF[F7***~ -VQY&&-8AI78AI789JQYJ&-'.89AI789J"rwws1a4!a%'/#9:;;AFVRYw...>!Ov|+FM0AT/Ic\F <r   c                   VR,          p\        V4      p	^p
^p^p WV,          ,           pV ! V4      w  rWV,           WZ^,          ,          V,          ,
          8:  d   T
pMV
^,          V,          V^V
,          ^,
          V,          ,           ,          pWV,          ,
          pV ! V4      w  rWV,           W[^,          ,          V,          ,
          8:  d   V) pM~V^,          V,          V^V,          ^,
          V,          ,           ,          p\        P                  ! VWj,          Wz,          4      p
\        P                  ! VWk,          W{,          4      pEK;  WW3# )a  
Nonmonotone backtracking line search as described in [1]_

Parameters
----------
f : callable
    Function returning a tuple ``(f, F)`` where ``f`` is the value
    of a merit function and ``F`` the residual.
x_k : ndarray
    Initial position.
d : ndarray
    Search direction.
prev_fs : float
    List of previous merit function values. Should have ``len(prev_fs) <= M``
    where ``M`` is the nonmonotonicity window parameter.
eta : float
    Allowed merit function increase, see [1]_
gamma, tau_min, tau_max : float, optional
    Search parameters, see [1]_

Returns
-------
alpha : float
    Step length
xp : ndarray
    Next position
fp : float
    Merit function value at next position
Fp : ndarray
    Residual at next position

References
----------
[1] "Spectral residual method without gradient information for solving
    large-scale nonlinear systems of equations." W. La Cruz,
    J.M. Martinez, M. Raydan. Math. Comp. **75**, 1429 (2006).

)maxr!   clip)r   x_kdprev_fsetagammatau_mintau_maxf_kf_baralpha_palpha_mrA   xpfpFpalpha_tpalpha_tms   &&&&&&&&          r   _nonmonotone_line_search_cruzr     s$   P "+CLEGGE
Q;2uz1C777EA:#rQwY]C,?'?@Q;2uz1C777HEA:#rQwY]C,?'?@''(G$5w7HI''(G$5w7HIbr   c                   ^p^p^p WV,          ,           pV ! V4      w  ppWV,           W{^,          ,          V,          ,
          8:  d   TpMV^,          V,          V^V,          ^,
          V,          ,           ,          pWV,          ,
          pV ! V4      w  ppWV,           W|^,          ,          V,          ,
          8:  d   V) pM~V^,          V,          V^V,          ^,
          V,          ,           ,          p\         P                  ! VW,          W,          4      p\         P                  ! VW,          W,          4      pEK=  W,          ^,           pW,          WF,           ,          V,           V,          pTpWVVWE3# )a  
Nonmonotone line search from [1]

Parameters
----------
f : callable
    Function returning a tuple ``(f, F)`` where ``f`` is the value
    of a merit function and ``F`` the residual.
x_k : ndarray
    Initial position.
d : ndarray
    Search direction.
f_k : float
    Initial merit function value.
C, Q : float
    Control parameters. On the first iteration, give values
    Q=1.0, C=f_k
eta : float
    Allowed merit function increase, see [1]_
nu, gamma, tau_min, tau_max : float, optional
    Search parameters, see [1]_

Returns
-------
alpha : float
    Step length
xp : ndarray
    Next position
fp : float
    Merit function value at next position
Fp : ndarray
    Residual at next position
C : float
    New value for the control parameter C
Q : float
    New value for the control parameter Q

References
----------
.. [1] W. Cheng & D.-H. Li, ''A derivative-free nonmonotone line
       search and its application to the spectral residual
       method'', IMA J. Numer. Anal. 29, 814 (2009).

)r!   r   )r   r   r   r   rx   Qr   r   r   r   nur   r   rA   r   r   r   r   r   Q_nexts   &&&&&&&&&&&         r   _nonmonotone_line_search_chengr   2  sD   ^ GGE
Q;2BS5A:-333EA:#rQwY]C,?'?@Q;2BS5A:-333HEA:#rQwY]C,?'?@''(G$5w7HI''(G$5w7HI VaZF	17	b	 F*AAb"a""r   )r   r2   rS   r+   rN   r   )	NNNr   -C6??2   :0yE>+=)NNNr   r   r   r   r   )	NNNr   r   r   NN
   )NNNr   r   NNr   )r   r   rj   )r   rj   r   )r   r   r   )r   r   r   g333333?)__doc__warningsr   _dcsrchr   numpyr!   __all__RuntimeWarningr   r   r2   r+   line_searchrS   rN   r   r   rX   r   r   r   r   r   r   r   r   <module>r      s      !	 	/<6~JZ !LE^Q3hD*T+v1h7|EPN#r   