§
    ^ùMhä  ã                   óZ   — 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dS )
z$Newton-CG trust-region optimization.é    Né   )Ú_minimize_trust_regionÚBaseQuadraticSubproblem© c           	      ó|   — |€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.

    Nz<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          ú_/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/scipy/optimize/_trustregion_ncg.pyÚ_minimize_trust_ncgr      sx   € ð( €{Ýð (ñ )ô )ð 	)à€|˜˜Ýð Oñ Pô Pð 	På! # rð :°¸#ÀDØ(-Õ:Nð:ð :à$8ð:ð :ð :ó    c                   ó   — e Zd ZdZd„ ZdS )r   z:Quadratic subproblem solved by a conjugate gradient methodc                 óD  — t          j        | j        ¦  «        }t          dt	          j        | j        ¦  «        ¦  «        | j        z  }| j        |k     rd}||fS |}| j        }| }	 |                      |¦  «        }t          j        ||¦  «        }	|	dk    rM|  	                    |||¦  «        \  }
}||
|z  z   }|||z  z   } | |¦  «         | |¦  «        k     r|}n|}d}||fS t          j        ||¦  «        }||	z  }|||z  z   }t          j                             |¦  «        |k    r(|  	                    |||¦  «        \  }
}|||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 t¤|Ñ4Ô4Ñ5Ô5¸¼ÑDˆ	ð Œ<˜)Ò#Ð#Ø!ˆMØ˜]Ð*Ð*ð ˆØŒHˆØˆBˆð(	ð —’˜A‘”ˆBÝ”&˜˜B‘-”-ˆCØaŠxˆxð
 ×:Ò:¸1¸aÀÑNÔN‘BØ˜˜a™‘ZØ˜˜a™‘ZØ4˜‘8”8˜d˜d 2™hœhÒ&Ð&Ø!#JJà!#JØ $Ø! =Ð0Ð0Ýœ˜q !™œˆIØ ‘OˆEØ˜ ™‘]ˆFÝŒ|× Ò  Ñ(Ô(¨LÒ8Ð8ð ×:Ò:¸1¸aÀÑNÔN‘BØ  a¡™Z
Ø $Ø! =Ð0Ð0Ø˜ ™‘^ˆFÝœV F¨FÑ3Ô3ˆNÝŒy˜Ñ(Ô(¨9Ò4Ð4Ø %Ø˜}Ð,Ð,Ø&¨Ñ2ˆIØW˜y¨1™}Ñ,ˆFð ˆAØˆAØˆAñQ(	r   N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r8   r   r   r   r   r   *   s.   € € € € € ØDÐDðRð Rð Rð Rð Rr   r   )r   NNN)r<   r   Únumpyr   Úscipy.linalgr   Ú_trustregionr   r   Ú__all__r   r   r   r   r   ú<module>rA      sœ   ðØ *Ð *Ø €€€à Ð Ð Ð Ø Ð Ð Ð Ø KÐ KÐ KÐ KÐ KÐ KÐ KÐ Kà
€ð:ð :ð :ð :ð>Tð Tð Tð Tð TÐ2ñ Tô Tð Tð Tð Tr   