+
    LV-j 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   &&&&&,Úr/Volumes/fast/ai/experiments/ui-tars-smoke/.venv/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&   WƒV^,           R% EK  WtV&   W“V^,           R% EK  	  \        W4      p
\        V
4      p\        V4      pWË,          pW«,          pWÞ3# )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Ø�7‰7�D€Aà„vÜÐIÓJÐJô 	�Š�‹€AÜ
�Š�‹€Aô �1�XˆØ�•�f˜Ÿ™˜A˜D�	Õ!ˆØ�•�g˜Ÿ™˜Q˜T�Õ"ˆØ��sˆtˆW�q—s‘s˜1˜Q�3™4 ˜7•| B•Õ&ˆØ��sˆtˆW�q—s‘s˜1˜Q�3™4 ˜7•| B•Õ&ˆäˆr‹7”T˜"˜a“[Õ ¤C¨£G¬d°2°q«kÕ$9Ô9Øˆa‰DØˆa��cˆd‹Gàˆa‰DØˆa��cˆd‹Gñ ô 	˜Ó€Aä�!‹W€FÜ�!‹W€Fð �O€Eð �J€Eàˆ<Ð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   € ô �WŠW�Q‹Z€FÜ—’˜“€JÜ—’œŸš˜q›	¨Ô*€JÜ	�Š�Õ# jÕ0Ó	1€BÜ	�Š�Õ# jÕ0Ó	1€Bàˆ6€Mr   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 �FŠF�1�T�a˜•c�T˜1˜Q�3�Y•< •?Ó# a¨!­¨Q¨q­S¨¥kÕ1€EäˆA‹€Aô 	�Š�‹€AØ€Aˆ…c�Fð 	ˆA„vÜ" 1 T a¨¥c T¨4¨A¨a­C¨4 Z¥=°1°T°a¸µc°T¸1¸Q½3°Yµ<°-Ó@ˆˆ$ˆ1ˆQ�3ˆàˆ8€Or   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{®Gáz„?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ˆŒØ�<‰<˜!ÔÜð >ó ?ð ?ô *¨*°t·y±y°lÓC‰ˆŒô ˜TŸY™Y›ˆŒä&7¸¿	¹	Ó&Bñ	$ˆÔØÔ#Ü˜TŸY™Y¬¯©Ó/ˆŒÜ˜TŸY™Y¨Ó.ˆŒð "Ÿ^™^¨d¯h©hÕ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# )zÉGiven 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Ÿ<™<¨	Õ1´C¸×9PÑ9PÐ8PØ8<¿¹Ø8<¿¹ó5Gõ Gó Hˆ	ô
 ˜œC §	¡	× 2Ñ 2Ó 4Ó5Ð5ØŸ™ YÕ.´°T×5LÑ5LØ59·]±]Ø59·]±]ó2Dõ DóEˆ	ð ×.Ñ.Ô.Ü˜DŸN™N¨IÓ6ˆIð ˜Œ>Ø‰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  ršV ;P                  ^,          un        X
^ 8X  Ed[   V P                  V P                  8”  Ed?   \        X	R3V P                  ) 4      p\        V4      pWÁ8:  d   V^ 8X  d   RpEM—\        W›RR7      p\        V4      pWÎ,          ^,          WÁ,
          ,          V,          pW/,           pWÁ8  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M•T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M•T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   MöT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Ñ/CÀIÓ/NÑ,ˆ 9Ø�N‰NˆØˆØ"ÐØˆŒ
à�j‰j˜4Ÿ<™<Õ'÷ "Ø%*Ñ"à—I‘I˜n¬R¯VªV°A«YÕ6Õ6�ØŸ-™-¨°Ø49Ø.2ð (ó 4‘�ð �JŠJ˜!�O�Jð �q�y˜TŸ\™\¨D×,>Ñ,>Õ>ô ˜q %˜j¨4¯8©8¨)Ó4�ä˜a›�ð Ô&¨>¸QÔ+>Ø$)�MÙô % Q°Ô5�ä˜a›�ð !'¥°Õ1°VÕ5EÕFÀyÕP�Ø+Õ:�
àÕ%Ü#CÀAÓ#F‘L�E˜5à!×>Ñ>¸qÀ%Ø?HóJ‘F�B˜ô  # B¨ 8´Ô5�Hô &(§V¢V¨A¬r¯vªv°a¸«|Ó%<�Nð (0°¥{°U¸AµXÕ'=Ø)7¸.ÐTUÍÕ:UÕ)Uõ'W�Nà%¨¯©Ô4Ø˜X¨Õ-Õ-˜Ùð !/�IÜ # IÀÀqÅÕ/HÓ I�Ið Ÿ	™	 J¬r¯vªv°a«yÕ$8Õ8�AØ"Ÿm™m¨A°UØ8=Ø26ð ,ó 8‘G�A�tð ˜q”yà)3˜Ø-1Ó*ô %(¨	°:Ó$>˜	ô *-ÜŸGšG¤B§F¢F¨9Õ+@Ó$AÓBØ%×(9Ñ(9¸9Õ;NÕ(OÕOó*›ô &)¨Õ);Ó%<¸yÕ%H�NØ%¨¯©Ô4Ùð !/�Ið &0“Nà˜”˜tŸ|™|¨t×/AÑ/AÔAð " QÔ&ÜŸš ›�AØ$)�MÙä?ÀÓB‘��uØ$�à˜uÕ$�à˜a•K %¨¥(Õ*Ø—{‘{ ^Õ3°iÀµlÕBôCàð +�	Ü 	¸EÀ1½HÕ+DÓE�	ô "%Ü—G’G˜IÕ1Ó2Ø× 1Ñ 1°9Õ3FÕ GÕGó"“ô 6°a¸¸DÓA‘��qÜ˜a›�ô   	¸EÀ&È!Å)½OÕ+KÓL�	ô "%Ü—G’GœBŸFšF 9Õ#8Ó9Ó:Ø× 1Ñ 1°9Õ3FÕ 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   