+
    /i A                     t    R t ^ RIt^ RIHtHtHtHt ^RIH	t	H
t
 . R
OtRR ltR tR tR t ! R	 R]
4      tR# )z2Nearly exact trust-region optimization subproblem.N)normget_lapack_funcssolve_triangular	cho_solve)_minimize_trust_regionBaseQuadraticSubproblemIterativeSubproblemc                    Vf   \        R4      h\        V4      '       g   \        R4      h\        W3RVRVRVR\        /VB # )a  
Minimization of scalar function of one or more variables using
a nearly exact trust-region algorithm.

Options
-------
initial_trust_radius : float
    Initial trust-region radius.
max_trust_radius : float
    Maximum value of the trust-region radius. No steps that are longer
    than this value will be proposed.
eta : float
    Trust region related acceptance stringency for proposed steps.
gtol : float
    Gradient norm must be less than ``gtol`` before successful
    termination.
subproblem_maxiter : int, optional
    Maximum number of iterations to perform per subproblem. Only affects
    trust-exact. Default is 25.

    .. versionadded:: 1.17.0
z9Jacobian is required for trust region exact minimization.z?Hessian matrix is required for trust region exact minimization.argsjachess
subproblem)
ValueErrorcallabler   r   )funx0r
   r   r   trust_region_optionss   &&&&&,_/var/www/html/photoedit/myenv/lib/python3.14/site-packages/scipy/optimize/_trustregion_exact.py_minimize_trustregion_exactr      sj    0 { / 0 	0D>> / 0 	0!# : :# :D :-@:$8: :    c                   \         P                  ! V 4      p V P                  w  rW8w  d   \        R4      h\         P                  ! V4      p\         P
                  ! V4      p\        V4       EF  p^W5,          ,
          V P                  WU3,          ,          pRW5,          ,
          V P                  WU3,          ,          pW5^,           R V P                  V^,           R1V3,          V,          ,           pW5^,           R V P                  V^,           R1V3,          V,          ,           p	\        V4      \        V^4      ,           \        V4      \        V	^4      ,           8  d   WdV&   WV^,           R% EK  WtV&   WV^,           R% EK  	  \        W4      p
\        V
4      p\        V4      pW,          pW,          pW3# )a  Given upper triangular matrix ``U`` estimate the smallest singular
value and the correspondent right singular vector in O(n**2) operations.

Parameters
----------
U : ndarray
    Square upper triangular matrix.

Returns
-------
s_min : float
    Estimated smallest singular value of the provided matrix.
z_min : ndarray
    Estimated right singular vector.

Notes
-----
The procedure is based on [1]_ and is done in two steps. First, it finds
a vector ``e`` with components selected from {+1, -1} such that the
solution ``w`` from the system ``U.T w = e`` is as large as possible.
Next it estimate ``U v = w``. The smallest singular value is close
to ``norm(w)/norm(v)`` and the right singular vector is close
to ``v/norm(v)``.

The estimation will be better more ill-conditioned is the matrix.

References
----------
.. [1] Cline, A. K., Moler, C. B., Stewart, G. W., Wilkinson, J. H.
       An estimate for the condition number of a matrix.  1979.
       SIAM Journal on Numerical Analysis, 16(2), 368-375.
z.A square triangular matrix should be provided.N)np
atleast_2dshaper   zerosemptyrangeTabsr   r   )Umnpwkwpwmpppmvv_normw_norms_minz_mins   &              r    estimate_smallest_singular_valuer/   0   se   D 	aA77DAvIJJ 	A
A 1XfAD	!gQT"stWqss1Q347|B&stWqss1Q347|B&r7T"a[ CGd2qk$99aDacdGaDacdG  	A!WF!WF OE JE<r   c                D   \         P                  ! V 4      p\         P                  ! V4      p\         P                  ! \         P                  ! V 4      ^R7      p\         P                  ! W,           V,
          4      p\         P
                  ! W,
          V,           4      pWE3# )z
Given a square matrix ``H`` compute upper
and lower bounds for its eigenvalues (Gregoshgorin Bounds).
Defined ref. [1].

References
----------
.. [1] Conn, A. R., Gould, N. I., & Toint, P. L.
       Trust region methods. 2000. Siam. pp. 19.
)axis)r   diagr   summinmax)HH_diag
H_diag_abs
H_row_sumslbubs   &     r   gershgorin_boundsr<      si     WWQZFJq	*J	#j0	1B	#j0	1B6Mr   c                   \         P                  ! VRV^,
          1V^,
          3,          ^,          4      W^,
          V^,
          3,          ,
          p\        V 4      p\         P                  ! V4      p^WR^,
          &   V^8w  dL   \	        VRV^,
          1RV^,
          13,          VRV^,
          1V^,
          3,          ) 4      VRV^,
          % W53# )a  
