| Server IP : 217.160.0.135 / Your IP : 216.73.217.85 Web Server : Apache System : Linux www 6.18.52-i1-ampere #1203 SMP Mon Sep 14 18:29:59 CEST 2026 aarch64 User : sws1074145052 ( 1074145052) PHP Version : 8.3.32 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /usr/lib/python3/dist-packages/scipy/optimize/__pycache__/ |
Upload File : |
�
d�c� � �Z � d Z ddlZddlZddlZddlmZmZ g Z d d�Z
G d� de� � ZdS )
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 �A/usr/lib/python3/dist-packages/scipy/optimize/_trustregion_ncg.py�_minimize_trust_ncgr sx � �( �{�� (� )� )� )��|��
�� O� P� P� P�!�#�r� :��#�D�(-�:N�:� :�$8�:� :� :� c � � e Zd ZdZd� ZdS )r z:Quadratic subproblem solved by a conjugate gradient methodc �D � t j | j � � }t dt j | j � � � � | j z }| j |k rd}||fS |}| j }| } | � |� � }t j ||� � } | dk rM| � |||� � \ }
}||
|z z }|||z z }
| |� � | |
� � k r|}n|
}d}||fS t j ||� � }|| z }|||z z }t j � |� � |k r(| � |||� � \ }
}|||z z }d}||fS |||z z }t j ||� � }t j |� � |k rd}||fS ||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 �solvezCGSteihaugSubproblem.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�&�&�!#�J�J�!#�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� Rr r )r NNN)r<