Submit
Path:
~
/
/
proc
/
thread-self
/
root
/
opt
/
alt
/
python35
/
lib64
/
python3.5
/
site-packages
/
sklearn
/
utils
/
__pycache__
/
File Content:
optimize.cpython-35.pyc
��(Xk � @ s� d Z d d l Z d d l Z d d l m Z m Z d d l m Z Gd d � d e � Z d d � Z d d � Z f d d d d d d d � Z d S)a� Our own implementation of the Newton algorithm Unlike the scipy.optimize version, this version of the Newton conjugate gradient solver uses only one function call to retrieve the func value, the gradient value and a callable for the Hessian matvec product. If the function call is very expensive (e.g. for logistic regression with large design matrix), this approach gives very significant speedups. � N)�line_search_wolfe2�line_search_wolfe1� )�ConvergenceWarningc @ s e Z d Z d S)�_LineSearchErrorN)�__name__� __module__�__qualname__� r r �/optimize.pyr s r c K so t | | | | | | | | � } | d d k rR t | | | | | | | | � } | d d k rk t � � | S)a Same as line_search_wolfe1, but fall back to line_search_wolfe2 if suitable step length is not found, and raise an exception if a suitable step length is not found. Raises ------ _LineSearchError If no suitable step size is found r N)r r r ) �fZfprime�xkZpkZgfk�old_fval�old_old_fval�kwargsZretr r r �_line_search_wolfe12 s r c C sZ t j t | � d | j �} | } | } d } t j | | � } x| | k rUt j t j | � � | k rq P| | � } t j | | � } d | k o� d t j t j � j k n r� Pn/ | d k r� | d k r� Pn | | | | 7} P| | } | | | 7} | | | } t j | | � } | | } | | | } | d } | } qF W| S)aI Solve iteratively the linear system 'fhess_p . xsupi = fgrad' with a conjugate gradient descent. Parameters ---------- fhess_p : callable Function that takes the gradient as a parameter and returns the matrix product of the Hessian and gradient fgrad : ndarray, shape (n_features,) or (n_features + 1,) Gradient vector maxiter : int Number of CG iterations. tol : float Stopping criterion. Returns ------- xsupi : ndarray, shape (n_features,) or (n_features + 1,) Estimated solution �dtyper � � ) �npZzeros�lenr �dot�sum�absZfinfoZfloat64Zeps)�fhess_p�fgrad�maxiter�tol�xsupiZriZpsupi�iZdri0ZApZcurvZalphaiZdri1Zbetair r r �_cg7 s4 / r g-C��6?�d �� Tc C s� t j | � j � } | } d } | r<