ó
Ê½÷Xc           @` s‚   d  Z  d d l m Z m Z m Z d d l Z d d l Z d d l	 m
 Z
 m Z g  Z d	 d d d „ Z d e f d „  ƒ  YZ d S(
   s"   Dog-leg trust-region optimization.i    (   t   divisiont   print_functiont   absolute_importNi   (   t   _minimize_trust_regiont   BaseQuadraticSubproblemc         K` s^   | d k r t d ƒ ‚ n  | d k r6 t d ƒ ‚ n  t |  | d | d | d | d t | S(   s   
    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.

    s,   Jacobian is required for dogleg minimizations+   Hessian is required for dogleg minimizationt   argst   jact   hesst
   subproblemN(   t   Nonet
   ValueErrorR   t   DoglegSubproblem(   t   funt   x0R   R   R   t   trust_region_options(    (    sA   /tmp/pip-build-7oUkmx/scipy/scipy/optimize/_trustregion_dogleg.pyt   _minimize_dogleg   s    R   c           B` s)   e  Z d  Z d „  Z d „  Z d „  Z RS(   s0   Quadratic subproblem solved by the dogleg methodc         C` s[   |  j  d k rT |  j } |  j | ƒ } t j | | ƒ t j | | ƒ | |  _  n  |  j  S(   sV   
        The Cauchy point is minimal along the direction of steepest descent.
        N(   t   _cauchy_pointR	   R   t   hesspt   npt   dot(   t   selft   gt   Bg(    (    sA   /tmp/pip-build-7oUkmx/scipy/scipy/optimize/_trustregion_dogleg.pyt   cauchy_point+   s
    	-c         C` sV   |  j  d k rO |  j } |  j } t j j | ƒ } t j j | | ƒ |  _  n  |  j  S(   sS   
        The Newton point is a global minimum of the approximate function.
        N(   t   _newton_pointR	   R   R   t   scipyt   linalgt
   cho_factort	   cho_solve(   R   R   t   Bt   cho_info(    (    sA   /tmp/pip-build-7oUkmx/scipy/scipy/optimize/_trustregion_dogleg.pyt   newton_point5   s    		c   	      C` s½   |  j  ƒ  } t j j | ƒ | k  r4 t } | | f S|  j ƒ  } t j j | ƒ } | | k r| | | | } t } | | f S|  j | | | | ƒ \ } } | | | | } t } | | f S(   sŒ  
        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.
        (   R   R   R   t   normt   FalseR   t   Truet   get_boundaries_intersections(	   R   t   trust_radiust   p_bestt   hits_boundaryt   p_ut   p_u_normt
   p_boundaryt   _t   tb(    (    sA   /tmp/pip-build-7oUkmx/scipy/scipy/optimize/_trustregion_dogleg.pyt   solve@   s    "

(   t   __name__t
   __module__t   __doc__R   R   R,   (    (    (    sA   /tmp/pip-build-7oUkmx/scipy/scipy/optimize/_trustregion_dogleg.pyR   (   s   	
	(    (   R/   t
   __future__R    R   R   t   numpyR   t   scipy.linalgR   t   _trustregionR   R   t   __all__R	   R   R   (    (    (    sA   /tmp/pip-build-7oUkmx/scipy/scipy/optimize/_trustregion_dogleg.pyt   <module>   s   