
    (ph%                     L    S r SSKrSSKrSSKJrJr  / rSS jr	 " S S\5      r
g)	z"Dog-leg trust-region optimization.    N   )_minimize_trust_regionBaseQuadraticSubproblemc                 |    Uc  [        S5      e[        U5      (       d  [        S5      e[        X4X#U[        S.UD6$ )a  
Minimization of scalar function of one or more variables using
the dog-leg 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.

z,Jacobian is required for dogleg minimizationz+Hessian is required for dogleg minimization)argsjachess
subproblem)
ValueErrorcallabler   DoglegSubproblem)funx0r   r   r	   trust_region_optionss         U/var/www/html/venv/lib/python3.13/site-packages/scipy/optimize/_trustregion_dogleg.py_minimize_doglegr   	   sM    ( {GHHD>>FGG!# :D-=:$8: :    c                   *    \ rS rSrSrS rS rS rSrg)r   &   z0Quadratic subproblem solved by the dogleg methodc                     U R                   cS  U R                  nU R                  U5      n[        R                  " X5      [        R                  " X5      -  * U-  U l         U R                   $ )zF
The Cauchy point is minimal along the direction of steepest descent.
)_cauchy_pointr   hesspnpdot)selfgBgs      r   cauchy_pointDoglegSubproblem.cauchy_point)   sW     %AAB#%66!<"&&-#?!@1!DD!!!r   c                     U R                   c\  U R                  nU R                  n[        R                  R                  U5      n[        R                  R                  X15      * U l         U R                   $ )zC
The Newton point is a global minimum of the approximate function.
)_newton_pointr   r	   scipylinalg
cho_factor	cho_solve)r   r   Bcho_infos       r   newton_pointDoglegSubproblem.newton_point3   s\     %A		A||..q1H"',,"8"8"E!ED!!!r   c                 <   U R                  5       n[        R                  R                  U5      U:  a  SnX#4$ U R	                  5       n[        R                  R                  U5      nXQ:  a  XAU-  -  nSnXc4$ U R                  XBU-
  U5      u  pxXHX$-
  -  -   nSnXc4$ )a  
Minimize a function using the dog-leg trust-region algorithm.

This algorithm requires function values and first and second derivatives.
It also performs a costly Hessian decomposition for most iterations,
and the Hessian is required to be positive definite.

Parameters
----------
trust_radius : float
    We are allowed to wander only this far away from the origin.

Returns
-------
p : ndarray
    The proposed step.
hits_boundary : bool
    True if the proposed step is on the boundary of the trust region.

Notes
-----
The Hessian is required to be positive definite.

References
----------
.. [1] Jorge Nocedal and Stephen Wright,
       Numerical Optimization, second edition,
       Springer-Verlag, 2006, page 73.
FT)r(   r"   r#   normr   get_boundaries_intersections)	r   trust_radiusp_besthits_boundaryp_up_u_norm
p_boundary_tbs	            r   solveDoglegSubproblem.solve>   s    D ""$<<V$|3!M(( ! <<$$S)#x 78J M,, 11#|2>@..
((r   )r   r!   N)	__name__
__module____qualname____firstlineno____doc__r   r(   r5   __static_attributes__ r   r   r   r   &   s    :"	"<)r   r   )r=   NN)r;   numpyr   scipy.linalgr"   _trustregionr   r   __all__r   r   r=   r   r   <module>rB      s*    (   K
::T). T)r   