Compute term that makes the leading ``k`` by ``k``
submatrix from ``A`` singular.

Parameters
----------
A : ndarray
    Symmetric matrix that is not positive definite.
U : ndarray
    Upper triangular matrix resulting of an incomplete
    Cholesky decomposition of matrix ``A``.
k : int
    Positive integer such that the leading k by k submatrix from
    `A` is the first non-positive definite leading submatrix.

Returns
-------
delta : float
    Amount that should be added to the element (k, k) of the
    leading k by k submatrix of ``A`` to make it singular.
v : ndarray
    A vector such that ``v.T B v = 0``. Where B is the matrix A after
    ``delta`` is added to its element (k, k).
N)r   r3   lenr   r   )Ar    r%   deltar"   r*   s   &&&   r   singular_leading_submatrixrA      s    6 FF1TacT1Q3Y<?#a!QqSk1EAA 	AAcF 	Av"1TacT4AaC4Z=1TacT1Q3Y<-@$1Q38Or   c                      a a ] tR t^t oRtRt^t]P                  ! ]	4      P                  tRV 3R lltR tR tRtVtV ;t# )r   a  Quadratic subproblem solved by nearly exact iterative method.

Notes
-----
This subproblem solver was based on [1]_, [2]_ and [3]_,
which implement similar algorithms. The algorithm is basically
that of [1]_ but ideas from [2]_ and [3]_ were also used.

References
----------
.. [1] A.R. Conn, N.I. Gould, and P.L. Toint, "Trust region methods",
       Siam, pp. 169-200, 2000.
.. [2] J. Nocedal and  S. Wright, "Numerical optimization",
       Springer Science & Business Media. pp. 83-91, 2006.
.. [3] J.J. More and D.C. Sorensen, "Computing a trust region step",
       SIAM Journal on Scientific and Statistical Computing, vol. 4(3),
       pp. 553-572, 1983.
g{Gz?c	                r  < \         S	V `  WW44       RV n        RV n        ^ V n        W`n        Wpn        Vf   V P                  MTV n        V P                  ^ 8  d   \        R4      h\        RV P                  34      w  V n        \        V P                  4      V n        \        V P                  4      w  V n        V n        \%        V P                  \&        P(                  4      V n        \%        V P                  R4      V n        V P                  V P.                  ,          V P*                  ,          V n        R# )   NzJmaxiter must not be set to a negative number, use np.inf to mean infinite.fror   )potrf)super__init__previous_tr_radius	lambda_lbniterk_easyk_hardMAXITER_DEFAULTmaxiterr   r   r   choleskyr>   	dimensionr<   hess_gershgorin_lbhess_gershgorin_ubr   r   infhess_infhess_froEPSCLOSE_TO_ZERO)
selfxr   r   r   hessprL   rM   rO   	__class__s
   &&&&&&&&&r   rH   IterativeSubproblem.__init__   s     	+ #%
 
 07t++G<<! > ? ? **tyylC TYY&7		&B	$#TYY/TYY. "^^dhh6Fr   c           
     l   \        ^ V P                  V,          \        V P                  ) V P                  V P
                  4      ,           4      p\        ^ \        V P                  P                  4       4      ) V P                  V,          \        V P                  V P                  V P
                  4      ,
          4      pWP                  8  d   \        V P                  V4      pV^ 8X  d   ^ pMC\        \        P                  ! W2,          4      W0P                  W#,
          ,          ,           4      pWCV3# )zGiven a trust radius, return a good initial guess for
