
    tKg%                     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         f/home/alanp/www/video.onchill/myenv/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#%66!Q<"&&B-#?!@1!DD!!!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1H"',,"8"81"E!ED!!!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8J 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   