Ë
    t‰Kgä  ã                   óR   — d Z ddl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$Newton-CG trust-region optimization.é    Né   )Ú_minimize_trust_regionÚBaseQuadraticSubproblemc           	      óh   — |€t        d«      ‚|€|€t        d«      ‚t        | |f||||t        dœ|¤ŽS )a2  
    Minimization of scalar function of one or more variables using
    the Newton conjugate gradient 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 Newton-CG trust-region minimizationzdEither the Hessian or the Hessian-vector product is required for Newton-CG trust-region minimization)ÚargsÚjacÚhessÚhesspÚ
subproblem)Ú
ValueErrorr   ÚCGSteihaugSubproblem)ÚfunÚx0r   r   r	   r
   Útrust_region_optionss          úc/home/alanp/www/video.onchill/myenv/lib/python3.12/site-packages/scipy/optimize/_trustregion_ncg.pyÚ_minimize_trust_ncgr      sc   € ð( €{Üð (ó )ð 	)à€|˜˜Üð Oó Pð 	Pä! # rð :°¸#ÀDØ(-Ô:Nñ:à$8ñ:ð :ó    c                   ó   — e Zd ZdZd„ Zy)r   z:Quadratic subproblem solved by a conjugate gradient methodc                 óL  — t        j                  | j                  «      }t        dt	        j
                  | j                  «      «      | j                  z  }| j                  |k  rd}||fS |}| j                  }| }	 | j                  |«      }t        j                  ||«      }	|	dk  rB| j                  |||«      \  }
}||
|z  z   }|||z  z   } | |«       | |«      k  r|}n|}d}||fS t        j                  ||«      }||	z  }|||z  z   }t        j                  j                  |«      |k\  r$| j                  |||«      \  }
}|||z  z   }d}||fS |||z  z   }t        j                  ||«      }t	        j
                  |«      |k  rd}||fS ||z  }| ||z  z   }|}|}|}Œ))a´  
        Solve the subproblem using a conjugate gradient method.

        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
        -----
        This is algorithm (7.2) of Nocedal and Wright 2nd edition.
        Only the function that computes the Hessian-vector product is required.
        The Hessian itself is not required, and the Hessian does
        not need to be positive semidefinite.
        g      à?FTr   )ÚnpÚ
zeros_liker   ÚminÚmathÚsqrtÚjac_magr
   ÚdotÚget_boundaries_intersectionsÚscipyÚlinalgÚnorm)ÚselfÚtrust_radiusÚp_originÚ	toleranceÚhits_boundaryÚzÚrÚdÚBdÚdBdÚtaÚtbÚpaÚpbÚ
p_boundaryÚ	r_squaredÚalphaÚz_nextÚr_nextÚr_next_squaredÚ	beta_nextÚd_nexts                         r   ÚsolvezCGSteihaugSubproblem.solve,   sÙ  € ô2 —=‘= §¡Ó*ˆô ˜œTŸY™Y t§|¡|Ó4Ó5¸¿¹ÑDˆ	ð <‰<˜)Ò#Ø!ˆMØ˜]Ð*Ð*ð ˆØH‰HˆØˆBˆð ð —‘˜A“ˆBÜ—&‘&˜˜B“-ˆCØaŠxð
 ×:Ñ:¸1¸aÀÓN‘BØ˜˜a™‘ZØ˜˜a™‘ZÙ˜“8™d 2›hÒ&Ø!#‘Jà!#JØ $Ø! =Ð0Ð0ÜŸ™˜q !›ˆIØ ‘OˆEØ˜ ™‘]ˆFÜ|‰|× Ñ  Ó(¨LÒ8ð ×:Ñ:¸1¸aÀÓN‘BØ  a¡™Z
Ø $Ø! =Ð0Ð0Ø˜ ™‘^ˆFÜŸV™V F¨FÓ3ˆNÜy‰y˜Ó(¨9Ò4Ø %Ø˜}Ð,Ð,Ø&¨Ñ2ˆIØW˜y¨1™}Ñ,ˆFð ˆAØˆAØˆAñQ r   N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r7   © r   r   r   r   *   s   „ ÙDóRr   r   )r<   NNN)r;   r   Únumpyr   Úscipy.linalgr   Ú_trustregionr   r   Ú__all__r   r   r<   r   r   Ú<module>rA      s-   ðÙ *Û ã Û ß Kà
€ó:ô>TÐ2õ Tr   