the damping factor, the lower bound and the upper bound.
The values were chosen accordingly to the guidelines on
section 7.3.8 (p. 192) from [1]_.
)r5   jac_magr4   rR   rV   rU   r   diagonalrS   rI   rJ   r   sqrtUPDATE_COEFF)rY   	tr_radius	lambda_ubrJ   lambda_initials   &&   r   _initial_values#IterativeSubproblem._initial_values  s     4<<	1C9P9P8P8<8<5G G H	
 C		 2 2 455Y.T5L5L59]]59]]2D DE	 ...DNNI6I >N )>!?!*->->	@S-T!TVN )33r   c                n	   V P                  V4      w  r#pV P                  pRpRp^ V n        V P                  V P                  8  EdZ   V'       d   RpMEV P                  V\
        P                  ! V4      ,          ,           pV P                  VRRRR7      w  rV ;P                  ^,          un        X
^ 8X  Ed[   V P                  V P                  8  Ed?   \        X	R3V P                  ) 4      p\        V4      pW8:  d   V^ 8X  d   RpEM\        WRR7      p\        V4      pW,          ^,          W,
          ,          V,          pW/,           pW8  Ed   \        V	4      w  ppV P                  VVV4      w  pp\!        VV.\"        R7      p\
        P$                  ! V\
        P$                  ! XV4      4      pV^,          V^,          ,          VW!^,          ,          ,           ,          pVV P&                  8:  d   VVV,          ,          pEMTp\)        W2V^,          ,
          4      pV P                  V\
        P                  ! V4      ,          ,           pV P                  VRRRR7      w  pp
V
^ 8X  d   TpRpEKO  \)        VV4      p\)        \
        P*                  ! \
        P"                  ! W4,          4      4      W0P,                  WC,
          ,          ,           4      pEK  \#        W,
          4      V,          pVV P.                  8:  d   EMTpTpEK  V
^ 8X  d   V P                  V P                  8:  d   V^ 8X  d   \
        P0                  ! V4      pRpEMK\        X	4      w  ppTpVV,          pV^,          V^,          ,          V P&                  V,          V^,          ,          8:  d   MTp\)        W2V^,          ,
          4      p\)        \
        P*                  ! W4,          4      W0P,                  WC,
          ,          ,           4      pEK  \3        XX	V
4      w  pp\        V4      p\)        W2VV^,          ,          ,           4      p\)        \
        P*                  ! \
        P"                  ! W4,          4      4      W0P,                  WC,
          ,          ,           4      pEKu  W0n        W n        Wn        XV3# )zSolve quadratic subproblemTF)loweroverwrite_acleanr   )trans)key)rf   rQ   rK   rO   r   r   eyerP   r_   rX   r   r   r   r   r/   get_boundaries_intersectionsr4   r   dotrM   r5   ra   rb   rL   r   rA   rJ   lambda_currentrI   )rY   rc   rq   rJ   rd   r"   hits_boundaryalready_factorizedr6   r    infor#   p_normr$   r,   delta_lambda
lambda_newr-   r.   tatbstep_lenquadratic_termrelative_errorcr@   r*   r+   s   &&                          r   solveIterativeSubproblem.solve1  s    04/C/CI/N,9NN"
jj4<<' "%*"IInRVVAY66--49.2 ( 4 JJ!OJ qyT\\D,>,>> q%j488)4a &>Q+>$)M %Q5a !'1V5EFyP+:
%#CA#FLE5!>>q%?HJFB  #B85H &(VVArvva|%<N (0{UAX'=)7.TU:U)U'WN%4X-- !/I #Iq/H II 		Jrvvay$88A"mmAU8=26 , 8GAt qy)3-1* %(	:$>	 *-GGBFF9+@$AB%(9(99;N(OO* &));%<y%HN%4 !/I &0Nt||t/A/AA "Q&A$)M?Bu$u$aK%(*{{^3ilBC +		E1H+DE	 "%GGI12 1 193F GG" 6aDAqa  	E&!)O+KL	 "%GGBFF9#89: 1 193F GG"
 #,"+-r   )rX   rP   rQ   rV   rR   rS   rU   rL   rM   rq   rJ   rO   rK   rI   )Ng?g?N)__name__
__module____qualname____firstlineno____doc__rb   rN   r   finfofloatepsrW   rH   rf   r~   __static_attributes____classdictcell____classcell__)r\   __classdict__s   @@r   r   r      sC     , L O
((5/

C/Gb4>Y  Y r   )r   r/   rA   r   ) NN)r   numpyr   scipy.linalgr   r   r   r   _trustregionr   r   __all__r   r/   r<   rA   r   r   r   r   <module>r      sF    8 % % K" :FL^*'TL 1 L r   