§
    fŠtj%  ã                   óR   — 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
dS )
z"Dog-leg trust-region optimization.é    Né   )Ú_minimize_trust_regionÚBaseQuadraticSubproblem© c                 ó�   — |€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.

    Nz,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/html/CA-Chatbot/venv/lib/python3.11/site-packages/scipy/optimize/_trustregion_dogleg.pyÚ_minimize_doglegr   	   sg   € ð( €{ÝÐGÑHÔHÐHÝ�D‰>Œ>ð HÝÐFÑGÔGÐGÝ! # rð :°¸#ÀDÝ-=ð:ð :à$8ð:ð :ð :ó    c                   ó$   — e Zd ZdZd„ Zd„ Zd„ ZdS )r   z0Quadratic subproblem solved by the dogleg methodc                 ó¾   — | j         €P| 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)   sU   € ð ÔÐ%Ø”ˆAØ—’˜A‘”ˆBÝ#%¤6¨!¨Q¡<¤<µ"´&¸¸B±-´-Ñ#?Ð!@À1Ñ!DˆDÔØÔ!Ð!r   c                 óÄ   — | j         €S| j        }| j        }t          j                             |¦  «        }t          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   sV   € ð ÔÐ%Ø”ˆAØ”	ˆAÝ”|×.Ò.¨qÑ1Ô1ˆHÝ"'¤,×"8Ò"8¸À1Ñ"EÔ"EÐ!EˆDÔØÔ!Ð!r   c                 óf  — |                       ¦   «         }t          j                             |¦  «        |k     rd}||fS |                      ¦   «         }t          j                             |¦  «        }||k    r|||z  z  }d}||fS |                      |||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Ð3Ø!ˆMØ˜=Ð(Ð(ð ×ÒÑ!Ô!ˆõ ”<×$Ò$ SÑ)Ô)ˆØ�|Ò#Ð#Ø ¨xÑ 7Ñ8ˆJØ ˆMØ˜}Ð,Ð,ð ×1Ò1°#°vÀ±|Ø2>ñ@ô @‰ˆˆ2à˜2 ¨#¡Ñ.Ñ.ˆ
ØˆØ˜=Ð(Ð(r   N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r'   r3   r   r   r   r   r   &   sG   € € € € € Ø:Ð:ð"ð "ð "ð	"ð 	"ð 	"ð<)ð <)ð <)ð <)ð <)r   r   )r   NN)r7   Únumpyr   Úscipy.linalgr!   Ú_trustregionr   r   Ú__all__r   r   r   r   r   ú<module>r<      s“   ðØ (Ð (Ø Ð Ð Ð Ø Ð Ð Ð Ø KÐ KÐ KÐ KÐ KÐ KÐ KÐ Kà
€ð:ð :ð :ð :ð:T)ð T)ð T)ð T)ð T)Ð.ñ T)ô T)ð T)ð T)ð T)r   