
    ^Mh%                     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         b/var/www/html/test/jupyter/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!DD!!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1H"',"8"81"E"E!ED!!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8J 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   