Ë
    âQ(h%  ã                   óJ   — d Z ddlZddlZddlmZmZ g Zdd„Z	 G d„ de«      Z
y)	z"Dog-leg trust-region optimization.é    Né   )Ú_minimize_trust_regionÚBaseQuadraticSubproblemc                 ót   — |€t        d«      ‚t        |«      st        d«      ‚t        | |f|||t        dœ|¤ŽS )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         ú`/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/scipy/optimize/_trustregion_dogleg.pyÚ_minimize_doglegr   	   sO   € ð( €{ÜÐGÓHÐHÜ�DŒ>ÜÐFÓGÐGÜ! # rð :°¸#ÀDÜ-=ñ:à$8ñ:ð :ó    c                   ó"   — e Zd ZdZd„ Zd„ Zd„ Zy)r   z0Quadratic subproblem solved by the dogleg methodc                 óØ   — | j                   €S| j                  }| j                  |«      }t        j                  ||«      t        j                  ||«      z   |z  | _         | j                   S )zV
        The Cauchy point is minimal along the direction of steepest descent.
        )Ú_cauchy_pointr   ÚhesspÚnpÚdot)ÚselfÚgÚBgs      r   Úcauchy_pointzDoglegSubproblem.cauchy_point)   s[   € ð ×ÑÐ%Ø—‘ˆAØ—‘˜A“ˆBÜ#%§6¡6¨!¨Q£<´"·&±&¸¸B³-Ñ#?Ð!@À1Ñ!DˆDÔØ×!Ñ!Ð!r   c                 óì   — | j                   €]| j                  }| j                  }t        j                  j                  |«      }t        j                  j                  ||«       | _         | j                   S )zS
        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_pointzDoglegSubproblem.newton_point3   s^   € ð ×ÑÐ%Ø—‘ˆAØ—	‘	ˆAÜ—|‘|×.Ñ.¨qÓ1ˆHÜ"'§,¡,×"8Ñ"8¸À1Ó"EÐ!EˆDÔØ×!Ñ!Ð!r   c                 óJ  — | j                  «       }t        j                  j                  |«      |k  rd}||fS | j	                  «       }t        j                  j                  |«      }||k\  r|||z  z  }d}||fS | j                  |||z
  |«      \  }}||||z
  z  z   }d}||fS )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   ÚsolvezDoglegSubproblem.solve>   sÌ   € ðD ×"Ñ"Ó$ˆÜ�<‰<×Ñ˜VÓ$ |Ò3Ø!ˆMØ˜=Ð(Ð(ð ×ÑÓ!ˆô —<‘<×$Ñ$ SÓ)ˆØ�|Ò#Ø ¨xÑ 7Ñ8ˆJØ ˆMØ˜}Ð,Ð,ð ×1Ñ1°#°vÀ±|Ø2>ó@‰ˆˆ2à˜2 ¨#¡Ñ.Ñ.ˆ
ØˆØ˜=Ð(Ð(r   N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r&   r2   © r   r   r   r   &   s   „ Ù:ò"ò	"ó<)r   r   )r7   NN)r6   Únumpyr   Úscipy.linalgr    Ú_trustregionr   r   Ú__all__r   r   r7   r   r   ú<module>r<      s*   ðÙ (Û Û ß Kà
€ó:ô:T)Ð.õ T)r   